Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^4: var comparison

by nemesisgus (Acolyte)
on Sep 08, 2012 at 18:32 UTC ( #992518=note: print w/replies, xml ) Need Help??

in reply to Re^3: var comparison
in thread var comparison

Yes, that's one of the solutions MidLifeXis proposed and I think it's also considered a Perl "best practice".

Replies are listed 'Best First'.
Re^5: var comparison
by LanX (Bishop) on Sep 08, 2012 at 18:42 UTC
    hmm, nobody gave you a code example ?

    DB<100> @option{qw/a b c/}=() => (undef, undef, undef) DB<101> exists $option{a} => 1 #true DB<102> exists $option{d} => "" #false

    but smart-match should be safe as long as you don't forget the quotes.

    Cheers Rolf

      Nice hash slice, thanks!

      Just let me polish up your code so other newbies don't get confused:

      my %option; @option{qw/a b c/}=(); # my %option = ( # 'a' => undef, # 'b' => undef, # 'c' => undef # ); exists $option{a} and print 'true'; exists $option{d} or print 'false';

      PS: what the h**l is DB <...> ?

        DB <...> : the code was run under the debugger. Example of a debugger session:
        $ perl -de 42 Loading DB routines from version 1.32 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 42 DB<1> %hash = qw( a 1 b 2 c 3 d 4 ); DB<2> print %hash c3a1b2d4 DB<3> print scalar %hash 4/8 DB<4> $hash{e} = undef DB<5> print scalar %hash 5/8 DB<6> print "true" if defined $hash{e} DB<7> print "true" if exists $hash{e} true DB<8>

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992518]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2018-06-24 13:32 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.