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

Re: Is this bad coding style?

by bobf (Monsignor)
on Jan 08, 2009 at 04:16 UTC ( [id://734796]=note: print w/replies, xml ) Need Help??


in reply to Is this bad coding style?

I know this is just an example, but strict and warnings can help nonetheless. In this case you define @arrray and loop over @array. OK, that's out of my system. :-)

A dispatch table might help, especially if you've got a lot of special cases. For example:

my %dispatch = ( '#' => \&sub1, 1 => \&sub2, ); my @array = (1, 2, 3, '#', 6, 7, '#', 9, 10); # corrected typo! foreach (@array) { if( exists $dispatch{$_} ) { $dispatch{$_}->(); } else { sub3(); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 02:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found