Just use a hash:
#!/usr/bin/perl -w
use strict;
open(my $fh, "<", "/var/ldt/ldt.conf") || die "Can't open file: $!\n";
my %vars;
while(<$fh>){
## remove trailing newlines
chomp;
## Split the line on =
my @F=split(/=/,$_,2);
## remove quotes
$F[1]=~s/^['"]//;
$F[1]=~s/['"]$//;
## Save the values in the hash
$vars{$F[0]}=$F[1];
}
print "LDT_HWADDR:$vars{LDT_HWADDR}\n";
print "LDT_OS_ID:$vars{LDT_OS_ID}\n";
print "RUN_UPDATES:$vars{RUN_UPDATES}\n";
Output:
LDT_HWADDR:00:00:00:00:00:00
LDT_OS_ID:24
RUN_UPDATES:true
Alternatively, use $$var. Note, however, that such things are very rarely, if ever, a good idea and very often lead to complications (for example, see the link provided by @Sobrique in the comments). The approach above is much safer.
#!/usr/bin/perl
open(my $fh, "<", "/var/ldt/ldt.conf") || die "Can't open file: $!\n";
while(<$fh>){
## remove trailing newlines
chomp;
## Split the line on =
my @F=split(/=/,$_,2);
## remove quotes
$F[1]=~s/^['"]//;
$F[1]=~s/['"]$//;
## Set the variables
${$F[0]}=$F[1];
}
print "$LDT_HWADDR\n";
print "$LDT_OS_ID\n";
print "$RUN_UPDATES\n";