Re: Reading entire file into an array..HELP!



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

.



Relevant Pages

  • Re: Vick Gets 23 Months In Prison
    ... about the "for the heck of it". ... Predators kill ... Humans don't need to hunt to survive in this country. ... it is legal for some reason ...
    (rec.sport.football.college)
  • Re: Expression columns and DevisionByZero
    ... it should work but doesn't and if frustrating as heck. ... Bill ... > I tried out your suggestion - and it does indeed cause the same exception. ... >> Any reason not to do: ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Unicyle.com Sucks!
    ... What the heck are you guys talking about, we're all going to die. ... anyway I ordered it Friday and the reason your friend is going to get ...
    (rec.sport.unicycling)
  • Re: OT I want to post an incredibly funny pic that someone sent me
    ... �If it's NOT pinball ... related (or heck I'll give you arcade related) there is no reason to ... I'm guessing it's in political/tinfoil hat territory at the worst, ...
    (rec.games.pinball)
  • Re: Enbrel -- interesting
    ... Taht would be cool indeed! ... Heck, Remicade helped save Duckie's eyes, no ... reason why Enbrel shouldn't help save your ears! ...
    (alt.support.arthritis)