[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <3FDD817A.8010203@outblaze.com> [ref] => [htmlstate] => on_nl2br [postusername] => Victor [ip] => victor@outblaze [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 5 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Getting the most recent file - PERL Beginners

Getting the most recent file - PERL Beginners

I am trying to write some code to read the most recent log file in a directory. I wrote some code below. This works but I was wondering if there was a more efficient method to do this. Ideally I would like to include hours, minutes and seconds but that's not necessary at this point. --Paul foreach $iislog (files) { ($WRITETIME) = (stat("$iislogs\$iislog"))[9]; print scalar localtime ($WRITETIME); ($seconds, $minutes, $hours, $day, $month, $year, $wday, $yday, $isdst) = localtime(); ($seconds2, $minutes2, $hours2, $day2, $month2, $year2, $wday2, $yday2, $isdst2) = localtime($WRITETIME); if ($day == $day2 && $month == $month2) { #print scalar ...

  1. #1

    Default Getting the most recent file

    I am trying to write some code to read the most recent log file in a
    directory. I wrote some code below. This works but I was wondering if
    there was a more efficient method to do this. Ideally I would like to
    include hours, minutes and seconds but that's not necessary at this
    point.

    --Paul

    foreach $iislog (files) {

    ($WRITETIME) = (stat("$iislogs\\$iislog"))[9];

    print scalar localtime ($WRITETIME);

    ($seconds, $minutes, $hours, $day, $month, $year, $wday, $yday,
    $isdst) = localtime();
    ($seconds2, $minutes2, $hours2, $day2, $month2, $year2, $wday2,
    $yday2, $isdst2) = localtime($WRITETIME);

    if ($day == $day2 && $month == $month2) {



    #print scalar localtime();
    print "\n\n";
    print "The file was last modified on: ";
    print scalar localtime ($WRITETIME);
    print "\n\n";

    }
    }

    Perl Guest

  2. #2

    Default Re: Getting the most recent file

    <Perlnyclimits.org> wrote:
    >
    > I am trying to write some code to read the most recent log file in a
    > directory. I wrote some code below. This works but I was wondering if
    > there was a more efficient method to do this. Ideally I would like to
    > include hours, minutes and seconds but that's not necessary at this
    > point.
    >
    > foreach $iislog (files) {
    >
    > ($WRITETIME) = (stat("$iislogs\\$iislog"))[9];
    >
    > print scalar localtime ($WRITETIME);
    >
    > ($seconds, $minutes, $hours, $day, $month, $year, $wday, $yday, $isdst) = localtime();
    > ($seconds2, $minutes2, $hours2, $day2, $month2, $year2, $wday2, $yday2, $isdst2) = localtime($WRITETIME);
    >
    > if ($day == $day2 && $month == $month2) {
    >
    > print "\n\n";
    > print "The file was last modified on: ";
    > print scalar localtime ($WRITETIME);
    > print "\n\n";
    > }
    > }
    Hi Paul.

    First of all,

    use strict; # And declare all of your variables
    use warnings;

    # And indent your code!

    Then I'm not sure what you need. You say you want to read the most recent log file,
    but your code just prints out a list of modification times. Do you need this
    as well,or do you just want to find the latest file?

    (stat $file)[9]

    gives you the modification date, while

    -M $file

    gives you the age of the file. So you could just write

    files = sort { -M $a <=> -M $b } files;
    print $files[-1], "\n";

    Or do you need anything more?

    HTH,

    Rob


    Rob Dixon Guest

  3. #3

    Default RE: Getting the most recent file

    One question I have:

    With this statement:

    files = sort { -M $a <=> -M $b } files;

    How does Perl understand that these are files and not just text entries?
    Did using the readdir beforehand make this possible?

    -----Original Message-----
    From: Rob Dixon [mailto:robdixon.port995.com]
    Posted At: Saturday, December 13, 2003 6:27 AM
    Posted To: Perl
    Conversation: Getting the most recent file
    Subject: Re: Getting the most recent file

    <Perlnyclimits.org> wrote:
    >
    > I am trying to write some code to read the most recent log file in a
    > directory. I wrote some code below. This works but I was wondering if
    > there was a more efficient method to do this. Ideally I would like to
    > include hours, minutes and seconds but that's not necessary at this
    > point.
    >
    > foreach $iislog (files) {
    >
    > ($WRITETIME) = (stat("$iislogs\\$iislog"))[9];
    >
    > print scalar localtime ($WRITETIME);
    >
    > ($seconds, $minutes, $hours, $day, $month, $year, $wday, $yday,
    $isdst) = localtime();
    > ($seconds2, $minutes2, $hours2, $day2, $month2, $year2, $wday2,
    $yday2, $isdst2) = localtime($WRITETIME);
    >
    > if ($day == $day2 && $month == $month2) {
    >
    > print "\n\n";
    > print "The file was last modified on: ";
    > print scalar localtime ($WRITETIME);
    > print "\n\n";
    > }
    > }
    Hi Paul.

    First of all,

    use strict; # And declare all of your variables
    use warnings;

    # And indent your code!

    Then I'm not sure what you need. You say you want to read the most
    recent log file,
    but your code just prints out a list of modification times. Do you need
    this
    as well,or do you just want to find the latest file?

    (stat $file)[9]

    gives you the modification date, while

    -M $file

    gives you the age of the file. So you could just write

    files = sort { -M $a <=> -M $b } files;
    print $files[-1], "\n";

    Or do you need anything more?

    HTH,

    Rob



    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Paul Harwood Guest

  4. #4

    Default Re: Getting the most recent file

    Paul Harwood wrote:
    >
    > One question I have:
    >
    > With this statement:
    >
    > files = sort { -M $a <=> -M $b } files;
    >
    > How does Perl understand that these are files and not just text entries?
    > Did using the readdir beforehand make this possible?
    Well they /are/ just text entries! But ones that correspond to the names
    of existing files. Strictly speaking it's possible for a file to have been
    deleted between cataloguing it with 'readdir' and sorting the list,
    but this will just give you a warning (if you have 'use warnings' set)
    and sort the vanished file as if it had an age of zero days. If your
    software is at all permanent then you can temporarily switch off that
    particular warning by putting the statement in a block like this:

    {
    no warnings 'uninitialized';
    files = sort { -M $a <=> -M $b } files;
    }

    (After that, you should really cope with the condition where /all/
    of the files have been deleted in the interim so thet even the
    oldest file doesn't exist :)

    You also need to be aware that, unless the directory listing is
    of your current directory each element needs to be prefixed with
    the full path.

    HTH,

    Rob



    Rob Dixon Guest

  5. #5

    Default Re: Getting the most recent file

    That "-M" is a perl file test operator, it will take the string after it
    as name of a file automatically.

    Tor.

    Paul Harwood wrote:
    >One question I have:
    >
    >With this statement:
    >
    >files = sort { -M $a <=> -M $b } files;
    >
    >How does Perl understand that these are files and not just text entries?
    >Did using the readdir beforehand make this possible?
    >
    >-----Original Message-----
    >From: Rob Dixon [mailto:robdixon.port995.com]
    >Posted At: Saturday, December 13, 2003 6:27 AM
    >Posted To: Perl
    >Conversation: Getting the most recent file
    >Subject: Re: Getting the most recent file
    >
    ><Perlnyclimits.org> wrote:
    >
    >
    >>I am trying to write some code to read the most recent log file in a
    >>directory. I wrote some code below. This works but I was wondering if
    >>there was a more efficient method to do this. Ideally I would like to
    >>include hours, minutes and seconds but that's not necessary at this
    >>point.
    >>
    >>foreach $iislog (files) {
    >>
    >> ($WRITETIME) = (stat("$iislogs\\$iislog"))[9];
    >>
    >> print scalar localtime ($WRITETIME);
    >>
    >> ($seconds, $minutes, $hours, $day, $month, $year, $wday, $yday,
    >>
    >>
    >$isdst) = localtime();
    >
    >
    >> ($seconds2, $minutes2, $hours2, $day2, $month2, $year2, $wday2,
    >>
    >>
    >$yday2, $isdst2) = localtime($WRITETIME);
    >
    >
    >> if ($day == $day2 && $month == $month2) {
    >>
    >> print "\n\n";
    >> print "The file was last modified on: ";
    >> print scalar localtime ($WRITETIME);
    >> print "\n\n";
    >> }
    >>}
    >>
    >>
    >
    >Hi Paul.
    >
    >First of all,
    >
    > use strict; # And declare all of your variables
    > use warnings;
    >
    ># And indent your code!
    >
    >Then I'm not sure what you need. You say you want to read the most
    >recent log file,
    >but your code just prints out a list of modification times. Do you need
    >this
    >as well,or do you just want to find the latest file?
    >
    > (stat $file)[9]
    >
    >gives you the modification date, while
    >
    > -M $file
    >
    >gives you the age of the file. So you could just write
    >
    > files = sort { -M $a <=> -M $b } files;
    > print $files[-1], "\n";
    >
    >Or do you need anything more?
    >
    >HTH,
    >
    >Rob
    >
    >
    >
    >
    >

    --
    <!---------------------------------------------
    Victor
    Development Engineer
    Outblaze Ltd
    ---------------------------------------------->


    Victor Guest

  6. #6

    Default Re: Getting the most recent file

    That code is backwards, BTW, it gives the _oldest_ file!
    Terence Guest

Similar Threads

  1. Recent File - History
    By Steven_Ravett_Brown@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 3
    Last Post: May 22nd, 05:20 AM
  2. Recent File list in (CS) Windows XP
    By Lee_Pierce@adobeforums.com in forum Adobe Indesign Windows
    Replies: 0
    Last Post: June 14th, 09:31 PM
  3. Recent File List
    By Martin_Folley@adobeforums.com in forum Adobe Indesign Windows
    Replies: 1
    Last Post: June 10th, 09:17 AM
  4. Lacking recent files in 'File' menu
    By Gert_Caspersen@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 7
    Last Post: May 25th, 06:44 AM
  5. Clearing the File>Open recent menu
    By coreywilliams@adobeforums.com in forum Adobe Photoshop & Illustrator
    Replies: 12
    Last Post: May 1st, 11:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139