Can one set perlvars on command line?

J

J Krugman

Is there any trick to set a Perl variable (or any global variable,
for that matter) on the command line, as in, for example:

% perl {{{set $| to 1}}} somescript.pl --opt --flag arg

so that myscript.pl started out with $| having value 1?

TIA,

jill
 
G

gnari

J Krugman said:
Is there any trick to set a Perl variable (or any global variable,
for that matter) on the command line, as in, for example:

% perl {{{set $| to 1}}} somescript.pl --opt --flag arg

so that myscript.pl started out with $| having value 1?

is it cheating to use
perl -Mcheat somescript.pl --opt --flag arg
where you have put cheat.pm somewhere in @INC ?

use of -Mmodule=arg,arg might help do this in a
general way:
perl -Msetvar=OUTPUT_AUTOFLUSH,1 somescript.pl


what about (untested):
perl -e'$|=1;require "somescript.pl"' --opt --flag arg


gnari
 
B

Ben Morrow

Quoth J Krugman said:
Is there any trick to set a Perl variable (or any global variable,
for that matter) on the command line, as in, for example:

% perl {{{set $| to 1}}} somescript.pl --opt --flag arg

so that myscript.pl started out with $| having value 1?

perl -e'$| = 1; do shift' somescript.pl --opt --flag arg
perl -Mvars::i='$|,1' somescript.pl --opt --flag arg

(These both assume sh-like shells: with other shells you may have a much harder
time.)

Get vars::i from CPAN.

Ben
 
M

Malcolm Dew-Jones

J Krugman ([email protected]) wrote:


: Is there any trick to set a Perl variable (or any global variable,
: for that matter) on the command line, as in, for example:

: % perl {{{set $| to 1}}} somescript.pl --opt --flag arg

: so that myscript.pl started out with $| having value 1?


put your defaults in a .pm file (e.g. mystuff.pm) in the @INC path, and
then try

perl -Mmystuff

(I've never -M used for this, but can't see why it wouldn't work).

Certain command line switches (e.g. -0 ) work for a few variables.
 
J

Jeff Schwab

J said:
Is there any trick to set a Perl variable (or any global variable,
for that matter) on the command line, as in, for example:

% perl {{{set $| to 1}}} somescript.pl --opt --flag arg

so that myscript.pl started out with $| having value 1?

It's *definitely* cheating, but you could use the -i flag to set $^I...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top