Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: shift in list context buggy? (best answer so far!)

by LanX (Canon)
on Nov 09, 2013 at 14:39 UTC ( #1061829=note: print w/ replies, xml ) Need Help??


in reply to Re: shift in list context buggy? (scalar)
in thread shift in list context buggy?

Thx!

But

> Consider the relative difficulty of fixing your problem case vs. my counter-factual problem case:

while(  $x  = shift @a ) {    # Fixed

this is not a fix because while stops, if any element of @a is false.

DB<187> @a=(1,undef,2,3,0,4,5) DB<188> print $x while $x =shift @a 1 DB<189> print $x while $x =shift @a 23 DB<190> print $x while $x =shift @a 45 DB<191> print $x while $x =shift @a

Thats the old semipredicate problem, which can only be solved with list-assignments.

But I agree with you that it's most probably too late to fix that design decision...

Cheers Rolf

( addicted to the Perl Programming Language)

) for completeness: no defined doesn't help here, if undef is a legal value.

updates
  • corrected "semipredicate problem"
  • improved code example
  • your "better" update is indeed better

) best answer so far


Comment on Re^2: shift in list context buggy? (best answer so far!)
Select or Download Code
Re^3: shift in list context buggy? (best answer so far!)
by AnomalousMonk (Monsignor) on Nov 09, 2013 at 17:57 UTC
    But I agree with you that it's most probably too late to fix that design decision...

    Amen to that, brother. Trying to fix | change this ancient design decision now would provoke sustained and piercing shrieks of anguish that would make the howls induced by the recent hash ordering 'fix' sound by comparison as mellow as a Hash Bash gathering!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1061829]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (16)
As of 2014-08-27 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (244 votes), past polls