in reply to Error in Camel Book Ver2?

Nope, no error there. $pi ||= 3 is basically equivalent to $pi = ($pi || 3) which could be described as "If $pi doesn't already have a true value, then set $pi's value to 3." (The 'true' part should not be overlooked.)

So, you could write your assignment as: $list_info{subscribed_message} ||= $subscribed_message; That will set the value of $list_info{subscribed_message} to the value of $subscribed_message, if $list_info{subscribed_message} doesn't exist, or is undef, "", or 0.

Replies are listed 'Best First'.
Re: Re: Error in Camel Book Ver2?
by Anonymous Monk on Dec 21, 2000 at 11:19 UTC

    if I make a script that says:

    $pi ||= 3 print $pi;

    I'll get back something like

    syntax error at or.pl line 1, near "|| ="

    So the way its written won't work

    I wonder if this will be different if your testing a hash, since you use exists() instead of defined();

      syntax error at or.pl line 1, near "|| ="
      That's a Perl4 (or earlier) error message. Please upgrade to a version of Perl that was released sometime after the Spice Girls hit the pop charts.

      -- Randal L. Schwartz, Perl hacker

        merlyn, I've gotta say this was a great laugh for this morning =] Maybe future versions of perl should be named after the current music sensation of the time of release. =]

        [marius@marius.org ~]$ perl -v This is perl, the N'Sync version built for i386-freebsd Copyright 1987-1999, Larry Wall ...

        -marius
        Perl 4 didn't support overloading = with ||?

        If so, did it support the = and || operators?

        And if so, couldn't we use this: $value = $value || 'DEFAULT'; to accomplish the same thing?

        (Not that I don't support the idea of upgrading Perl to a recent version, but the Spice Girls are pretty old news themselves. *grin*)

      The code that you provide there is not the code giving you that error message. The error message you list indicates that you have an extraneous space in ||=. ||= should not have any spaces.

      The code you provided will give you an entirely different error, namely syntax error at - line 2, near "print" since you didn't have a semicolon at the end of the first line.

        ahh,

        huh,

        hmm,

        that's a weird place for spaces to make a difference, since,

        $pi = $foo || 67;

        will work, oh well, thanks everyone,

        thinks for a minute, ....

        Ohhh i see, ||= is an assignment operator, sweet cake, thanks everyone

         

        -justin simoni
        !skazat!