Re: Passing shell variables to PERL
On Wed, 06 Oct 2004 16:21:31 -0700, John W. Krahn [EMAIL PROTECTED] wrote: [Please do not top-post. TIA] ok Jeff Westman wrote: On Tue, 05 Oct 2004 15:30:59 -0700, John W. Krahn wrote: Jim wrote: Willy Perez wrote: Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON[varname], is there something compatible in perl. You can do the same in perl with the special hash named %ENV. for instance: print $ENV{'SHELL'} or you can use the env module: perldoc -f env perl is case sensitive so that should be Env not env. You have to export the variable if you want perl to recognize it! Example: $ ABC=xyz $ perl -e 'print $ENV{ABC}\n' $ export ABC=xyz $ perl -e 'print $ENV{ABC}\n' xyz $ How is that related to using the Env module? Everything. The original poster asked how to display some varaibles from the shell. You CANNOT display those in perl unless you export them in the shell first. Have you tested it? I did. If you don't export it (as I showed in my example above), nothing is listed. Once exported, the perl command line is then aware of the environement. The point is, unless exported, the ENV module is useless since it is unaware of the parent environment. Disclaimer: this is for *nix systems; in DOS/Win systems, variables are always exported. John -- use Perl; program fulfillment -Jeff -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Passing shell variables to PERL
You have to export the variable if you want perl to recognize it! Example: $ ABC=xyz $ perl -e 'print $ENV{ABC}\n' $ export ABC=xyz $ perl -e 'print $ENV{ABC}\n' xyz $ -Jeff On Tue, 05 Oct 2004 15:30:59 -0700, John W. Krahn [EMAIL PROTECTED] wrote: Jim wrote: Willy Perez wrote: Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON[varname], is there something compatible in perl. You can do the same in perl with the special hash named %ENV. for instance: print $ENV{'SHELL'} or you can use the env module: perldoc -f env perl is case sensitive so that should be Env not env. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Passing shell variables to PERL
[Please do not top-post. TIA] Jeff Westman wrote: On Tue, 05 Oct 2004 15:30:59 -0700, John W. Krahn wrote: Jim wrote: Willy Perez wrote: Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON[varname], is there something compatible in perl. You can do the same in perl with the special hash named %ENV. for instance: print $ENV{'SHELL'} or you can use the env module: perldoc -f env perl is case sensitive so that should be Env not env. You have to export the variable if you want perl to recognize it! Example: $ ABC=xyz $ perl -e 'print $ENV{ABC}\n' $ export ABC=xyz $ perl -e 'print $ENV{ABC}\n' xyz $ How is that related to using the Env module? John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Passing shell variables to PERL
Hi, Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON[varname], is there something compatible in perl. Willy Perez Liz Claiborne IT (201) 295-7011
Re: Passing shell variables to PERL
$ENV{ABC} This works for me, but I don't have a good understanding of what is going on to make it work. HTH, David On Tue, 5 Oct 2004 14:32:27 -0400, Willy Perez [EMAIL PROTECTED] wrote: Hi, Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON[varname], is there something compatible in perl. Willy Perez Liz Claiborne IT (201) 295-7011 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Passing shell variables to PERL
Hi, Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON[varname], is there something compatible in perl. You can do the same in perl with the special hash named %ENV. for instance: print $ENV{'SHELL'} or you can use the env module: perldoc -f env THanks Jim --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.772 / Virus Database: 519 - Release Date: 10/1/2004 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Passing shell variables to PERL
On Tue, 5 Oct 2004 14:32:27 -0400, Willy Perez [EMAIL PROTECTED] wrote: Hi, Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON[varname], is there something compatible in perl. Willy Perez Liz Claiborne IT (201) 295-7011 Hi Willy, Perl will auto-magically take all of your shell environment variables and put them in a hash: %ENV where the keys are the variable names and the values are the values! so, for your example above, # perl -e 'print $ENV{ABC}\n' should work! --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Passing shell variables to PERL
Thanks Errin/Jim/David, Hi Willy, Perl will auto-magically take all of your shell environment variables and put them in a hash: %ENV where the keys are the variable names and the values are the values! so, for your example above, # perl -e 'print $ENV{ABC}\n' should work! --Errin You can do the same in perl with the special hash named %ENV. for instance: print $ENV{'SHELL'} or you can use the env module: perldoc -f env THanks Jim $ENV{ABC} This works for me, but I don't have a good understanding of what is going on to make it work. HTH, David Willy Perez Liz Claiborne IT (201) 295-7011
Re: Passing shell variables to PERL
Jim wrote: Willy Perez wrote: Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON[varname], is there something compatible in perl. You can do the same in perl with the special hash named %ENV. for instance: print $ENV{'SHELL'} or you can use the env module: perldoc -f env perl is case sensitive so that should be Env not env. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response