in reply to Re: Using a sting with a variable name
in thread Using a sting with a variable name

It also assumes $one$var is defined if it exists. I don't know if that's ok or not.

Replies are listed 'Best First'.
Re^3: Using a sting with a variable name
by JavaFan (Canon) on May 11, 2009 at 15:04 UTC
    I was assuming from the phrasing of the question and the example that it can be given that $one is defined. Otherwise, it's a trivial test to add.

      it's a trivial test to add.

      One catch, using the following data, it'll say $var exists. But that's probably good enough.
      @var = qw( a b c ); $var2 = undef; $one = '$var'; # Exists! $two = '$var2'; # Exists
        Really? That's not what I get (nor expect):
        use 5.010; @var = qw (a b c); $var2 = undef; $one = '$var'; $two = '$var2'; if (defined ${"${\substr $one, 1}"}) { say '$var exists'; } else { say '$var does not exist'; } __END__ $var does not exist