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

Cfg

by unasoft (Initiate)
on May 11, 2005 at 02:37 UTC ( #455838=obfuscated: print w/replies, xml ) Need Help??

my %CFG = (); # See if you can guess what this is for sub getCfg { my $Cfg = shift; my $cfg = shift; my $cFg = $Cfg; my $CFg = $ENV{CFG}; my $cFG = $ENV{ $Cfg }; die "CFG is not defined $!" if not defined( $CFg ); return $cFG if defined( $cFG ); $cFG = $ENV{ "CFG_" . $Cfg }; return $cFG if defined( $cFG ); if( scalar( %CFG ) < 1 ) { tie %CFG, 'Tie::Cfg', READ => $CFg; } foreach $cfg (keys %CFG) { my $cfG = "CFG_" . $cfg . "_" . $CFG{$cfg} . "_" . $cFg; $cFG = $ENV{ $cfG }; return $cFG if defined( $cFG ); foreach my $CfG (keys %CFG) { if( $CfG ne $cfg ) { $cfG = "CFG_" . $cfg . "_" . $CFG{$cfg} . "_" . $CfG . "_" . $CFG{$CfG} . "_" . $cFg; $cFG = $ENV{ $cfG }; return $cFG if defined( $cFG ); } } } $cFG = cfg( $Cfg ); return $cFG; } sub cfg { my $env = shift; my $Env = 0; my $eNv = undef; my $enV = undef; foreach $eNv (keys %ENV) { $Env ++ if( $eNv =~ ".*${env}\$" ); $enV = $eNv if $Env == 1 and not defined( $enV ); die "\n$env is ambiguous $!\n" if $Env > 1; } if( $Env == 1 ) { return $ENV{ $enV }; } return undef; }

Replies are listed 'Best First'.
Re: Cfg
by K_M_McMahon (Hermit) on May 11, 2005 at 05:05 UTC
    I must be missing something. You have 2 subroutines and nothing that calls either one in the main code block? As is, this does nothing.

    On the other hand, I like the obfu concept of using the same variable in different ways by chainging the capitalization.....

    -Kevin
    my $a='62696c6c77667269656e6440676d61696c2e636f6d'; while ($a=~m/(^.{2})/s) {print unpack('A',pack('H*',"$1"));$a=~s/^.{2}//s;}
Re: Cfg
by jdalbec (Deacon) on May 12, 2005 at 01:59 UTC
    If $ENV{CFG} points to a config file of the form
    a=b c=d
    and you call getCfg('e') then it returns (in order of preference):
    $ENV{e} $ENV{CFG_e} $ENV{CFG_a_b_e} $ENV{CFG_a_b_c_d_e} $ENV{CFG_c_d_e} $ENV{CFG_c_d_a_b_e}
    and if none of those are defined it looks for a unique environment variable whose name ends in 'e' (if there's more than one, then it's an error).

    I can't imagine how you could end up with all these oddly named environment variables. Google doesn't help much. Maybe some kind of i18n/l10n settings?

Re: Cfg
by cristian (Hermit) on May 11, 2005 at 13:55 UTC
    ??????????????????????????????????????????? perl -e '$nothing_look = sub { print shift} and $nothing_look->("where is result ???") unless !show_result_not_look_nothing_obfu;' ???????????????????????????????????????????

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2022-05-28 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (98 votes). Check out past polls.

    Notices?