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

Re: Whatever happened to chomp?

by derby (Abbot)
on Dec 14, 2003 at 15:33 UTC ( [id://314642]=note: print w/replies, xml ) Need Help??


in reply to Whatever happened to chomp?

As others have pointed out, it is perl DWYM but exactly how does it do that? Well if you look at perl internals, a scalar value can be a string, an integer or a double (or another scalar). By context, it determines which value to use. In a numeric context (==), it will use one of the numeric (integer or double), in a string context, (eq), the string value.

Check this out:

#!/usr/bin/perl use strict; use warnings; use Devel::Peek qw( Dump ); while (my $data = <DATA>) { chomp $data; print Dump( $data ); if ($data == 2){print "->got 2\n"} } print "Enter a 2\n"; my $input = <>; print Dump( $input ); if ($input == 2){print "->got 2\n"} __DATA__ 1 2 3 4

-derby

Log In?
Username:
Password:

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

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

    No recent polls found