Perl Newbie here.
I want to open a file that I have setup as a configuration file. After opening the file I was to assign parts of the words to variables.
for example (configuration file config.conf):
I want to open the above file, config.conf, and read it while assiging variables to the items after the equals sign.
[CODE=perl]
my($cake,$icing );
$cake = undef;
$icing = undef;
open(handle,"co nfig.conf") || die "no file found\n";
foreach $line (<handle>) {
my( $cake) = $line =~ /^cake=(.*)/;
my($icing) = $line =~ /^icing=(.*)/;
}
print $cake; #nothing prints
print $icing; #nothing prints
close(handle);
#next i would like to split the $cake items by using the split command
#then I would split the $icing items
#tricky part I think is trying to create a directory structure where each cake has
# below it a sub directory for each icing
#I plan on populating taste results under the sub directory
#ex:
[/CODE]
$cake and $icing do not print.
If someone could help with my logic I would appreciate the hlep.
I want to open a file that I have setup as a configuration file. After opening the file I was to assign parts of the words to variables.
for example (configuration file config.conf):
Code:
cake=yellow,chocolate,red,white icing=butter,lemon,chocolate
[CODE=perl]
my($cake,$icing );
$cake = undef;
$icing = undef;
open(handle,"co nfig.conf") || die "no file found\n";
foreach $line (<handle>) {
my( $cake) = $line =~ /^cake=(.*)/;
my($icing) = $line =~ /^icing=(.*)/;
}
print $cake; #nothing prints
print $icing; #nothing prints
close(handle);
#next i would like to split the $cake items by using the split command
#then I would split the $icing items
#tricky part I think is trying to create a directory structure where each cake has
# below it a sub directory for each icing
#I plan on populating taste results under the sub directory
#ex:
[/CODE]
- /yellow
- /butter
- /lemon
- /chocolate
- /butter
- /white
- /butter
- /lemon
- /chocolate
- /butter
$cake and $icing do not print.
If someone could help with my logic I would appreciate the hlep.
Comment