Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Re: cgi buffer flush

by dorko (Prior)
on Mar 09, 2002 at 18:29 UTC ( #150594=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re: Re: Re: Re: cgi buffer flush
by dvergin (Monsignor) on Mar 09, 2002 at 20:49 UTC
          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

Re: Re: Re: Re: cgi buffer flush
by fuzzyping (Chaplain) on Mar 09, 2002 at 18:39 UTC
    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://150594]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2021-10-23 23:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (88 votes). Check out past polls.

    Notices?