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&#39;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">&lt;<a href="mailto:drench%2Bchipm@gmail.com">drench+chipm@gmail.com</a>&gt;</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 &lt;<a href="mailto:me@heyjay.com">me@heyjay.com</a>&gt; wrote:<br>
<br>
&gt; How would I do &quot;-X&quot; test in a loop?  I&#39;ve been trying variations on eval,<br>
&gt; but can&#39;t get it to work:<br>
&gt;<br>
&gt;         foreach (qw[-e -r -s]) {<br>
&gt;<br>
&gt;             eval &quot;$error = $_ unless $_ $xopt{data_file}&quot;;<br>
&gt;             print &quot;$_: $error\n&quot;;<br>
&gt;         }<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&#39;ll bite anyway: if you change that &quot;eval&quot; into a &quot;print&quot; you<br>
will see that what&#39;s getting eval&#39;ed is something like: &quot; = -e unless<br>
-e somefilename&quot;: $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 &quot;-e&quot; or &quot;-r&quot; or &quot;-s&quot;, right? Same goes for the<br>
bareword that $xopt{data_file} becomes: you&#39;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&#39;t contain any<br>
characters that mess up your quoting!<br>
<br>
I&#39;ll be condemned to Perl Hell (or at least Heck) for this, but I<br>
think this will do what you&#39;re asking:<br>
<br>
eval qq{\$error = &#39;$_&#39; unless $_ &#39;\Q$xopt{data_file}\E&#39;};<br>
<br>
Please don&#39;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>