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

 



bawy
Deleted

Jun 9, 2000, 4:06 PM

Post #1 of 3 (528 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
}


bawy
Deleted

Jun 12, 2000, 10:54 PM

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

thanks, but I already figured another way using PUSH.


TheGame+
Deleted

Jun 13, 2000, 3:44 AM

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

You could use an array of hashes for this.

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

@info = (
{
dr => '0010',
name => 'John Quincy',
degree => 'Ph.D.',
email => 'John.Quincy',
# some more fields here
},
{
dr => '0011',
name => 'Joe Adams',
degree => 'BA',
email => 'Joe.Adams',
# and so on
},
# some more records here
);

# print the whole thing with refs
foreach $href (@info) {
print join(', ',$href->{dr},$href->{name},$href->{degree}),"\n"; # some more fields here
}
</pre><HR></BLOCKQUOTE>

See 'perldoc perldsc' for more information on how to build this, print it etc.

 
 


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

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