On Thursday 01 July 2004 14:30, Rob Benton wrote:
>
> I'm looking for a little help here. I'm not understanding exactly
> what's wrong with this code:
>
> ===============================================================
> #!/usr/bin/perl -w
>
> use strict;
>
> open IN, "<comma.txt" or die "$!\n";
>
> my %rows;
>
> while (<IN>)
> {
> chomp;
> my @fields = split( /,/, $_);
> $rows{$fields[2]} = [ ($fields[3]..$fields[-1]) ];
> print "array: ";
> print "@{$rows{$fields[2]}}\n";
> }
>
> close IN;
> ===========================================================
>
> This prints nothing for the array. If I replace the scalars inside [
> () ] with literal strings or numbers it works. What the correct way
> to do what I'm attempting. Am I just quoting wrong?
The value in $fields[3] has to be less than or equal to the value in
$fields[-1] for the range operator to produce a non-empty list.
Perhaps you want an array slice instead?
$rows{ $fields[2] } = [ @fields[ 3 .. $#fields ] ];
print "array: @fields[3..$#fields]\n";
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>