Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: cgi buffer flush

by fuzzyping (Chaplain)
on Mar 09, 2002 at 12:06 UTC ( #150547=note: print w/replies, xml ) Need Help??


in reply to Re: cgi buffer flush
in thread cgi buffer flush

Isn't "$|++" the same as "$|=1"?

-fuzzyping

Replies are listed 'Best First'.
Re: Re: Re: cgi buffer flush
by dorko (Prior) on Mar 09, 2002 at 18:29 UTC
    Isn't "$|++" the same as "$|=1"?

    A lot of people seem to think it is, but it's not.

    • $|++ adds one to the current value of $|.
    • $| = 1 sets the value of $| equal to one.
    If for some reason $| = -1, doing a $|++ will make $| = 0, and usually that is not what $|++ is meant to do.

    $| = 1 is much safer and more straight forward (less ambiguous?).

    Update: Whoops. I was way wrong. A thousand lashes to me for misleading my fellows due to my neglectful ignorance. Thanks to dvergin for the correction and for setting me straight..

    Cheers!

    Brent

    -- Yeah, I'm a Delt.

            If for some reason $| = -1,...

      No. Please don't make assertions like that when you haven't tested them.

      $| is magic. It always equals either zero or one. Nothing else. Behold:

      print "$|\n"; # 0 $| = -1; print "$|\n"; # 1 $|++; print "$|\n"; # 1 $|++; print "$|\n"; # 1 $|--; print "$|\n"; # 0 $|--; print "$|\n"; # 1 $|--; print "$|\n"; # 0
      As you can see, $|++ always sets $| to one (no matter what it was) and $|-- always toggles it.

      I agree that $| = 1; is more clear to newer programmers. But rationalle for that usage has to do with the learning curve and not with the behavior of $|.

      ------------------------------------------------------------
      "Perl is a mess and that's good because the
      problem space is also a mess.
      " - Larry Wall

      Makes perfect sense, but under what circumstances would $|=-1, unless those where you specifically defined it as such? I can see where it would be a much better idea to use $|=1 so you don't mistakenly define $| to 2 (or higher).

      OTOH, why haven't more folks discussed the use of the FileHandle or IO modules that support the autoflush method? Wouldn't that negate this argument altogether?

      -fuzzyping
              so you don't mistakenly define $| to 2...

        That won't happen. See my response to dorko for a demonstration of the magical character of $|.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2021-02-27 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?