mmm... might I add one bug that might occur from this example? What happens if the person has a last name containing spaces? I know a couple of people on this planet with last names like that... So I made one small adjustment to your code. I used a
split() with a limit of 2:
#!/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!