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: Intermediate:
File data

 



mrsrx
Deleted

Jan 21, 2001, 9:20 AM

Post #1 of 2 (174 views)
File data Can't Post

Hello everyone!

The file on my server has two pieces of information formatted like this:
string1|string2
and as you can see, the two strings are separated by a "|"

I was looking for the code that will get the contents of a file and separate two strings from an open (I already have OPEN and CLOSE, and all I need is that code for getting the content and separate it).
This would save me the use of two files.

Thanks in advance!

Srx



pu_nk
journeyman

Jan 21, 2001, 10:03 AM

Post #2 of 2 (172 views)
Re: File data [In reply to] Can't Post

If i read your post properly i assume this is what you would be looking for..
Here is some code that may help you out to "split" the data in the file..

$datafile = "cool.txt";
print "Content-type: text/html\n\n";
open (FILE, "$datafile") || print "Could not open $datafile ($!)";
flock FILE, 2;
@data=<FILE>;
flock FILE, 8;
close(FILE);

foreach $line (@data) {
chomp $line;


#This line depends on how many items you have in the file .
#THe way you arrange the idems is buy separating them with commas.
#In this example i made it look like the file contained 3 items (Kelly|23|blond)


($item1,$item2,$item3)=split(/\|/,$line);
print "$item1 is $item2 in age and has $item3 hair\n";
}


have fun





 
 


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

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