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:
Help with elsif!

 



Aquilo
journeyman

Dec 14, 2000, 2:39 AM

Post #1 of 6 (827 views)
Help with elsif! Can't Post

if($des eq "") { $des = "$des";
}elsif ($des eq "") { $des = "No data"; }

How can I tell it if there is any content to use it, elsif No Data?
Thanks!



CuzDesign
Deleted

Dec 14, 2000, 2:59 AM

Post #2 of 6 (823 views)
Re: Help with elsif! [In reply to] Can't Post

Hello,
You could do it 2 ways.

Way number 1

if ($des eq "") {
$des = $des;
}else{
$des = "No Data";
}

or

if ($des ne "") {
$des = "No Data";
}else{
$des = $des;
}

The first one checks to see if $des has nothing if is doesn't than we do the make $des = $des if there is something thatn we make $des = "No Data"

The second does the samething just in reverse.

Hope this helps.

Regards,
Ray



Aquilo
journeyman

Dec 14, 2000, 3:24 AM

Post #3 of 6 (822 views)
Re: Help with elsif! [In reply to] Can't Post

yep thanks! I was looking at the parse section to my login script and went DAAAAAA just reverse it!

Thanks!!!!



rGeoffrey
User / Moderator

Dec 14, 2000, 6:13 PM

Post #4 of 6 (813 views)
Re: Help with elsif! [In reply to] Can't Post

This looks like a time to use "or equal" (||=).

Just as you can say += or -= you can say ||=.

$des ||= 'no data';

is the same things as saying...

$des = $des || 'no data';

And because || will short circuit as soon as it finds a TRUE value this will do what you want. Remember that in perl we get FALSE values for 0 and the empty string "".

So we have these examples..


Code
my $des = 'something'; 
$des ||= 'no data';

# the value of $des is now 'something'

#-----------------

my $des = "";
$des ||= 'no data';

# the value of $des is now 'no data'



zanardi
journeyman

Dec 15, 2000, 2:02 PM

Post #5 of 6 (796 views)
Re: Help with elsif! [In reply to] Can't Post

or:

$des = $des ? $des : "No Data";
print $des;

print $des ? $des : "No Data";
^ will do the same as the above 2 lines

My BBS


Aquilo
journeyman

Dec 15, 2000, 4:50 PM

Post #6 of 6 (793 views)
Re: Help with elsif! [In reply to] Can't Post

Thank I'll jot that down, great resource info!:)


 
 


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

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