in reply to Using a sting with a variable name

no strict 'refs'; if (defined ${"${\substr $one, 1}"}) { ... }
That's assuming $one contains the name of a package variable.

Replies are listed 'Best First'.
Re^2: Using a sting with a variable name
by almut (Canon) on May 11, 2009 at 15:09 UTC
    if (defined ${"${\substr $one, 1}"}) {

    Instead of ${"${\substr $one, 1}"} you could also just write ${substr $one, 1}.

Re^2: Using a sting with a variable name
by ikegami (Patriarch) on May 11, 2009 at 15:02 UTC
    It also assumes $one$var is defined if it exists. I don't know if that's ok or not.
      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