[Chicago-talk] Doing "-X" tests in a loop
Joel Limardo
joel.limardo at forwardphase.com
Tue Oct 6 11:00:49 PDT 2009
Do you really even need to know whether there was actually an 'error'?
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my @files = qw|README.TXT note2gap.txt nonexistent.txt|;
my %euphoria = map{$_=>[(-e $_), (-f $_), (-s $_)]} @files;
print Dumper %euphoria;
print q|nonexistent.txt doesn't exist because it doesn't satisfy -f, |.
((!($euphoria{'nonexistent.txt'}[1]))?'true':'false');
print qq|\nREADME.TXT does exist because it does satisfy -f, |.
((($euphoria{'README.TXT'}[1]))?'true':'false');
1;
=== output of Dumper, etc. ===
$VAR1 = 'nonexistent.txt';
$VAR2 = [
undef,
undef,
undef
];
$VAR3 = 'README.TXT';
$VAR4 = [
1,
1,
'750'
];
$VAR5 = 'note2gap.txt';
$VAR6 = [
1,
1,
'6299'
];
You can always test for undef (print statement output):
nonexistent.txt doesn't exist because it doesn't satisfy -f, true
README.TXT does exist because it does satisfy -f, true
From: chicago-talk-bounces+joel.limardo=forwardphase.com at pm.org
[mailto:chicago-talk-bounces+joel.limardo=forwardphase.com at pm.org] On Behalf
Of Jay Strauss
Sent: Tuesday, October 06, 2009 11:18 AM
To: Chicago.pm chatter
Subject: [Chicago-talk] Doing "-X" tests in a loop
Hi,
How would I do "-X" test in a loop? I've been trying variations on eval,
but can't get it to work:
foreach (qw[-e -r -s]) {
eval "$error = $_ unless $_ $xopt{data_file}";
print "$_: $error\n";
}
but $error doesn't change if any of the tests fail
Obviously my "eval" is wrong but I've tried it a bunch of different ways and
cant get it work.
Could someone point me in the right direction?
Thanks
Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20091006/a66e7046/attachment.html>
More information about the Chicago-talk
mailing list