PhillipHuang has asked for the wisdom of the Perl Monks concerning the following question:
Below is '1.spec', only two lines.#!/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"; }
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?$cfg{name} = 'philip'; $cfg{age} = '21';
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: 'do' read file
by wfsp (Abbot) on Dec 14, 2011 at 08:47 UTC | |
Re: 'do' read file
by cdarke (Prior) on Dec 14, 2011 at 08:51 UTC | |
by PhillipHuang (Beadle) on Dec 14, 2011 at 09:13 UTC | |
Re: 'do' read file
by jdporter (Paladin) on Dec 14, 2011 at 15:50 UTC | |
Re: 'do' read file
by scorpio17 (Canon) on Dec 14, 2011 at 15:10 UTC | |
by jdporter (Paladin) on Dec 14, 2011 at 16:01 UTC | |
Re: 'do' read file
by TJPride (Pilgrim) on Dec 14, 2011 at 09:04 UTC |