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:
splitting data lines into array

 



carpedout
stranger

Oct 5, 2001, 3:05 PM

Post #1 of 2 (550 views)
splitting data lines into array Can't Post

This is so easy I'm sure it's laughable, but I'm not sure how to split the lines into an array without ending up with a comma at the last entry. So, while ya'll chuckle - please help!

I have a simple external db (simple.dat) file similar to:

line 1
line 2
line 3

(single fields, no delimeters)

and I want to read that data file's lines and put them into an array so:

# however many lines from simple.dat
@linez = ("line1","line2","line3") ;

Once it's in array, I can do more with it, of course :) What's the simplest way to do that?

Thanks....



mhx
Enthusiast / Moderator

Oct 5, 2001, 3:31 PM

Post #2 of 2 (549 views)
Re: splitting data lines into array [In reply to] Can't Post

This should do exactly what you want:

Code
open FILE, 'simple.dat' or die "cannot open simple.dat: $!\n"; 
chomp( @lines = <FILE> );
close FILE;

<FILE> reads all lines into @lines and chomp() will remove the linebreaks from each line.
Hope this helps.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"


 
 


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

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