[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [SLUG] Reading a file into variables?



Thanks all,

I've got a bit to play with now thanks to your help.
I was looking for a Perl book and would you believe there isn't much around
these days (well at least were I went looking). It's either VB or Java or C
but I found little on Perl.. Very annoying..

Unfortuntely we do alot of Java here and I'm probably better off learning
that instead. So many languages , so little time...


thanks,
George Vieira
Network Administrator
Citadel Computer Systems P/L
http://www.citadelcomputer.com.au



-----Original Message-----
From: Michael Lake [mailto:Mike.Lake@nospam.uts.edu.au]
Sent: Tuesday, 4 July 2000 5:45 PM
To: 'slug@nospam.slug.org.au'
Subject: Re: [SLUG] Reading a file into variables?


George Vieira wrote:
> open "file.txt" for input as #1
> while (eof(1))
>  count=count+1
>  input #1, line$(count)
> loop
> close #1
> 
> what's the Perl version of this? I can't seem to get it to read one line
> each into an array.. it always grabs the whole file...


sub read_data
{
   my $i=0;
   my @nospam.data_line;
   open (FILE, "data") ||
             die "Cannot open file for reading\!";
   while(<FILE>)
   {
      $data_line[$i] = $_;
      $i = $i + 1;
   }
  close(FILE);
}

It can be written in another million ways and also cleaner
but this is closer in style to what you have above. 
"Learning Perl" from O'Reilly is Excellent!


Mike

--------------------------------------------------------------------
Michael Lake
University of Technology, Sydney
Email: mailto:Mike.Lake@nospam.uts.edu.au Ph: 02 9514 1724 Fx: 02
9514 1628 
URL: http://www.science.uts.edu.au/~michael-lake/
Linux enthusiast, active caver and interested in anything
technical.
--------------------------------------------------------------------
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to slug-request@nospam.slug.org.au with
unsubscribe in the text
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to slug-request@nospam.slug.org.au with
unsubscribe in the text