<?xml version="1.0" encoding="windows-1252"?>
<node id="1006645" title="Re^3: How can i debug compound map/grep statements just using print?" created="2012-12-01 16:39:01" updated="2012-12-01 16:39:01">
<type id="11">
note</type>
<author id="965102">
Kenosis</author>
<data>
<field name="doctext">
&lt;p&gt;You have the following:&lt;/p&gt;
&lt;c&gt;
=item B&lt;-a, --amount&gt;

Search for files older than &lt;amount&gt; days, mandatory.
&lt;/c&gt;
&lt;p&gt;In two days, there are 2 * 24 * 60 * 60 or 172800 seconds, thus it seemed that the following was needed:&lt;/p&gt;
&lt;c&gt;
$amount = $amount * 24 * 60 * 60;
&lt;/c&gt;
&lt;p&gt;since one day equals 24 * 60 * 60 or 86400 seconds.  Additionally, the following worked when I ran it using the above formula for &lt;c&gt;$amount&lt;/c&gt;:&lt;/p&gt;
&lt;c&gt;
$result =
  grep { /.+\.$suffix$/ and $time - ( $_-&gt;stat )[9] &gt;= $amount }
  io($dir)-&gt;all;
&lt;/c&gt;
&lt;p&gt;An equivalent search can be done using [http://search.cpan.org/~rclamp/File-Find-Rule-0.33/lib/File/Find/Rule.pm|File::Find::Rule]:&lt;/p&gt;
&lt;c&gt;
$result = File::Find::Rule-&gt;file()
						  -&gt;maxdepth(1)
						  -&gt;name(qr/.+\.$suffix$/i)
						  -&gt;mtime("&gt;= $amount")
						  -&gt;in($dir);
&lt;/c&gt;
&lt;p&gt;And the following, too, but &lt;c&gt;grep&lt;/c&gt;ping on days old instead of using &lt;c&gt;mtime&lt;/c&gt;:&lt;/p&gt;
&lt;c&gt;
$result = grep { -M &gt;= $amount / 86400 } # Convert back to days
          File::Find::Rule-&gt;file()
                          -&gt;maxdepth(1)
                          -&gt;name(qr/.+\.$suffix$/i)
                          -&gt;in($dir);
&lt;/c&gt;
&lt;p&gt;All three methods produced the same result, even when an equivalent constant was used for the days in the last &lt;c&gt;grep&lt;/c&gt;.&lt;/p&gt;
&lt;p&gt;After adjusting the &lt;c&gt;$amount&lt;/c&gt; formula, your original code produced the same result, too:&lt;/p&gt;
&lt;c&gt;
    $result =
      grep { $_ == 1 }
      map  { $time - $_ &gt;= $amount }
      map  { ( $_-&gt;stat )[9] }  # e.g i'm interested in this...
      grep { $_-&gt;name =~ /.+\.$suffix$/ } # ...and this
      io($dir)-&gt;all;
&lt;/c&gt;
&lt;p&gt;Thus, all four code snippets produced identical results.&lt;/p&gt;</field>
<field name="root_node">
1006618</field>
<field name="parent_node">
1006632</field>
</data>
</node>
