Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Playing with module::variables and -s

by pernod (Chaplain)
on Oct 18, 2004 at 18:20 UTC ( [id://400261]=note: print w/replies, xml ) Need Help??


in reply to Is using '-s' really bad and why?

For what it's worth, here's my fiddling with -s and modules. Consider the following toy module (With horrible style. Don't write real code like this, kids ;):

1: package MyMod; 2: #$value = "Ding!"; 3: sub spit { 4: return $value; 5: } 6: 1;
And the following little script:
1: use MyMod; 2: print MyMod::spit(), "\n";

With the following command line, this will print "Hey Monks!"

c:/monks/temp $perl -s ss.pl -MyMod::value="Hey Monks!" Hey Monks!

If, on the other hand, I uncomment line 2 in MyMod.pm, setting the default value of the variable to "Ding", the same command line will return the value set in the module.

c:/monks/temp $perl -s ss.pl -MyMod::value="Hey Monks!" Ding!

To my eyes, this allows -s to set uninitialised module variables from the command line, but it will not override variables already defined. I don't really see how this can come in handy though. Perhaps some funky obfuscation?

Oh well. Curiosity strikes again :)

pernod
--
Mischief. Mayhem. Soap.

Replies are listed 'Best First'.
Re: Playing with module::variables and -s
by ysth (Canon) on Oct 18, 2004 at 18:28 UTC
    To my relief, perl -s -e'print $^O' -- -^O=foo doesn't print foo. But perl -we'print `perl -s -eprint" "\$^O -- -\x0f=foo`' does.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-16 23:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found