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:
unshift @contents, $_ while(<FILE>)

 



vallely
Novice

Mar 14, 2001, 3:07 PM

Post #1 of 2 (432 views)
unshift @contents, $_ while(<FILE>) Can't Post

I checked the FAQs looking for a way to display a very simple database in reverse in HTML. The appropriate post was the very last post of the 1200 or so in the list. Go figure.... This is what I got

Can anyone tell me why it won't work?
I'm sure it's very simple.
I am a true beginner.



open FILE, "file.txt" or die "can't read file: $!";
print "Content-type: text/html", "\n\n";
unshift @contents, $_ while(<FILE>) {($name, $email, $itemname, $desc, $city, $state) = split /\|/;
print "<font face=arial size=3><B>Name:</B> $name\n";
print "
\n";
print "<B>Email</B>\n";
print "<a href='mailto:$email'>\n";
print "$email\n";
print "</A>\n";
print "
\n";
print "<B>Item Name:</B> $itemname\n";
print "
\n";
print "<B>Description:</B> $desc\n";
print "
\n";
print "<B>City:</B> $city\n";
print "
\n";
print "<B>State:</B> $state\n";
print "
\n";
print "<hr>\n";
print "
\n";
print "</font>\n";



}
close(FILE);





japhy
Enthusiast

Mar 14, 2001, 5:27 PM

Post #2 of 2 (430 views)
Re: unshift @contents, $_ while(<FILE>) [In reply to] Can't Post

You're trying to use a post-fix while expression as a regular-style while loop. Perhaps you meant:


Code
while (<FILE>) { 
chomp;
unshift @contents, $_;
my ($a,$b,$c) = split /\|/;
# ...
}

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


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

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