Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I have written a perl script but I don't know how to get the variables from a txt file. Actually, I can read the txt file in hash and get the variables but I have a small issue. In the txt file I have some paths that include variables.
The txt file with the variables looks like:
V1=/home/user V2=$V1/test V3=$V2/file.txt
I read the lines using:
Read variables open my $vars, '<:utf8', "$Bin/vars.txt" or die $! ; while (<$vars>) { chomp; my ($key, $value) = split(/=/, $_); $vars{$key} = $value; } my $V1 = $vars{'V1'}; my $V2 = $vars{'V2'}; my $V3 = $vars{'V3'}; print "$V1\n"; print "$V2\n"; print "$V3\n"; close ($vars);
The result that I get is:
/home/user /$V1/test /$V2/file.txt
but I want
/home/user /home/user/test /home/user/test/file.txt
I would appreciate any help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Get variables from txt file
by davido (Cardinal) on Aug 28, 2014 at 16:49 UTC | |
|
Re: Get variables from txt file
by toolic (Bishop) on Aug 28, 2014 at 16:28 UTC | |
by Anonymous Monk on Aug 29, 2014 at 08:45 UTC | |
by djerius (Beadle) on Aug 29, 2014 at 20:17 UTC | |
|
Re: Get variables from txt file
by MidLifeXis (Monsignor) on Aug 28, 2014 at 16:32 UTC | |
by jellisii2 (Hermit) on Aug 28, 2014 at 20:24 UTC |