#!/usr/bin/perl -w
#%names = ();
$fn = "";
$ln = "";
while (<>){
chomp;
($fn, $ln) = split;
$names{$ln} = $fn;
}
foreach $ln (sort keys %names){
print "$ln, $names{$ln}\n"; #prints last name (key), first name (value)
}
names.txt (the file that I call on the command line to read from)
[text]
Barack Obama
Chad Johnson
Brady Quinn
George Bush
[/text]
When I run % ./namesEnhanced.pl names.txt I get:
line 4: syntax error near unexpected token `('
line 4: `%names = ();'
So.... that's strange. I comment that out and run:
line 5: =: command not found
line 6: =: command not found
line 8: syntax error near unexpected token `)'
line 8: `while (<>){'
...
I am simply modifying a perl script that I made before that takes input from the keyboard instead of a file. The other script runs just fine... What is going on?!
Question
generalt
namesEnhanced.pl
#!/usr/bin/perl -w #%names = (); $fn = ""; $ln = ""; while (<>){ chomp; ($fn, $ln) = split; $names{$ln} = $fn; } foreach $ln (sort keys %names){ print "$ln, $names{$ln}\n"; #prints last name (key), first name (value) }names.txt (the file that I call on the command line to read from)
[text]
Barack Obama
Chad Johnson
Brady Quinn
George Bush
[/text]
When I run % ./namesEnhanced.pl names.txt I get:
line 4: syntax error near unexpected token `('
line 4: `%names = ();'
So.... that's strange. I comment that out and run:
line 5: =: command not found
line 6: =: command not found
line 8: syntax error near unexpected token `)'
line 8: `while (<>){'
...
I am simply modifying a perl script that I made before that takes input from the keyboard instead of a file. The other script runs just fine... What is going on?!
Link to comment
Share on other sites
2 answers to this question
Recommended Posts