Re: Reading entire file into an array..HELP!
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 18 Jan 2006 15:03:28 -0800
MegaC wrote:
> Hi all,
>
> I am having a heck of a time trying to read input from a file.
>
> Here is the cuplrit code:
>
> my($count) = 0;
> foreach $count(@array1) {
> open(FILE, $count);
You have not verified that the open() actually succeeded. This file
was never actually opened, but you didn't seem to care. Instead, you
just tried to read from it anyway.
open FILE, $count or die "Could not open $count: $!";
The program will exit if the file cannot be opened. The $! will
contain the reason the open failed.
Note that you should, in general, use the three-argument form of open,
and use lexical filehandles instead of global barewords:
open my $fh, '<', $count or die "Could not open $count: $!";
my @allLines = <$fh>
print @allLines, "\n\n";
> @allLines = <FILE>;
> print "@allLines\n\n";
perldoc -q spaces
> close FILE;
> }
>
>
> WHAT AM I DOING WRONG!
Your basic problem is that you are not asking Perl for all the help it
can give you. Start doing that.
Paul Lalli
.
- Follow-Ups:
- Re: Reading entire file into an array..HELP!
- From: Chris
- Re: Reading entire file into an array..HELP!
- From: rajesh
- Re: Reading entire file into an array..HELP!
- References:
- Reading entire file into an array..HELP!
- From: MegaC
- Reading entire file into an array..HELP!
- Prev by Date: Re: Transform column into row
- Next by Date: Re: Transform column into row
- Previous by thread: Re: Reading entire file into an array..HELP!
- Next by thread: Re: Reading entire file into an array..HELP!
- Index(es):
Relevant Pages
|