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:
Perl- varying a set of scalars depending on which part of an array

 



bawy
Deleted

Jun 9, 2000, 4:08 PM

Post #1 of 6 (847 views)
Perl- varying a set of scalars depending on which part of an array Can't Post

I am trying to substitute a set of scalar values depending on where in the array so I can print new content for each multiple set of values I can only get it to aknowlege the last item in the array though?! PLEASE HELP, URGENT!
print "Content-type: text/html\n\n";
foreach $key (sort keys(%formdata)) {
}
$0010 = ($dr, $name, $degree, $email, $rate, $slide, $area) = ("0010", "John Quincy", "Ph.D.", "John.Quincy", "1.01", "test1", "drug abuse");
$0011 = ($dr, $name, $degree, $email, $rate, $slide, $area) = ("0011", "Joe Adams", "BA", "Joe.Adams", "1.55", "test2", "prophecy issues");
$0012 = ($dr, $name, $degree, $email, $rate, $slide, $area) = ("0012", "Frank Lester", "MA", "Frank.Lester", "0.20", "test3", "rehab");
$0013 = ($dr, $name, $degree, $email, $rate, $slide, $area) = ("0013", "Martha Stewert", "Ph.D.", "martha.stewert", "1.01", "test4", "overdose");

@info = ($0010, $0011, $0012, $0013);

for ($i = 0; $i <= $#info; $i++) {

print <<"midsection";
<html><head><title>$name, $degree</title>
<body>
$dr, $name, $degree, $email, $rate, $slide, $area
</body></html>
midsection
}


dws
Deleted

Jun 9, 2000, 6:33 PM

Post #2 of 6 (847 views)
Re: Perl- varying a set of scalars depending on which part of an array [In reply to] Can't Post

There are a bunch of problems here, not the least of which is that the code emits invalid HTML, unless you're later going to split it into individual pages. I'll assume that you are.

You're not actually building up an array to index. The reason you're seeing the last set of values is that the code overwrites $dr, $name, et al. four times. The last time wins.

Try something like:
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


push @info, ["0010", "John Quincy", "Ph.D.", "John.Quincy", "1.01", "test1", "drug abuse"];
...
push @info, ["0013", "Martha Stewert", "Ph.D.", "martha.stewert", "1.01", "test4", "overdose"];

foreach @info {
($dr, $name, $degree, $email, $rate, $slide, $area) = @{$_};

print <<"midsection";
<html><head><title>$name, $degree</title>
<body>
$dr, $name, $degree, $email, $rate, $slide, $area
</body></html>
midsection
}
</pre><HR></BLOCKQUOTE>



[This message has been edited by dws (edited 06-09-2000).]


bawy
Deleted

Jun 9, 2000, 9:12 PM

Post #3 of 6 (847 views)
Re: Perl- varying a set of scalars depending on which part of an array [In reply to] Can't Post

Thanks, I am a step closer, but the

foreach @info {
...
}

is returning an error. I can not figure out why?

Yes, I plan to have it write a file for each page generated that is why there is an opening and closing HTML tag for each page generated. The browser however views this normally anyway, even if it is not correct.


dws
Deleted

Jun 9, 2000, 9:25 PM

Post #4 of 6 (847 views)
Re: Perl- varying a set of scalars depending on which part of an array [In reply to] Can't Post

A typo, and a fairly obvious one at that. Try

foreach ( @info ) {

and invest some time with a good Perl book.


bawy
Deleted

Jun 9, 2000, 9:35 PM

Post #5 of 6 (847 views)
Re: Perl- varying a set of scalars depending on which part of an array [In reply to] Can't Post

Thanks alot! Actually I read a hundred or so pages of a perl book a couple nights ago and that is the limit of my knowledge. I really have very limited time to learn and need to immidiatly put it to use, wish I had more. I have the same dilema with ASP right now (read a couple hundred pages in a night and have projects to get through.) Talk about crash course! I am used to javascript style formating (which is just more reason I should have seen that particular typo) but I am not used to the more traditional programming style of formatting that perl uses and am not sure when something is wrong or supposed to be like that. If you have any recomendations of good tutorials or other forums they would be very much appreciated.


dws
Deleted

Jun 9, 2000, 11:21 PM

Post #6 of 6 (847 views)
Re: Perl- varying a set of scalars depending on which part of an array [In reply to] Can't Post

I got a lot of mileage out of studying -- and occassionally puzzling over -- the code and commentary in Randal Schwartz's Web Techniques columns. They're available on-line at http://www.stonehenge.com/merlyn/WebTechniques/

Follow the link there and buy a copy of Learning Perl.


 
 


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

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