in reply to Script issue involves File Handling.
Consider getting an insight into References, they're so powerful. Not belittling the other solutions here by toolic and ww for they are far more readable and constructed and these guys are more experienced than humble me, but I am showing you a TIMTOWTDI thing cuz a surgeon needs to know what there in the guts is :p
Here we go:
#!/usr/local/bin/perl use strict; use warnings; my %hash; while(<DATA>){ chomp; my ($name,$crowdReaction,$killerMove)=split /\|/; $hash{$name}=[] unless exists $hash{$name}; #to skip duplicate + wrestlers names just in case. push @{$hash{$name}}, $crowdReaction,$killerMove; } print "WRESTLER\tCrowd Reaction\tKiller Move\n"; print "_" x 50, "\n"; foreach my $name (sort keys %hash){ for(my $i=0;$i< length(@{$hash{$name}});$i++){ print "$name\t@{$hash{$name}}[$i]\t\t@{$hash{$name}}[+ ++$i]\n"; } } __DATA__ The Rock|Cheer|Rock Bottom Triple H|Boo|Pedigree Stone Cold|Cheer|Stone Cold Stunner
N.B: The way you used the open function to open a file, you haven't provided arguments specifying if the file has been opened in modes of input, output, append...WRESTLER Crowd Reaction Killer Move __________________________________________________ Stone Cold Cheer Stone Cold Stunner The Rock Cheer Rock Bottom Triple H Boo Pedigree
|
|---|