http://qs321.pair.com?node_id=776340


in reply to Scalar variable value is name of a scalar variable

I tried using symbolic references and it seems to work.

Had to alter the logic a bit too.Is this implementation correct? I have read a few articles which advocate against using symbolic references.

my $lev = "INFO"; $logger->level($$lev); # DEBUG,INFO,WARN,ERROR,FATAL

Replies are listed 'Best First'.
Re^2: Scalar variable value is name of a scalar variable
by GrandFather (Saint) on Jul 01, 2009 at 08:48 UTC

    No need to use symbolic references when you can use real references instead, and with less typing:

    if ($lev =~ /.*DEBUG.*/i){ $loglev = \$DEBUG; }elsif($lev =~ /.*INFO.*/i){ $loglev = \$INFO; }elsif($lev =~ /.*WARN.*/i){ $loglev = \$WARN; }elsif($lev =~ /.*ERROR.*/i){ $loglev = \$ERROR; }elsif($lev =~ /.*FATAL.*/i){ $loglev = \$FATAL; }else{ die "\nPlease provide the correct log level\n"; } my $logger = get_logger(); $logger->level($$loglev); # $DEBUG,$INFO,$WARN,$ERROR,$FATAL

    True laziness is hard work