[Chicago-talk] Doing "-X" tests in a loop

Jay Strauss me at heyjay.com
Tue Oct 6 17:48:24 PDT 2009


My intent was to loop through the -x tests and stop on the first failure.
I'll play around with your way too.

Thanks
Jay

On Tue, Oct 6, 2009 at 1:00 PM, Joel Limardo
<joel.limardo at forwardphase.com>wrote:

>  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 <chicago-talk-bounces%2Bjoel.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
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20091006/f0735446/attachment.html>


More information about the Chicago-talk mailing list