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

Re^4: check parameters

by Corion (Pope)
on Apr 08, 2013 at 14:34 UTC ( #1027522=note: print w/replies, xml ) Need Help??

in reply to Re^3: check parameters
in thread check parameters

What is wrong with the code hdb gave you?

That code does not have the problem your code has, so why are you not using it?

As a hint, a string is always true in Perl. And your code simply constructs a string but never matches against it:

... if ("(".join('|', @{$opts->{params}}).")" # This constructs a string and !grep { /^$_/i } keys %$format) # and this matches $_ agains +t itself ...

Replies are listed 'Best First'.
Re^5: check parameters
by hdb (Prior) on Apr 08, 2013 at 14:41 UTC

    ag4ve, can you pls state what you want to achieve? Here is what happens step-wise:

    my $pattern ="(".join('|', @{$opts->{params}}).")"; # pattern is now "(a|b)" my @test = grep { /^$pattern/i } keys %$format; # @test = ( "bar", "abc" )

    !grep... puts grep into scalar context, ie it will return 2, the length of @test above. !2 is false therefore your "if" block will not be executed.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2017-07-26 19:33 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (400 votes). Check out past polls.