in reply to Changing variable names in a loop
I prefer to use hash table keys when the idea of dynamic variable names comes up.
The output is:
#! /usr/bin/perl -w use strict; use Data::Dumper; my @fields = qw/ inc_albums inc_genres /; my %record; my $content = "inc_albums=asdf\n"; foreach my $field (@fields) { ($record{$field}) = $content=~/${field}=(.*?)\n/; } print Dumper(\%record);
The output is:
$VAR1 = { 'inc_genres' => undef, 'inc_albums' => 'asdf' };
In Section
Seekers of Perl Wisdom