in reply to Re: Creating strings with specified names
in thread Creating strings with specified names

Oops, should have thought of that. Thanks!

Is what I suggested possible?

  • Comment on Re^2: Creating strings with specified names

Replies are listed 'Best First'.
Re^3: Creating strings with specified names
by kyle (Abbot) on Aug 07, 2008 at 21:14 UTC

    Writing Perl that creates variables with a name specified at run time is pretty easy, but it's generally not a good idea.

    $name = 'foo'; $$name = 'bar'; print "foo = $foo\n"; __END__ foo = bar

    Note that doesn't work if you use strict (which is always a good idea). In that case, you wind up with something like this:

    my $name = 'foo'; { no strict 'refs'; $$name = 'bar'; } print "foo = $main::foo\n";

    See how I still had to use the explicit package name to refer to the variable for printing.

    You can do a lot with eval too.