[oak perl] Re: [sf-perl] print Dumper \$|;
Paul Makepeace
Paul.Makepeace at realprogrammers.com
Thu Jan 16 11:57:01 CST 2003
On Thu, Jan 16, 2003 at 09:26:24AM -0800, Belden Lyman wrote:
> Paul Makepeace wrote:
> >On Wed, Jan 15, 2003 at 04:30:44PM -0800, Belden Lyman wrote:
> >
> >>Flush pipes, print $|:
> >>
> >> % perl -MData::Dumper -e '$|++; print Dumper \$|'
> >> $VAR1 = \'1';
> >>
> >>Okay, I believe that.
> >>
> >>Clog pipes, print $|:
> >>
> >> % perl -MData::Dumper -e '$|--; print Dumper \$|'
> >> $VAR1 = \'1';
> >>
> >>Huh? Same value? That can't be right though, because
> >
> >
> >This is a known perl oddity, and often used by golfers and obfuscators
> >as a toggler.
> >
> >$ perl -le 'print "p",--$|,"ng!" for 1..4'
> >p1ng!
> >p0ng!
> >p1ng!
> >p0ng!
> >$
> >
> >Paul
> >
>
>
> Sure, I know that. :)
>
> My intended question was, "How come Data::Dumper thinks $|-- has the
> same value as $|++ ?"
Because they *do* have the same value: --$| == ++$|
The use of Data::Dumper is a red herring here. You've accepted that $|
is magical but haven't shown in any way that DD is inconsistent with
simply printing its value.
> Your example is better at showing that $| obviously is changing value.
> But it doesn't explain why printing $| using Data::Dumper always gives
> back \'1', seemingly without regard to the actual value of $| at the
> time.
That's because you fiddled with it each time before you printed it :-)
To wit,
> >> % perl -MData::Dumper -e '$|++; print Dumper \$|'
> >> % perl -MData::Dumper -e '$|--; print Dumper \$|'
If you leave it unfettered it'll come back zero,
$ perl -MData::Dumper -e 'print Dumper \$|'
$VAR1 = \'0';
$
I could've misunderstood the question a second time, in which case I'll
just keep quiet from now :-)
Cheers,
Paul
PS Next post has to covertly use someone else's last name in it...
--
Paul Makepeace ....................................... http://paulm.com/
"If the answer is 5, then evolution will determine the colour."
-- http://paulm.com/toys/surrealism/
More information about the Oakland
mailing list