Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^3: Perl bug ?

by choroba (Bishop)
on Feb 06, 2013 at 12:13 UTC ( #1017400=note: print w/replies, xml ) Need Help??

in reply to Re^2: Perl bug ?
in thread Perl bug ?

Update: Disregard. See rather Re^5: Perl bug ?.

The order in which arguments to subroutines are processed is not guaranteed:

sub test { say for @_ } test($x=0, $x=$x+1, $x++, ++$x);
3 3 1 3
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^4: Perl bug ?
by tinita (Parson) on Feb 06, 2013 at 12:42 UTC
    no? I don't see your example as a proof for that.
    argument 1: $x=0 $x is set to 0 and $x (or an alias) is passed as argument 1
    argument 2: $x=$x+1 $x is set to 0+1 = 1 and $x (or an alias) is passed as argument 2
    argument 3: $x++ $x is incremented and the return value of the post increment (1) is passed as the argument 3
    argument 4: ++$x $x is incremented and the return value of the pre increment (3) is passed as argument 4.

    $x is now 3.
    argument 1 is an alias for $x. 3
    argument 2 is an alias for $x. 3
    argument 3 is 1.
    argument 4 is 3.
      You are right. I was on a wrong track.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^4: Perl bug ?
by vsespb (Chaplain) on Feb 06, 2013 at 12:18 UTC
    but anyway this
    ($errors && ($errors->[0] =~ /Journal file not found/i))
    should be true only and only if $errors->[0] contains Journal file not found ?
      Hmmm... strange. Can be simplified to
      perl -E 'my $e; say for $e && 0, $e->[0];'
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        seems like the arguments for "for" are executed first and then the loop body. so:
        the first element is $e && 0 which evaluates to $e. then the second argument is processed, autovivify happens.
        when in the loop body, $e is an array reference already, and because the first element is an alias to $e it prints ARRAY(0xde0d48). seems logical to me.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017400]
[Corion]: Meh ... Minion really doesn't want to run under the fork() emulation on Windows (which I understand), but has no other way either (which I find inconvenient)
[Corion]: Other than that, it seems really polished

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2018-06-21 14:53 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.