I want to read configuration from a file named '1.spec',and then try to print something. Here's my code:
#!/usr/bin/perl
# test.pl
use strict;
use warnings;
my %cfg;
unless(do '1.spec'){
warn "can not parse :$@";
warn "can not do: $!";
warn "could not run";
}
my @keys = keys %cfg;
my @values = values %cfg;
while(@keys){
print pop(@keys),'=',pop(@values),"\n";
}
Below is '1.spec', only two lines.
$cfg{name} = 'philip';
$cfg{age} = '21';
I can not get any print when run 'test.pl'. I read perldoc who says 'Do: Uses the value of EXPR as a filename and executes the contents of the file as a Perl script'. If I write 'print "hello"' in 1.spec, it can print as expected, but why it can not set the hash values?