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

Re: Test if multiple variables are defined

by AnomalousMonk (Canon)
on Jun 25, 2013 at 17:50 UTC ( #1040636=note: print w/replies, xml ) Need Help??

in reply to Test if multiple variables are defined

One More Way to Do It: grep:

>perl -wMstrict -le "my ($foo, $bar); my ($no_ws, $some_ws, $lotsa_ws) = ('no_ws', ' some_ws ', ' lotsa ws '); printf qq{'$_' } for $no_ws, $some_ws, $lotsa_ws; print ''; ;; s{ \A \s+ | \s+ \z }''xmsg for grep defined, $no_ws, $foo, $some_ws, $bar, $lotsa_ws; printf qq{'$_' } for $no_ws, $some_ws, $lotsa_ws; " 'no_ws' ' some_ws ' ' lotsa ws ' 'no_ws' 'some_ws' 'lotsa ws'

Update: However,  grep as used above has the disadvantage of creating an output list that may be the same size as the input list; Perl then has twice as much data to deal with.

The advantage of a looping statement like
    defined and s/^\s+|\s+$//g for LIST;
is that the elements of  LIST are operated on in place and no new list is created.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040636]
[GotToBTru]: no, lookup
[stevieb]: no, I mean have you considered using a dispatch table. an 80 condition if/else is huge :)
[GotToBTru]: that is how this should have been done, no question
[GotToBTru]: probably back when there were 5 or so clauses

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-06-22 13:03 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (520 votes). Check out past polls.