Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: var comparison

by Kenosis (Priest)
on Sep 06, 2012 at 19:46 UTC ( #992177=note: print w/replies, xml ) Need Help??


in reply to var comparison

Using smart matching (5.10+) is another option (unless 'clarity of intent' is compromised):

$var ~~ [qw/foo bar/];

Replies are listed 'Best First'.
Re^2: var comparison
by LanX (Chancellor) on Sep 06, 2012 at 23:39 UTC
    carefull! better always stringify if you're not sure that its not a ref "$var" ~~ [qw/foo bar/]

      Why, with the following expected behavior?

      use Modern::Perl; my $var1 = 'foo'; my $var2 = \$var1; say $var2; # prints SCALAR(0x2590b8) say "$var2"; # prints SCALAR(0x2590b8) say $var1 ~~ [qw/foo bar/]; # is true: prints 1 say $var2 ~~ [qw/foo bar/]; # is false: prints nothing say "$var2" ~~ [qw/foo bar/]; # is false: prints nothing
Re^2: var comparison
by nemesisgus (Acolyte) on Sep 06, 2012 at 22:00 UTC
    Thanks Kenosis. Smart matching promises to be a new friend from now on.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2016-10-01 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (7 votes). Check out past polls.