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

Re: Code help

Expand Messages
  • perl_1978
    Hi Sam, thanks for the reply. Yes the $novar =~ m/ s/ is looking for whitespace - I think - after the command env | grep VAR is executed and it returns
    Message 1 of 4 , Mar 21 7:09 AM
    • 0 Attachment
      Hi Sam, thanks for the reply.

      Yes the $novar =~ m/\s/ is looking for whitespace - I think - after
      the command "env | grep VAR" is executed and it returns nothing. I
      know there are better ways to do this but since I'm new at this I
      need to go little by little then try a hash down the road.


      --- In perl-beginner@yahoogroups.com, "buxh42a" <buxh42a@...> wrote:
      >
      > Why don't you use the %ENV hash to access environment variables?
      >
      > $novar = $ENV{VAR};
      >
      > I'm not exactly sure what you are doing in the if condition. Are
      you
      > just trying to see if it is equal to 1 or whitespace? Is the
      > whitespace check there to see if it the value of the environment
      > variable is empty or contains a space?
      >
      > Sam
      >
      > --- In perl-beginner@yahoogroups.com, "Kishore Balla"
      > <kishore.balla@> wrote:
      > >
      > > doing chomp should solve your problem
      > >
      > > $novar = `env | grep VAR`;
      > >
      > > chomp $novar;
      > >
      > > if ( $novar eq "VAR=1" or $novar =~ /\s*/ ) {
      > >
      > > #something
      > >
      > > }
      > > else {
      > >
      > > #something
      > >
      > > }
      > >
      > > HTH
      > >
      > >
      > > On 3/21/07, perl_1978 <perl_1978@> wrote:
      > > >
      > > > I'm trying to do a conditional if statement but the results
      I'm
      > > > getting back are not the desired ones.
      > > >
      > > > $novar = `env | grep VAR`;
      > > >
      > > > if (($novar eq "VAR=1") || ($novar =~ m/\s/)) {
      > > > something
      > > > }else
      > > > {
      > > > something
      > > > }
      > > >
      > > >
      > > > If I run the command "env | grep VAR" at the command line this
      VAR
      > > > is not set it will come back with nothing. For example -
      > > >
      > > > $ env | grep VAR
      > > > $
      > > >
      > > > I thought that was considered whitespace so I did an OR with
      $novar
      > > > =~ m/\s/ but it's not catching it and dropping to my esle line.
      > > > Could someone help me out and let me know what I'm doing wrong?
      > > >
      > > > Thanks
      > > >
      > > >
      > > >
      > >
      > >
      > >
      > > --
      > > ~ Kishore Balla
      > >
      > >
      > > [Non-text portions of this message have been removed]
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.