Thanks Dan,<br><br> I want to do some file tests, so I can give back meaningful errors to the user and avoid doing work on bad files.<br><br>I'll look up stat and see how to use it.<br><br>Thanks<br>Jay<br><br><div class="gmail_quote">
On Tue, Oct 6, 2009 at 12:21 PM, Dan Rench <span dir="ltr"><<a href="mailto:drench%2Bchipm@gmail.com">drench+chipm@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Tue, Oct 6, 2009 at 11:17 AM, Jay Strauss <<a href="mailto:me@heyjay.com">me@heyjay.com</a>> wrote:<br>
<br>
> How would I do "-X" test in a loop? I've been trying variations on eval,<br>
> but can't get it to work:<br>
><br>
> foreach (qw[-e -r -s]) {<br>
><br>
> eval "$error = $_ unless $_ $xopt{data_file}";<br>
> print "$_: $error\n";<br>
> }<br>
<br>
</div>Back up a bit. When find yourself using string eval(), stop, because<br>
string eval() is almost never a good idea.<br>
<br>
But I'll bite anyway: if you change that "eval" into a "print" you<br>
will see that what's getting eval'ed is something like: " = -e unless<br>
-e somefilename": $error is getting interpolated into a blank string,<br>
where you want it literal, and your first $_ is unquoted. I think you<br>
want $error to contain "-e" or "-r" or "-s", right? Same goes for the<br>
bareword that $xopt{data_file} becomes: you'll need to put quotes<br>
around it. But what kind of quotes? You could pick single quotes, but<br>
you better make sure the name of $xopt{data_file} doesn't contain any<br>
characters that mess up your quoting!<br>
<br>
I'll be condemned to Perl Hell (or at least Heck) for this, but I<br>
think this will do what you're asking:<br>
<br>
eval qq{\$error = '$_' unless $_ '\Q$xopt{data_file}\E'};<br>
<br>
Please don't actually use this code! Get rid of eval(), take the<br>
result of stat($xopt{data_file}) and go from there.<br>
_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
</blockquote></div><br>