Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Minimisation of codes (if grep {})

by Laurent_R (Canon)
on Oct 01, 2015 at 11:16 UTC ( [id://1143518]=note: print w/replies, xml ) Need Help??


in reply to Minimisation of codes (if grep {})

You'll need to change statement modifiers:
do_something() if ...
to standard conditionals:
if ($some_condition) { do_something(); }
to be able to use else statements as suggested by Corion:
if ($intermediate_array[12] eq "GSM") { if (grep { /^\Q$intermediate_array[11]\E$/ } @subscriber_error +) { $MO_userdep_error++ ; } elsif (grep { /^\Q$intermediate_array[11]\E$/ } @network_erro +r) { $MO_network_error++; } else { $MO_system_error++ if grep { /^\Q$intermediate_array[11]\E +$/ } @system_error; } }
As mentioned by Athanasius, replacing grep by the any function of List::Utils module is also likely to speed up your program.

Also, testing for string equality might be slightly faster than a regex.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-18 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found