Professional Web Applications Themes

Passing shell variables to PERL - PERL Beginners

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 <net> wrote:  > > > > 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[/ref] > > perl is case sensitive so that should be Env not env. > > John > ...

  1. #1

    Default 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 <net> wrote: 
    > >
    > > 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[/ref]
    >
    > perl is case sensitive so that should be Env not env.
    >
    > John
    > --
    > use Perl;
    > program
    > fulfillment
    >
    >
    >
    > --
    > To unsubscribe, e-mail: org
    > For additional commands, e-mail: org
    > <http://learn.perl.org/> <http://learn.perl.org/first-response>
    >
    >[/ref]
    Jeff Guest

  2. #2

    Default Re: Passing shell variables to PERL

    [Please do not top-post. TIA]


    Jeff Westman wrote: 
    >>
    >>perl is case sensitive so that should be Env not env.[/ref]
    >
    > 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
    > $[/ref]

    How is that related to using the Env module?


    John
    --
    use Perl;
    program
    fulfillment
    John Guest

  3. #3

    Default Re: Passing shell variables to PERL

    On Wed, 06 Oct 2004 16:21:31 -0700, John W. Krahn <net> wrote: 

    ok
     
    > >
    > > 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
    > > $[/ref]
    >
    > How is that related to using the Env module?[/ref]

    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.
     

    -Jeff
    Jeff Guest

Similar Threads

  1. what is similar to shell `du' in perl
    By Harry in forum PERL Beginners
    Replies: 5
    Last Post: March 4th, 06:57 PM
  2. getting shell outputs as variables
    By Peter in forum PERL Miscellaneous
    Replies: 5
    Last Post: September 30th, 11:32 PM
  3. Passing a directory into $ARGV[0] from a shell script
    By John in forum PERL Miscellaneous
    Replies: 12
    Last Post: September 29th, 04:44 AM
  4. Launching shell scripts using PERL and passing arguments
    By Rajesh Dorairajan in forum PERL Beginners
    Replies: 0
    Last Post: September 4th, 07:11 PM
  5. Which is better? C, Perl or Shell
    By one2001boy@yahoo.com in forum UNIX Programming
    Replies: 0
    Last Post: July 9th, 07:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139