CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
quick question

 



Mel
Deleted

Jun 29, 2000, 4:40 PM

Post #1 of 2 (170 views)
quick question Can't Post

what is the best way to read the contents of a file into an arry but do not readin blank lines.


DrZed
User

Jun 29, 2000, 7:10 PM

Post #2 of 2 (170 views)
Re: quick question [In reply to] Can't Post

Ok, assuming that you want each line to be an entry in the array, try the following:

#!/usr/bin/perl -w

open (FILE,"<filename.ext") &#0124; &#0124; die $!;
# flock(FILE,1); # Use flock if your server/OS allows file locking.
{ local ($/) = undef; $data = <FILE>; }
close (FILE);

$data=~s/\n+/\n/g;
@array = split(/\n/,$data);

The "$data=~s/\n+/\n/g" will get rid of blank lines and the split will create the array.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives