http://www.perlmonks.org?node_id=1016319


in reply to how to read perl variable from a line read from a file

Hello Bharath666, and welcome to the Monastery!

As parv says, one approach is to use eval:

#! perl use Modern::Perl; my ($VAR1, $VAR2); my $INST = 'C'; while (<DATA>) { chomp; if (/ ^ ([^=]*?) = (.*) $ /x) { my ($lhs, $rhs) = ($1, $2); eval '$' . $lhs . ' = "' . $rhs . '";'; warn $@ if $@; } } say for $VAR1, $VAR2; __DATA__ VAR1=$INST/dirivebase/program VAR2=$INST/origbase/data

Output:

22:54 >perl 513_SoPW.pl C/dirivebase/program C/origbase/data 23:07 >

The problem with this ‘solution’ is that the code is tightly-bound to the exact form of the input data, making it brittle and inflexible. I have to say, you will be better-off re-examining the broader problems your code is addressing, and then re-thinking your general strategy.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,