<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Perl's -M file Test operator in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902261#M839434</link>
    <description>This should be a snap so I must be doing something really dumb.&lt;BR /&gt;&lt;BR /&gt;I want to do something with files created in the last X days.  (I have used 17 in this example to pick up files from this month.)&lt;BR /&gt;&lt;BR /&gt;For the directory in question there is a bunch of matching files going back years.&lt;BR /&gt;&lt;BR /&gt;Why when I execute this code is the "false" line aways printed???&lt;BR /&gt;____________&lt;BR /&gt;&lt;BR /&gt;#! /usr/bin/perl&lt;BR /&gt;$aDir = '/tmp';&lt;BR /&gt;&lt;BR /&gt;@result = `find $aDir -name \"*error.log\"`;&lt;BR /&gt;&lt;BR /&gt;foreach $file (@result) {&lt;BR /&gt;&lt;BR /&gt; if ((-M $file) &amp;gt; 16.0)&lt;BR /&gt;        { $tmp = `ls -l $file`; print "true: $tmp"; }&lt;BR /&gt; else&lt;BR /&gt;        { $tmp = `ls -l $file`; print "false: $tmp"; }&lt;BR /&gt;}</description>
    <pubDate>Mon, 16 May 2005 21:35:08 GMT</pubDate>
    <dc:creator>Daavid Turnbull</dc:creator>
    <dc:date>2005-05-16T21:35:08Z</dc:date>
    <item>
      <title>Perl's -M file Test operator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902261#M839434</link>
      <description>This should be a snap so I must be doing something really dumb.&lt;BR /&gt;&lt;BR /&gt;I want to do something with files created in the last X days.  (I have used 17 in this example to pick up files from this month.)&lt;BR /&gt;&lt;BR /&gt;For the directory in question there is a bunch of matching files going back years.&lt;BR /&gt;&lt;BR /&gt;Why when I execute this code is the "false" line aways printed???&lt;BR /&gt;____________&lt;BR /&gt;&lt;BR /&gt;#! /usr/bin/perl&lt;BR /&gt;$aDir = '/tmp';&lt;BR /&gt;&lt;BR /&gt;@result = `find $aDir -name \"*error.log\"`;&lt;BR /&gt;&lt;BR /&gt;foreach $file (@result) {&lt;BR /&gt;&lt;BR /&gt; if ((-M $file) &amp;gt; 16.0)&lt;BR /&gt;        { $tmp = `ls -l $file`; print "true: $tmp"; }&lt;BR /&gt; else&lt;BR /&gt;        { $tmp = `ls -l $file`; print "false: $tmp"; }&lt;BR /&gt;}</description>
      <pubDate>Mon, 16 May 2005 21:35:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902261#M839434</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2005-05-16T21:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Perl's -M file Test operator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902262#M839435</link>
      <description>Here's the perl way to do it&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn/itrc 128 &amp;gt; perl -MFile::Find -le'find(sub{/\.log$/ and$res{$File::Find::name}=[stat]},"/tmp");for(keys%res){$x=-M$_&amp;lt;16.0?"True":"False";print scalar localtime$res{$_}[9]," $_ ($x)"}'&lt;BR /&gt;Tue Mar 22 14:16:04 2005 /tmp/kde-merijn/konqueror-crash-o4ueGb.log (False)&lt;BR /&gt;Sun May  8 12:05:28 2005 /tmp/p59.log (True)&lt;BR /&gt;Sun May  1 18:33:50 2005 /tmp/xine-plugin.log (True)&lt;BR /&gt;Sun May  1 18:33:42 2005 /tmp/Download/hs_err_pid25962.log (True)&lt;BR /&gt;Thu Dec 16 18:53:44 2004 /tmp/Download/gnokii-0.6.4/config.log (False)&lt;BR /&gt;Tue May  3 23:45:29 2005 /tmp/kde-merijn/konqueror-crash-9qeahb.log (True)&lt;BR /&gt;Thu May 12 23:24:43 2005 /tmp/kde-merijn/konqueror-crash-J39zLb.log (True)&lt;BR /&gt;Tue Mar 22 19:36:35 2005 /tmp/kde-merijn/konqueror-crash-6ugIvb.log (False)&lt;BR /&gt;Tue Apr 19 19:02:41 2005 /tmp/kde-merijn/konqueror-crash-AVMgqb.log (False)&lt;BR /&gt;Tue May  3 23:51:23 2005 /tmp/kde-merijn/konqueror-crash-YA25Xa.log (True)&lt;BR /&gt;Tue Apr 19 14:04:19 2005 /tmp/kde-merijn/konqueror-crash-USJMgc.log (False)&lt;BR /&gt;Fri Apr 22 20:41:55 2005 /tmp/kde-merijn/konqueror-crash-zP78wb.log (False)&lt;BR /&gt;Mon Oct 13 20:40:06 2003 /tmp/Download/avifile-0.7-0.7.38/config.log (False)&lt;BR /&gt;Tue May  3 20:13:38 2005 /tmp/kde-merijn/konqueror-crash-IILVNb.log (True)&lt;BR /&gt;lt09:/home/merijn/itrc 129 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Or in a script:&lt;BR /&gt;&lt;BR /&gt;--8&amp;lt;---&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use File::Find;&lt;BR /&gt;&lt;BR /&gt;my %res;&lt;BR /&gt;find (sub {&lt;BR /&gt; m/\.log$/ and $res{$File::Find::name} = [ stat ];&lt;BR /&gt; },"/tmp");&lt;BR /&gt;&lt;BR /&gt;foreach my $file (keys %res) {&lt;BR /&gt; my $x = -M $_ &amp;lt; 16.0 ? "True" :"False";&lt;BR /&gt; print scalar localtime $res{$_}[9], " $_ ($x)\n";&lt;BR /&gt; }'&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;&lt;BR /&gt;Sorry I switched true and false, but I guess you get the drift here&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Tue, 17 May 2005 01:27:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902262#M839435</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2005-05-17T01:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Perl's -M file Test operator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902263#M839436</link>
      <description>Yes H.Merijn, this does look like it will do what I am after - thank you.&lt;BR /&gt;&lt;BR /&gt;I will update just how well it works tomorrow before closing the thread and assigning points.&lt;BR /&gt;&lt;BR /&gt;I am curious however to know what was wrong with my code? (apart from relying to much on commands designed for ues in a shell.)  The relevant pages of may camel book are quite warn!</description>
      <pubDate>Tue, 17 May 2005 01:35:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902263#M839436</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2005-05-17T01:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Perl's -M file Test operator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902264#M839437</link>
      <description>OK, I'll tell you if you promise not to use external `find`s anymore :)&lt;BR /&gt;&lt;BR /&gt;If you take a real close look at the entries in @result, you'd see that the file names have trailing new lines :)&lt;BR /&gt;&lt;BR /&gt;chomp (@result = grep /error\.log$/ =&amp;gt; `find /tmp`);&lt;BR /&gt;&lt;BR /&gt;would have done it your way&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 May 2005 01:44:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902264#M839437</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2005-05-17T01:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Perl's -M file Test operator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902265#M839438</link>
      <description>I think the reason why your code didn't work is that you forgot to chomp the newline character on $file variable.&lt;BR /&gt;&lt;BR /&gt;foreach $file (@result) {&lt;BR /&gt;&lt;BR /&gt;chomp $file;&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;}</description>
      <pubDate>Tue, 17 May 2005 01:59:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902265#M839438</guid>
      <dc:creator>Ermin Borovac</dc:creator>
      <dc:date>2005-05-17T01:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Perl's -M file Test operator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902266#M839439</link>
      <description>Thanks!  Once I unraveled what each bit did it makes sense and was easy to import into the application.&lt;BR /&gt;&lt;BR /&gt;"warnings.pm" does not seem to be available on the system I am working on which seemed a little odd.  I presume this is normally part of the standard distribution?</description>
      <pubDate>Tue, 17 May 2005 21:30:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902266#M839439</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2005-05-17T21:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Perl's -M file Test operator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902267#M839440</link>
      <description>warnings.pm is core module that was first introduced in 5.6 me thinks.&lt;BR /&gt;&lt;BR /&gt;It is a replacement for command line flag -w, and while -w flag is global, warnings.pm can be used to enable/disable warnings for a block of code.</description>
      <pubDate>Tue, 17 May 2005 22:33:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902267#M839440</guid>
      <dc:creator>Ermin Borovac</dc:creator>
      <dc:date>2005-05-17T22:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Perl's -M file Test operator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902268#M839441</link>
      <description>If you do not have warnings, you run 5.6.2 or older. You could consider upgrading to a more recent perl:&lt;BR /&gt;&lt;BR /&gt;warnings  was first released with perl 5.006&lt;BR /&gt;  5.006      undef&lt;BR /&gt;  5.006001   undef&lt;BR /&gt;  5.006002   undef&lt;BR /&gt;  5.007003   1.00&lt;BR /&gt;  5.008      1.00&lt;BR /&gt;  5.008001   1.03&lt;BR /&gt;  5.008002   1.03&lt;BR /&gt;  5.008003   1.03&lt;BR /&gt;  5.008004   1.03&lt;BR /&gt;  5.008005   1.03&lt;BR /&gt;  5.008006   1.03&lt;BR /&gt;  5.009      1.03&lt;BR /&gt;  5.009001   1.03&lt;BR /&gt;  5.009002   1.04&lt;BR /&gt;&lt;BR /&gt;The big advantage of 'use warnings' over -w, is that use warnings is lexically scoped. That means that if you use -w (which is good), it would also promote the warnings setting to all modules and scripts used from the calling process, whereas 'use warnings' only affects the current scope, and you can even put off subsets of warnings for (sub) blocks where you know things would warn.&lt;BR /&gt;&lt;BR /&gt;# perldoc warnings&lt;BR /&gt;# perldoc perllexwarn&lt;BR /&gt;&lt;BR /&gt;for a more elaborate explanation and examples that make sense. The latter also describes wich categories can be enabled or disabled.&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Wed, 18 May 2005 01:06:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902268#M839441</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2005-05-18T01:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Perl's -M file Test operator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902269#M839442</link>
      <description>Thanks for your assistance.&lt;BR /&gt;&lt;BR /&gt;I have learnt a lot from your input.&lt;BR /&gt;&lt;BR /&gt;I promise not to use the external find from within Perl ;-)&lt;BR /&gt;&lt;BR /&gt;(I am a tad embarrased about not picking the new lines as the culprit for why my original code was not working as I have been caught by this previously.)&lt;BR /&gt;&lt;BR /&gt;The current platform is perl5.005_03 which explains why warnings.pm was not present.</description>
      <pubDate>Wed, 18 May 2005 01:16:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-s-m-file-test-operator/m-p/4902269#M839442</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2005-05-18T01:16:35Z</dc:date>
    </item>
  </channel>
</rss>

