
FishMonger
Veteran
Jul 29, 2011, 6:19 AM
Post #2 of 2
(265 views)
|
|
Re: [akshay] Help Needed..Perl Beginner
[In reply to]
|
Can't Post
|
|
1a) The die statement should include the reason it failed, which can be done by adding $! to the statement and it should include what you're were trying to open. 1b) Use a while loop instead of the for loop. 1c) You should be using a lexical var for the filehandle instead of the bareword and you should be using the 3 arg form of open. 2) Surround your code with code tags.
open my $FH, '<', 'test.txt' or die "Can't open 'test.txt' $!"; while ( my $line = <$FH> ) { print $line; } close $FH;
|