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

RE: file into memory

Thread Previous | Thread Next
From:
Bob Showalter
Date:
December 24, 2002 06:07
Subject:
RE: file into memory
Message ID:
2E4528861499D41199D200A0C9B15BC001D7E60A@FRISTX
> -----Original Message-----
> From: Schwedler Kofoed [mailto:Schw_kof@mail.tele.dk]
> Sent: Monday, December 23, 2002 6:04 PM
> To: beginners@perl.org
> Subject: file into memory
> 
> 
> 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'm not sure what that accomplishes for you, but...

> 
> I have tried to:
> 
> open FILE, "< tmp.txt";

You need to check for errors on open.

> @xx = <FILE>;

That's OK; it will read the entire file into the array, but you should add
"use strict;" at the top of your script and use "my" to declare @xx.

>     while  $file(@xx)    {

You're confusing the syntax of while() and foreach()

You want:

   for my $file (@xx) {
   
   }

> ................
> }
> 
> but I cant get it to work  - where did I go wrong ?


Thread Previous | Thread Next


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