Loading ...
Sorry, an error occurred while loading the content.
 

RE: [PBML] Expanding Env variables.

Expand Messages
  • RAJESH PETHE
    If the user is giving inputs to the shell then you don t need to do anything. If it s giving inputs to perl then you need to access the %ENV hash that stores
    Message 1 of 7 , Mar 5, 2006
      If the user is giving inputs to the shell then you don't need to do
      anything. If it's giving inputs to perl then you need to access the %ENV
      hash that stores all the env. Variables. For example use $ENV{HOME} to
      get the value of $HOME env. Variable.

      Regards
      Rajesh


      -----Original Message-----
      From: perl-beginner@yahoogroups.com
      [mailto:perl-beginner@yahoogroups.com] On Behalf Of jabir ahmed
      Sent: Monday, March 06, 2006 12:07 PM
      To: perl-beginner@yahoogroups.com
      Subject: [PBML] Expanding Env variables.

      Hello

      Can anyone help me with this

      The user input could be

      /home/user/file.txt
      $HOME/file.txt
      ~/file.txt

      $SOMELOCATION/a.txt
      $APPPATH/a.conf.


      how could i expand the path and get the real path using perl.

      thanks in advance

      jab


      [Non-text portions of this message have been removed]



      Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html
      Yahoo! Groups Links










      ============================================================================================================================

      Tech Mahindra, formerly Mahindra-British Telecom.


      Disclaimer:


      The contents of this E-mail (including the contents of the enclosure(s) or attachment(s) if any) are privileged and confidential material of Tech Mahindra and should not be disclosed to, used by or copied in any manner by anyone other than the intended addressee(s). In case you are not the desired addressee, you should delete this message and/or re-direct it to the sender. The views expressed in this E-mail message (including the enclosure(s) or attachment(s) if any) are those of the individual sender, except where the sender expressly, and with authority, states them to be the views of Tech Mahindra.


      This e-mail message including attachment/(s), if any, is believed to be free of any virus. However, it is the responsibility of the recipient to ensure that it is virus free and Tech Mahindra is not responsible for any loss or damage arising in any way from its use.

      ============================================================================================================================
    • jabir ahmed
      the problem is i am not sure which env variable he would use! jab ... -- To try is to risk failure, but risk must be taken, Because the greatest Hazard in life
      Message 2 of 7 , Mar 5, 2006
        the problem is i am not sure which env variable he would use!

        jab

        On 3/6/06, RAJESH PETHE <rpethe@...> wrote:
        >
        >
        > If the user is giving inputs to the shell then you don't need to do
        > anything. If it's giving inputs to perl then you need to access the %ENV
        > hash that stores all the env. Variables. For example use $ENV{HOME} to
        > get the value of $HOME env. Variable.
        >
        > Regards
        > Rajesh
        >
        >
        >
        > -----Original Message-----
        > From: perl-beginner@yahoogroups.com
        > [mailto:perl-beginner@yahoogroups.com] On Behalf Of jabir ahmed
        > Sent: Monday, March 06, 2006 12:07 PM
        > To: perl-beginner@yahoogroups.com
        > Subject: [PBML] Expanding Env variables.
        >
        > Hello
        >
        > Can anyone help me with this
        >
        > The user input could be
        >
        > /home/user/file.txt
        > $HOME/file.txt
        > ~/file.txt
        >
        > $SOMELOCATION/a.txt
        > $APPPATH/a.conf.
        >
        >
        > how could i expand the path and get the real path using perl.
        >
        > thanks in advance
        >
        > jab
        >
        >
        > [Non-text portions of this message have been removed]
        >
        >
        >
        > Unsubscribing info is here:
        > http://help.yahoo.com/help/us/groups/groups-32.html
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        > ============================================================================================================================
        >
        > Tech Mahindra, formerly Mahindra-British Telecom.
        >
        >
        > Disclaimer:
        >
        >
        > The contents of this E-mail (including the contents of the enclosure(s) or
        > attachment(s) if any) are privileged and confidential material of Tech
        > Mahindra and should not be disclosed to, used by or copied in any manner by
        > anyone other than the intended addressee(s). In case you are not the desired
        > addressee, you should delete this message and/or re-direct it to the sender.
        > The views expressed in this E-mail message (including the enclosure(s) or
        > attachment(s) if any) are those of the individual sender, except where the
        > sender expressly, and with authority, states them to be the views of Tech
        > Mahindra.
        >
        >
        > This e-mail message including attachment/(s), if any, is believed to be
        > free of any virus. However, it is the responsibility of the recipient to
        > ensure that it is virus free and Tech Mahindra is not responsible for any
        > loss or damage arising in any way from its use.
        >
        >
        > ============================================================================================================================
        >
        >
        > Unsubscribing info is here:
        > http://help.yahoo.com/help/us/groups/groups-32.html
        >
        >
        >
        > SPONSORED LINKS
        > Basic programming language<http://groups.yahoo.com/gads?t=ms&k=Basic+programming+language&w1=Basic+programming+language&w2=C+programming+language&w3=Computer+programming+languages&w4=The+c+programming+language&w5=C+++programming+language&w6=List+of+programming+languages&c=6&s=193&.sig=aLlETYEcZKW67uFZnuZPPw> C
        > programming language<http://groups.yahoo.com/gads?t=ms&k=C+programming+language&w1=Basic+programming+language&w2=C+programming+language&w3=Computer+programming+languages&w4=The+c+programming+language&w5=C+++programming+language&w6=List+of+programming+languages&c=6&s=193&.sig=n4wEVXDpIBKogo8e_G77cw> Computer
        > programming languages<http://groups.yahoo.com/gads?t=ms&k=Computer+programming+languages&w1=Basic+programming+language&w2=C+programming+language&w3=Computer+programming+languages&w4=The+c+programming+language&w5=C+++programming+language&w6=List+of+programming+languages&c=6&s=193&.sig=KFl1CeQi7jrKmsK4WD6ygQ> The
        > c programming language<http://groups.yahoo.com/gads?t=ms&k=The+c+programming+language&w1=Basic+programming+language&w2=C+programming+language&w3=Computer+programming+languages&w4=The+c+programming+language&w5=C+++programming+language&w6=List+of+programming+languages&c=6&s=193&.sig=lU9w7-4UlGPB4LjDy84c2Q> C++
        > programming language<http://groups.yahoo.com/gads?t=ms&k=C+++programming+language&w1=Basic+programming+language&w2=C+programming+language&w3=Computer+programming+languages&w4=The+c+programming+language&w5=C+++programming+language&w6=List+of+programming+languages&c=6&s=193&.sig=dtKotXT1Ne2N9AO_aEbPFQ> List
        > of programming languages<http://groups.yahoo.com/gads?t=ms&k=List+of+programming+languages&w1=Basic+programming+language&w2=C+programming+language&w3=Computer+programming+languages&w4=The+c+programming+language&w5=C+++programming+language&w6=List+of+programming+languages&c=6&s=193&.sig=0shmxLBHwrZWcSjC3QvZAA>
        > ------------------------------
        > YAHOO! GROUPS LINKS
        >
        >
        > - Visit your group "perl-beginner<http://groups.yahoo.com/group/perl-beginner>"
        > on the web.
        >
        > - To unsubscribe from this group, send an email to:
        > perl-beginner-unsubscribe@yahoogroups.com<perl-beginner-unsubscribe@yahoogroups.com?subject=Unsubscribe>
        >
        > - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
        > Service <http://docs.yahoo.com/info/terms/>.
        >
        >
        > ------------------------------
        >



        --
        To try is to risk failure, but risk must be taken,
        Because the greatest Hazard in life is to risk
        nothing.
        Phone: +91 98861 36420
        email: jabirahmed@... , jabirahmed@...
        Instant Messenger:
        yahoo jabirahmed@...,msn : jabir07@...,ICQ: 56327312, Skype:
        jabirahmed


        [Non-text portions of this message have been removed]
      • Damien Carbery
        ... The user is not using the shell, but providing the above examples while the perl script is running. I spoke with jab via IM and the solution was simply to
        Message 3 of 7 , Mar 6, 2006
          --- In perl-beginner@yahoogroups.com, "jabir ahmed" <jabirahmed@...>
          wrote:
          >
          > the problem is i am not sure which env variable he would use!
          >
          > jab
          >
          > On 3/6/06, RAJESH PETHE <rpethe@...> wrote:
          > > If the user is giving inputs to the shell then you don't need to
          > > do anything. If it's giving inputs to perl then you need to
          > > access the %ENV hash that stores all the env. Variables. For
          > > example use $ENV{HOME} to get the value of $HOME env. Variable.
          > >
          > > Regards
          > > Rajesh
          > > -----Original Message-----
          > > Hello
          > >
          > > Can anyone help me with this
          > >
          > > The user input could be
          > >
          > > /home/user/file.txt
          > > $HOME/file.txt
          > > ~/file.txt
          > >
          > > $SOMELOCATION/a.txt
          > > $APPPATH/a.conf.
          > >
          > >
          > > how could i expand the path and get the real path using perl.
          > >

          The user is not using the shell, but providing the above examples
          while the perl script is running.

          I spoke with jab via IM and the solution was simply to use 'echo' and
          backticks to get the shell to do the work:

          my $entered_string = '$SOMELOCATION/a.txt';
          my $expanded_string = `echo $entered_string`;
        • merlyn@stonehenge.com
          ... Damien The user is not using the shell, but providing the above examples Damien while the perl script is running. Damien I spoke with jab via IM and the
          Message 4 of 7 , Mar 6, 2006
            >>>>> "Damien" == Damien Carbery <daymobrew@...> writes:

            Damien> The user is not using the shell, but providing the above examples
            Damien> while the perl script is running.

            Damien> I spoke with jab via IM and the solution was simply to use 'echo' and
            Damien> backticks to get the shell to do the work:

            Damien> my $entered_string = '$SOMELOCATION/a.txt';
            Damien> my $expanded_string = `echo $entered_string`;

            A perfectly fine solution if you don't care about speed, security, destroying
            whitespace, or otherwise mangling shell-related metacharacters.

            In other words, the wrong solution for nearly everyone.

            The right solution is in the FAQ, which nobody seems to search before posting
            to this mailing list.

            --
            Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
            <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
            Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
            See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
          • Victor Bouffier
            ... What Randal suggests is in perldoc -q ~ under the linux/unix command line. Windows users can search through the Activeperl documentation for the same
            Message 5 of 7 , Mar 6, 2006
              On Mon, 2006-03-06 at 12:19 -0800, merlyn@... wrote:
              > >>>>> "Damien" == Damien Carbery <daymobrew@...> writes:
              >
              > Damien> The user is not using the shell, but providing the above examples
              > Damien> while the perl script is running.
              >
              > Damien> I spoke with jab via IM and the solution was simply to use 'echo' and
              > Damien> backticks to get the shell to do the work:
              >
              > Damien> my $entered_string = '$SOMELOCATION/a.txt';
              > Damien> my $expanded_string = `echo $entered_string`;
              >
              > A perfectly fine solution if you don't care about speed, security, destroying
              > whitespace, or otherwise mangling shell-related metacharacters.
              >
              > In other words, the wrong solution for nearly everyone.
              >
              > The right solution is in the FAQ, which nobody seems to search before posting
              > to this mailing list.
              >

              What Randal suggests is in
              perldoc -q '~'

              under the linux/unix command line. Windows users can search through the
              Activeperl documentation for the same info.
            • Damien Carbery
              ... examples ... echo and ... destroying ... before posting ... And perlfaq4
              Message 6 of 7 , Mar 6, 2006
                --- In perl-beginner@yahoogroups.com, Victor Bouffier <victor@...> wrote:
                >
                > On Mon, 2006-03-06 at 12:19 -0800, merlyn@... wrote:
                > > >>>>> "Damien" == Damien Carbery <daymobrew@...> writes:
                > >
                > > Damien> The user is not using the shell, but providing the above
                examples
                > > Damien> while the perl script is running.
                > >
                > > Damien> I spoke with jab via IM and the solution was simply to use
                'echo' and
                > > Damien> backticks to get the shell to do the work:
                > >
                > > Damien> my $entered_string = '$SOMELOCATION/a.txt';
                > > Damien> my $expanded_string = `echo $entered_string`;
                > >
                > > A perfectly fine solution if you don't care about speed, security,
                destroying
                > > whitespace, or otherwise mangling shell-related metacharacters.
                > >
                > > In other words, the wrong solution for nearly everyone.
                > >
                > > The right solution is in the FAQ, which nobody seems to search
                before posting
                > > to this mailing list.
                > >
                >
                > What Randal suggests is in
                > perldoc -q '~'
                >
                > under the linux/unix command line. Windows users can search through the
                > Activeperl documentation for the same info.
                >

                And perlfaq4
                http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/lib/Pod/perlfaq4.html#how_can_i_expand_variables_in_text_strings
                How can I expand variables in text strings?

                Let's assume that you have a string that contains placeholder variables.

                $text = 'this has a $foo in it and a $bar';

                You can use a substitution with a double evaluation. The first /e
                turns $1 into $foo, and the second /e turns $foo into its value. You
                may want to wrap this in an eval: if you try to get the value of an
                undeclared variable while running under use strict, you get a fatal error.

                eval { $text =~ s/(\$\w+)/$1/eeg };
                die if $@;

                It's probably better in the general case to treat those variables as
                entries in some special hash. For example:

                %user_defs = (
                foo => 23,
                bar => 19,
                );
                $text =~ s/\$(\w+)/$user_defs{$1}/g;
              • merlyn@stonehenge.com
                ... Damien And perlfaq4 Yeah, that s actually the one I was thinking of. Damien
                Message 7 of 7 , Mar 6, 2006
                  >>>>> "Damien" == Damien Carbery <daymobrew@...> writes:

                  Damien> And perlfaq4

                  Yeah, that's actually the one I was thinking of.

                  Damien> http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/lib/Pod/perlfaq4.html#how_can_i_expand_variables_in_text_strings

                  Huh? Why go all the way to CANADA to get a file that is ON YOUR HARD DRIVE.

                  People, repeat after me: "perldoc perlfaq4". Simple, fast, safe.

                  --
                  Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                  <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                  Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
                  See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
                Your message has been successfully submitted and would be delivered to recipients shortly.