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

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.

Replies are listed 'Best First'.
Re^4: Using a sting with a variable name
by ikegami (Patriarch) on May 11, 2009 at 15:10 UTC

    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
        You're still only checking whether the variable is defined or not. The data I gave was for after you made the change you said would check for existence.