[comp.lang.perl] perl -s and -foo=23 or -bar-17

ccount@athena.mit.edu (Craig A Counterman) (01/12/91)

The -s option was recently brought to my attention, so I thought I'd
try using it.  I found that -foo defines $foo with the value 1, as
advertised.  I tried -foo=23, hoping that that'd give it the value 23
instead of 1.  It didn't.  It didn't define $foo either. However, it
did remove '-foo=23' from @ARGV.  I guessed that the variable 'foo=23'
was created and given the value 1.  This is a rather useless
(inaccessable) variable!  (a local perl (relative) expert just tought
me how to access it through *baz, e.g.  *baz = $_main{"foo=23"};print
$baz;
 )


This is logical. But unhelpful, IMO.  More helpful would be to (in
order of increasing utility, in my opinion):
1) create $foo with the value 1
2) ignore -foo=23, leave it in @ARGV
3) create $foo with the value 23

Note that this is a more general problem, -bar-17 creates "bar-17",
another inaccessable variable.  And so on.  -s leads to the creation
of variables with illegal names.  So (3) isn't sufficient by itself to 
deal with all such cases.

So, what if anything can be done?  Note this in the man page under -s
behaviour?

I'm anxious to get a copy of the Book.  I've gotten so much excellent
use from perl in the past year (exactly, now that I think of it), and
still find that I use about 40% of the language.

Thanks,
Craig
becoming Lazy, Impatient, and Proud.

merlyn@iwarp.intel.com (Randal L. Schwartz) (01/12/91)

In article <1991Jan12.073433.19925@athena.mit.edu>, ccount@athena (Craig A Counterman) writes:
|				    I guessed that the variable 'foo=23'
| was created and given the value 1.  This is a rather useless
| (inaccessable) variable!  (a local perl (relative) expert just tought
| me how to access it through *baz, e.g.  *baz = $_main{"foo=23"};print
| $baz;
|  )

Simpler than that:

$NormalMerlyn = 50;
*X = 'Funky Variable 1, Merlyn';  $X = 100;
*X = 'Another // Funky, Merlyn';  $X = 200;
print "Vars are: ", join(":",grep(/Merlyn$/, keys _main)), "\n";
*Z = 'Funky Variable 1, Merlyn';  print "fv1 = $Z\n";
*Z = 'Another // Funky, Merlyn';  print "a/f = $Z\n";

| I'm anxious to get a copy of the Book.  I've gotten so much excellent
| use from perl in the past year (exactly, now that I think of it), and
| still find that I use about 40% of the language.

Thanks for the testimonial even before getting your hands on it.
Larry and I both hope that you find what you are looking for in The Book.

$W="X10"; for (split(/Z*/,"Just another Perl hacker,")) {*X = $W++; $X = $_;}
eval 'print $X'.join(',$X', 10..35)
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/