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:
How does this While loop semantic work?

 



efedotov
New User

Mar 3, 2015, 8:07 PM

Post #1 of 2 (2594 views)
How does this While loop semantic work? Can't Post


Code
while ($tag->[1]{title} and $tag->[1]{title} ne 'next'){ 
$tag = $stream->get_tag("a");
}


I don't understand what's the point of having two of the same values being AND'd. What's the point of having

Code
$tag->[1]{title} and $tag->[1]{title}

?


(This post was edited by efedotov on Mar 3, 2015, 8:11 PM)


BillKSmith
Veteran

Mar 3, 2015, 9:20 PM

Post #2 of 2 (2585 views)
Re: [efedotov] How does this While loop semantic work? [In reply to] Can't Post

Perhaps this equivalent code would be clearer.


Code
while ( ($tag->[1]{title}) and ($tag->[1]{title} ne 'next') ){  
$tag = $stream->get_tag("a");
}


The 'and' and its left-hand argument are needed to handle the special case when $tag->[1]{title} is false (either undefined, 0, or an empty string). It is intended to prevent the warning "Use of undefined variable in ....". Note that when the left-hand argument is false, the right-hand argument is not even evaluated (because of "short-circuit" processing).
Good Luck,
Bill

 
 


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

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