develooper Front page | perl.beginners | Postings from December 2002

Re: file into memory

Thread Previous
From:
Rob Dixon
Date:
December 24, 2002 03:50
Subject:
Re: file into memory
Message ID:
20021224115044.90472.qmail@onion.perl.org
Thanks Naryan.

This is my old while/for dyslexia playing me up again :-/

I think you're wrong about the interpolation though. while () won't take a
control variable and I doubt it will compile in this form.

Cheers,

Rob

"Narayan Kumar" <narayan@tc4hq.cmcltd.com> wrote in message
news:Pine.LNX.4.10.10212241711220.14719-100000@tc4hq.cmcltd.com...
> I am very new to perl.
> I dont think I get your question.
>
> How about using "foreach" instead of "while".
> foreach ( @xx )
> {
> .....
> }
>
> while $file ( @xx ) will actually be interpolated to,
> $file("peter 141444 \noscar e324345 \nsimon  j85547\n");
> which is as good as $file(0); and will never work.
>
> Narayan
>
> On Tue, 24 Dec 2002, Schwedler Kofoed wrote:
>
> |Hi all,
> |
> |I would like to open a file with the content:
> |
> |peter 141444
> |oscar e324345
> |simon  j85547
> |
> |in a perl script - but instead of reading the file one line at a time I
> |would like to suck the whole file into memory and processing each line
from
> |there.
> |
> |I have tried to:
> |
> |open FILE, "< tmp.txt";
> |@xx = <FILE>;
> |    while  $file(@xx)    {
> |................
> |}
> |
> |but I cant get it to work  - where did I go wrong ?
> |
> |Thanks!
> |
> |/Jakob
> |
>



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About