Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Concatnate long statement

by FunkyMonk (Canon)
on Jul 03, 2007 at 22:10 UTC ( #624801=note: print w/replies, xml ) Need Help??


in reply to Concatnate long statement

You really don't want a subroutine (it looks like that's what you're doing) with 18 arguments. It's going to cause you all sorts of problems when when you miss one of them out, or get some of them in the wrong order. That number of arguments really gives off a bad code smell.

Refactor your code now, before it's too late.

Replies are listed 'Best First'.
Re^2: Concatnate long statement
by Fletch (Chancellor) on Jul 04, 2007 at 00:05 UTC

    And if not refactor, at least switch to using pseudo-named arguments by expecting key/value pairs and appending those to defaults.

    sub womble { my @defaults = ( fleem => 12.3, alarm_low => 99, alarm_hi => 'naked ernest borgnine', alarm_hello => 'nice to see you', alarm_good_evening => STOP_STEALING_PYTHON_GAGS, quux => 19.95, ); my %args = ( @defaults, @_ ); if( $args{ quux } > 15 ) { enable_flux_capacitor(); } ## ... rest of womblification routine } womble( quux => 1.21 * GIGAWATS_PER_MICROFLEEM, alarm_low => 42, );
      A variation:
      use strict; use warnings; use Data::Dumper; my %WOMBLE_DEFAULTS = ( fleem => 12.3, alarm_low => 99, alarm_hi => 'naked ernest borgnine', alarm_hello => 'nice to see you', alarm_good_evening => 'STOP_STEALING_PYTHON_GAGS', quux => 19.95, ); my $DEBUG = 1; womble({ quux => 1.21, alarm_low => 42, }); exit( 0 ); sub womble { my ($args_href) = @_; %$args_href = (%WOMBLE_DEFAULTS, %$args_href); warn Dumper( $args_href ) if $DEBUG; ## ... rest of womblification routine }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://624801]
help
Chatterbox?
[Discipulus]: problem scrolling even main page..;=(
[LanX]: holli -> Good Intentions: Wikisyntax for the Monastery
[LanX]: monklinks are automatically converted ...
[LanX]: On another node, I just saw yesterday that the everything engine supports auto-paragraph whithout the need to type <p>
LanX i.e. the newest everything engine

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-11-20 19:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (291 votes). Check out past polls.

    Notices?