my @tokens = split; my $header = $tokens[0];
Or just:
my $header = ( split )[ 0 ];
my ($n, @list); ($n, @list) = @_;
Or just:
my ( $n, @list ) = @_;
my (@list); foreach $_ (@list) {
You just created @list so there is nothing in it and the foreach loop will not iterate over an empty list.
foreach $_ (@list) { ... my @list = @tokens[0,3,4,7,8]; ... push (@list, $_);
You shouldn't modify an array that you are iterating over in a foreach loop. As perlsyn warns "If any part of LIST is an array, "foreach" will get very confused if you add or remove elements within the loop body, for example with "splice". So don't do that.".
my @tokens = split; my $header = $tokens[0]; my @records = @tokens [3,4,5,6,10,11];
Or just:
my ( $header, @records ) = ( split )[ 0, 3, 4, 5, 6, 10, 11 ];
my $y = $tokens[0]; my $m = $tokens[1]; my $d = $tokens[2]; my $h = $tokens[3];
Or just:
my ( $y, $m, $d, $h ) = @tokens;
In reply to Re: Lexical scope
by jwkrahn
in thread Lexical scope
by velocitymodel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |