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:
getting a else after a bad hash

 



Aquilo
journeyman

Feb 3, 2001, 2:40 AM

Post #1 of 2 (319 views)
getting a else after a bad hash Can't Post


Code
#!/usr/local/bin/perl 

%Services = (
'Xtram' => 'mail.xtram.com',
'Ev90' => 'ev90.mail.everyone.net',
'3lE' => '3le.mail.everyone.net',
'GeoSims' => 'geosims.mail.everyone.net'
);

@service = sort(keys(%Services));
foreach $value(@service){
if ($in{'Service'} =~ /$value/){
print "Location: http:\/\/$Services{$value}\/$Script\n\n";
}
}



Question: how do I place an " else " for
if ($in{'Service'} =~ /$value/){
print "something";
} else {
print "Content-type: text/html\n\n";
print "This part is not working";
}

All I get is
Content-type: text/html This part is not working
Content-type: text/html This part is not working
Content-type: text/html This part is not working
Content-type: text/html This part is not working
script.pl?Service=Xtram&password=xxxx&username=xxxx

times* the number elaments in the hash then the string
I also tryed puting it after the end of
foreach $value(@service){
if ($in{'Service'} =~ /$value/){
print "Location: http:\/\/$Services{$value}\/$Script\n\n";
}
} else {
print "error";
} # didn't work

I've tryed using a sub like

} else {
&noservice;
}

but that gives me errors! something is not going my way!

Thanks for any help! :)



kencl
User

Feb 4, 2001, 1:01 AM

Post #2 of 2 (313 views)
Re: getting a else after a bad hash [In reply to] Can't Post

You can put the if else block inside the foreach loop. Your problem is that

@service = sort(keys(%Services));

should be

@service = sort(values(%Services));

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!

 
 


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

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