in reply to Exporting variables from perl script to shell

I'm assuming you're calling the shell script using the system() function. What's wrong with:
system( "FOO='bar' ", $command, );

Update: system( "FOO='bar' $command" ); should work better, according to Aristotle. I was just trying to point out you can set shell parameters on a per-command basis.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^2: Exporting variables from perl script to shell
by Stevie-O (Friar) on Dec 21, 2004 at 16:49 UTC
    I would code it like this:
    do { local $ENV{FOO} = 'bar'; system($command); };
    This gives you the temporary-env-value semantics of "FOO='bar' $command", yet doesn't assume that the user's shell has said semantics (Win32's cmd.exe certainly doesn't, for example).
    --Stevie-O
    $"=$,,$_=q>|\p4<6 8p<M/_|<('=> .q>.<4-KI<l|2$<6%s!<qn#F<>;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/</;$_=$,,y[A-Z a-z] {}cd;print lc
Re^2: Exporting variables from perl script to shell
by Aristotle (Chancellor) on Dec 21, 2004 at 16:40 UTC

    How about “that doesn't work”? :-) You need something like system( "FOO='bar' $command" );, ie you must go via shell — the list form of system won't.

    Makeshifts last the longest.

Re^2: Exporting variables from perl script to shell
by edan (Curate) on Dec 21, 2004 at 16:42 UTC

    That won't work. "FOO='bar'" will be interpreted as a command that system() tries to exec, and results in system: No such file or directory

    --
    edan