in reply to Associative Array Trouble
#!/usr/bin/perl -w use strict; my $i = 1; my %list; open TEST, 'test.txt' || die "Couldn't open it"; print "\nFile Opened\n\n\n"; while(<TEST>){ chomp; my ($f, $l) = split(' ', $_, 2); print "$i : $l\,$f\n"; $list{$i} = [$f,$l]; $i += 1; } foreach my $c (sort keys %list) { print "$list{$c}->[1],$list{$c}->[0]$/"; } close TEST; print "\n\n\nFile Closed\n";
Also, may I ask why
$list{$c}->[1],$list{$c}->[0]
and
$list{$c}[1],$list{$c}[0]
are not really the same thing?
Is it because without the dereferencing arrows, it is not "technically correct" code?
I have never used the arrows and my code has always worked fine!
|
|---|