Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Dangerous Names

by Anonymous Monk
on Dec 18, 2008 at 10:49 UTC ( [id://731220]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Dangerous Names
in thread Dangerous Names

Pretty much everything else in Perl is happy to treat undef as 0, why not sort?
I think you're confused
D:\>perl -wle"print undef" Use of uninitialized value in print at -e line 1. D:\>perl -wle"warn undef" Use of uninitialized value in warn at -e line 1.
Nothing in perl treats undef as 0 without barfing
D:\>perl -we"print 1 <=> undef Use of uninitialized value in numeric comparison (<=>) at -e line 1. 1 D:\>perl -we"print 1 + undef Use of uninitialized value in addition (+) at -e line 1. 1 D:\>perl -we"print 1 - undef Use of uninitialized value in subtraction (-) at -e line 1. 1 D:\>

Replies are listed 'Best First'.
Re^4: Dangerous Names
by tinita (Parson) on Dec 18, 2008 at 11:36 UTC
    >> Pretty much everything else in Perl is happy to treat undef as 0, why not sort?
    > I think you're confused
    [...]
    These are just warnings. sort dies, that's the difference. So if you don't have warnings on, you can do string comparisons with <=> as long as you want, and suddenly with a special input your script will die instead of only warn.
    I see it as another encouragement to always use warnings =)
      Whatcha talkin bout Willis?
      D:\>perl -we"print for sort { warn qq,($a)($b),; $a <=> $b } 2, 1, 4 , + undef, undef, 3, 'nan','nan','inf','inf'" (2)(1) at -e line 1. Use of uninitialized value in concatenation (.) or string at -e line 1 +. (4)() at -e line 1. Use of uninitialized value in numeric comparison (<=>) at -e line 1. Use of uninitialized value $a in concatenation (.) or string at -e lin +e 1. ()(3) at -e line 1. Use of uninitialized value in numeric comparison (<=>) at -e line 1. (nan)(nan) at -e line 1. (inf)(inf) at -e line 1. Use of uninitialized value in concatenation (.) or string at -e line 1 +. (1)() at -e line 1. Use of uninitialized value in numeric comparison (<=>) at -e line 1. (1)(4) at -e line 1. (2)(4) at -e line 1. Use of uninitialized value $a in concatenation (.) or string at -e lin +e 1. Use of uninitialized value in concatenation (.) or string at -e line 1 +. ()() at -e line 1. Use of uninitialized value in numeric comparison (<=>) at -e line 1. Use of uninitialized value in numeric comparison (<=>) at -e line 1. Use of uninitialized value $a in concatenation (.) or string at -e lin +e 1. ()(1) at -e line 1. Use of uninitialized value in numeric comparison (<=>) at -e line 1. (1)(3) at -e line 1. (3)(2) at -e line 1. (3)(4) at -e line 1. (nan)(inf) at -e line 1. (inf)(nan) at -e line 1. Use of uninitialized value $a in concatenation (.) or string at -e lin +e 1. ()(nan) at -e line 1. Use of uninitialized value in numeric comparison (<=>) at -e line 1. Use of uninitialized value in concatenation (.) or string at -e line 1 +. (nan)() at -e line 1. Use of uninitialized value in numeric comparison (<=>) at -e line 1. (nan)(1) at -e line 1. (1)(nan) at -e line 1. (1)(inf) at -e line 1. (1)(inf) at -e line 1. Use of uninitialized value $_ in print at -e line 1. Use of uninitialized value $_ in print at -e line 1. nannaninfinf1234
      I dont see how that can happen, except like
      D:\>perl -e"print sort { $a <=> $b } undef, 1, undef, 2" 12 D:\>perl -e"print sort { $a <=> $b;undef } undef, 1, undef, 2" Sort subroutine didn't return a numeric value at -e line 1.
      which is kind of stupid
        Whatcha talkin bout Willis?
        My nickname is tinita.
        Go read the original posting.
        perl -wle'@a = sort { print "$a <=> $b"; $a <=> $b } 2, 3, "nan"; print "\@a = @a";' 2 <=> 3 2 <=> nan Sort subroutine didn't return a numeric value at -e line 1.
        So where's the last print statement? It isn't executed. sort dies. Or what exactly was your question?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-26 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found