Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: Numification of strings

by eyepopslikeamosquito (Canon)
on Aug 03, 2010 at 04:54 UTC ( #852595=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use strict;
    use warnings;
    my $x = "2abc";
    my $y = $x + 42;
    print "x=", $x, " y=", $y, "\n";
    
  2. or download this
    Argument "2abc" isn't numeric in addition (+) at f.pl line 4.
    x=2abc y=44
    
  3. or download this
    x = "2abc"
    y = x + 42
    print "x=", x, "y=", y, "\n"
    
  4. or download this
    Traceback (most recent call last):
      File "f.py", line 2, in <module>
        y = x + 42
    TypeError: cannot concatenate 'str' and 'int' objects
    
  5. or download this
    x = "2abc"
    y = int(x) + 42
    print "x=", x, "y=", y, "\n"
    
  6. or download this
    Traceback (most recent call last):
      File "f2.py", line 2, in <module>
        y = int(x) + 42
    ValueError: invalid literal for int() with base 10: '2abc'
    
  7. or download this
    x = "2abc"
    y = int(x[0:1]) + 42
    print "x=", x, "y=", y, "\n"
    
  8. or download this
    x= 2abc y= 44
    
  9. or download this
    x = "2abc"
    y = x + 42
    print "x=", x, "y=", y, "\n"
    
  10. or download this
    f.rb:2:in `+': can't convert Fixnum into String (TypeError)
        from f.rb:2
    
  11. or download this
    x = "2abc"
    y = x.to_i() + 42
    print "x=", x, " y=", y, "\n"
    
  12. or download this
    x=2abc y=44
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (16)
As of 2015-07-07 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (90 votes), past polls