Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by toolic (Chancellor)
on Mar 31, 2010 at 17:09 UTC ( #832091=note: print w/ replies, xml ) Need Help??


in reply to Repeating Code - there has GOT to be a better way!

If you are open to a completely different approach, I suggest you store your data as data rather than storing your data as code. For example, if you store your data as something standard, such as XML, then you can read it using a standard parser (such as XML::Twig). Then, you don't have to worry about including 11 hash variables via do.


Comment on Re: Repeating Code - there has GOT to be a better way!
Re^2: Repeating Code - there has GOT to be a better way!
by jedikaiti (Friar) on Mar 31, 2010 at 17:13 UTC

    I wish I could. Alas, at this point, I have no say in how the data is pulled from the DB and stored. Although I might get to re-write that code later, in which case I will keep this in mind! But for now, this is what I am stuck with.

    Kaiti
    Swiss Army Nerd
      You might try something like:
      my %Cmd; { no strict 'vars'; # you have a 'use strict;' line, right? %Cmd = do ("db/$name" . 'Cmd.pm'); }
        %Cmd = do ("db/${name}Cmd.pm");

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

        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://832091]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2014-09-19 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (146 votes), past polls