Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Dangerous Names

by samtregar (Abbot)
on Dec 17, 2008 at 22:07 UTC ( [id://731076]=note: print w/replies, xml ) Need Help??


in reply to Re: Dangerous Names
in thread Dangerous Names

Right, that's half the battle. Furthermore, sort barfs on undefs, which I find very odd. Pretty much everything else in Perl is happy to treat undef as 0, why not sort?

-sam

Replies are listed 'Best First'.
Re^3: Dangerous Names
by Anonymous Monk on Dec 18, 2008 at 10:49 UTC
    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:\>
      >> 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

Log In?
Username:
Password:

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

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

    No recent polls found