in reply to Recover a path from a config file
Using do or eval to parse files like your work.conf is potentially very dangerous. Arbitrary Perl code can be inserted in files like that.
I have used Data::Undump with some success to more safely read data from files like your work.conf
However, since you are interested in only the values for $folder and license, you could extract those with regular expressions
(Untested)
use strict; use warnings; my $dir; my $lic; my $cfgf = 'work.conf'; open my $cfgh, '<', $cfgf or die "Can't open $cfgf: $!\n"; while (<$cfgh>) { if (/\$folder\s+=\s+'([^']+)'/) $dir = $1; next; } if (/license\s+=>\s+'([^']+)'/) { $lic = $dir . $1; last; } } print "Folder: $dir\nLicense: $lic\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Recover a path from a config file
by Chaoui05 (Scribe) on Jun 07, 2016 at 08:24 UTC | |
by Anonymous Monk on Jun 07, 2016 at 08:32 UTC | |
by Chaoui05 (Scribe) on Jun 07, 2016 at 16:57 UTC |