Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Repeating Code - there has GOT to be a better way!

by cleverett (Friar)
on Mar 31, 2010 at 17:59 UTC ( #832111=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Repeating Code - there has GOT to be a better way!
in thread Repeating Code - there has GOT to be a better way!

You might try something like:

my %Cmd; { no strict 'vars'; # you have a 'use strict;' line, right? %Cmd = do ("db/$name" . 'Cmd.pm'); }


Comment on Re^3: Repeating Code - there has GOT to be a better way!
Download Code
Re^4: Repeating Code - there has GOT to be a better way!
by Jenda (Abbot) on Apr 01, 2010 at 06:36 UTC
    %Cmd = do ("db/${name}Cmd.pm");

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Re^4: Repeating Code - there has GOT to be a better way!
by almut (Canon) on Apr 01, 2010 at 07:01 UTC

    Or even

    #!/usr/bin/perl my %cmds = map { (/(.*)Cmd/) => { do $_ } } <*Cmd.pm>; use Data::Dumper; print Dumper \%cmds;
    $ cat *Cmd.pm ; ./832111.pl %barCmd = ( # barCmd.pm BAR => 99, # ... ); %fooCmd = ( # fooCmd.pm FOO => 42, # ... ); $VAR1 = { 'bar' => { 'BAR' => 99 }, 'foo' => { 'FOO' => 42 } };

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2014-12-18 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (61 votes), past polls