robh has asked for the wisdom of the Perl Monks concerning the following question:
Hi - I'd like to do this sort of thing but the eval test fails...
#!/usr/bin/perl my %tests=( -s => "size > 0", -T => "type Text", -B => "is Binary", -r => "is readable", -z => "is Zero bytes", ); my $myfile=$0; foreach my $t (keys %tests) { if ( eval("$tests{$t} $myfile") ) { print "Passed [$t] test ($tests{$t})\n"; } else { print "Failed [$t] test ($tests{$t})\n"; } } Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File testing via list of test operators
by chrestomanci (Priest) on Dec 21, 2010 at 14:16 UTC | |
|
Re: File testing via list of test operators
by Perlbotics (Archbishop) on Dec 21, 2010 at 15:06 UTC | |
by robh (Initiate) on Dec 21, 2010 at 15:14 UTC | |
|
Re: File testing via list of test operators
by ELISHEVA (Prior) on Dec 21, 2010 at 14:17 UTC | |
by robh (Initiate) on Dec 21, 2010 at 14:32 UTC | |
by JavaFan (Canon) on Dec 21, 2010 at 14:48 UTC | |
by ELISHEVA (Prior) on Dec 21, 2010 at 15:03 UTC | |
|
Re: File testing via list of test operators
by Anonymous Monk on Dec 21, 2010 at 14:26 UTC | |
by robh (Initiate) on Dec 21, 2010 at 14:38 UTC |