Hi hw!

Please see
http://www.shlomifish.org/philosophy/computers/netiquette/email/reply-to-list.html
.

On Sat, 1 Jul 2017 19:15:22 +0200 hw <h...@gc-24.de> wrote:

> Shlomi Fish wrote:
> > Hi Shawn!
> >
> > On Sat, 1 Jul 2017 11:32:30 -0400
> > Shawn H Corey <shawnhco...@gmail.com> wrote:
> >  
> >> On Sat, 1 Jul 2017 17:27:02 +0200
> >> hw <h...@gc-24.de> wrote:
> >>  
> >>>
> >>> Hi,
> >>>
> >>> can someone please explain this:
> >>>
> >>>
> >>> perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
> >>> i:
> >>>
> >>>
> >>> Particularly:
> >>>
> >>>
> >>> + Why doesn´t it print 1?  
> >>
> >> Because !!$i is zero
> >>  
> >>>
> >>> + How is this not a bug?  
> >>
> >> Nope, no bug.
> >>  
> >>>
> >>> + What is being printed here?  
> >>
> >> !!$i which is !(!(0)) which is !(1) which is 0
> >>  
> >
> > I suspect !1 returns an empty string in scalar context.  
> 
> What would be the reasoning for a numerical operator turning
> numerical values into (empty) strings within a numerical context?
> 

"!" is not a numerical operator - it is a *logical* operator. If one passes a
true value to it one gets a false value. Else, one gets a true value. See
http://perldoc.perl.org/perlop.html . If used in a numerical context, false
values are treated as zeroes, but not all of them are zeroes in other contexts.

Regards,

        Shlomi


> 
> 
> >  
> >>>
> >>> + How do you do what I intended in perl?
> >>>  
> >>
> >> How do we know what you intend?
> >>
> >>  
> >
> >
> >  
> 



-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/

Real programmers don’t write workarounds. They tell their users to upgrade
their software.
    — http://www.shlomifish.org/humour.html

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to