On Sun, 2017-11-05 at 00:43 +0000, Dong Liu wrote:
> I try used perl script to get characters from data:
>
> #!/usr/bin/perl -w
> use v5.14;
> while (<DATA>){
> chomp;
> my $line = '';
> $line = (split //,@_)[5];
At no point in your script do you or perl assign a value to the array
@_ so the array will have 0 elements, and an array in scalar context
will return the number of elements in the array, so that statement is
the same as:
$line = ( split //, '0' )[ 5 ];
Which will create the list ( '0' ). So every element other than zero
(the first element) will be undef. So that statement is the same as:
$line = undef;
> print "it is $line.\n";
> }
>
> __DATA__
> Danio rerio strain Tuebingen chromosome 1 GRCz11 Primary Assembly
> Danio rerio strain Tuebingen chromosome 2 GRCz11 Primary Assembly
>
> the results is :
> Use of uninitialized value $line in concatenation (.) or string at
> foundins.pl line 9, <DATA> line 1.
> it is .
> Use of uninitialized value $line in concatenation (.) or string at
> foundins.pl line 9, <DATA> line 2.
> it is .
>
> the aim for the work is to get the number for each line such as:
> 1 for first line and
> 2 for second lin
When using a while ( <> ) loop the current line number can be found in
the $. variable:
$ perldoc -v $.
John
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/