Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Dangerous Names

by tinita (Parson)
on Dec 18, 2008 at 11:36 UTC ( [id://731228]=note: print w/replies, xml ) Need Help??


in reply to Re^3: 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
[...]
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 =)

Replies are listed 'Best First'.
Re^5: Dangerous Names
by Anonymous Monk on Dec 18, 2008 at 13:39 UTC
    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?
        Dammit, Jim
        D:\>perl -wle"@a = sort { print qq,$a <=> $b,; $a <=> $b } 2, 3, qq,na +n,;print for @a 2 <=> 3 2 <=> nan nan 2 3
        Do you even look at what I post? It doesn't die for me. Perl 5.8/5.10

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found