Loading ...
Sorry, an error occurred while loading the content.

Re: retaining file modification time

Expand Messages
  • daymobrew@yahoo.com
    And to avoid unnecessary variables (less clutter if using strict ) you can do: ($UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed,
    Message 1 of 6 , Jan 29, 2001
    • 0 Attachment
      And to avoid unnecessary variables (less clutter if using 'strict')
      you can do:

      ($UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed,
      $UnUsed, $atime, $mtime, $ctime, $UnUsed, $UnUsed) = lstat $the_file;
      utime ($atime, $mtime, $the_file);

      There is probably a way to shorten all of this (other than an array on
      the left side) but I don't know it.

      --- In perl-beginner@y..., Kul <aka.Kul@q...> wrote:
      > cyndie@s... wrote:
      >
      > > Hi,
      > >
      > > Anyone know of a quick and easy way to change a file but retain
      the
      > > orginal file-mod times?
      > >
      > > TIA, Cyndie
      >
      > Hi Cyndie
      >
      > Do a "lstat" on the file BEFORE modification:
      > ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
      $mtime, $ctime, $blksize, $block) = lstat ($the_file);
      > Now do your modifications
      > Now you want "UTIME", with the origional times: access first, the
      modification, followed by the file name in question
      > utime ($atime, $mtime, $the_file);
      > You can replace the access or modification with any time you want
      >
      > Regards
      > Kul
    • Dan Boger
      ... how about something like this: ($atime,$mtime) = @(lstat($the_file))[8,9]; untested, but this, or very similar should work... :) -- Dan Boger System
      Message 2 of 6 , Jan 29, 2001
      • 0 Attachment
        On Tue, Jan 30, 2001 at 02:19:41AM -0000, daymobrew@... wrote:
        > And to avoid unnecessary variables (less clutter if using 'strict')
        > you can do:
        >
        > ($UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed,
        > $UnUsed, $atime, $mtime, $ctime, $UnUsed, $UnUsed) = lstat $the_file;
        > utime ($atime, $mtime, $the_file);
        >
        > There is probably a way to shorten all of this (other than an array on
        > the left side) but I don't know it.

        how about something like this:

        ($atime,$mtime) = @(lstat($the_file))[8,9];

        untested, but this, or very similar should work... :)

        --
        Dan Boger
        System Administrator
        Brainbench linux MVP
        http://www.brainbench.com
      • Charles K. Clarkson
        From: Dan Boger ... This worked for me: my ($mtime, $ctime) = (lstat $file)[8, 9]; HTH, Charles K. Clarkson
        Message 3 of 6 , Jan 29, 2001
        • 0 Attachment
          From: "Dan Boger" <dan@...>
          > On Tue, Jan 30, 2001 at 02:19:41AM -0000, daymobrew@... wrote:
          > > And to avoid unnecessary variables (less clutter if using 'strict')
          > > you can do:
          > >
          > > ($UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed,
          > > $UnUsed, $atime, $mtime, $ctime, $UnUsed, $UnUsed) = lstat $the_file;
          > > utime ($atime, $mtime, $the_file);
          > >
          > > There is probably a way to shorten all of this (other than an array on
          > > the left side) but I don't know it.
          >
          > how about something like this:
          >
          > ($atime,$mtime) = @(lstat($the_file))[8,9];
          >
          > untested, but this, or very similar should work... :)

          This worked for me:
          my ($mtime, $ctime) = (lstat $file)[8, 9];

          HTH,
          Charles K. Clarkson
        • Cynthia Rossbach
          Wow, you guys are great! Thanks for all the responses, I was able to get it to work quickly. I ended up using the very sweet, short piece of code from Charles:
          Message 4 of 6 , Jan 29, 2001
          • 0 Attachment
            Wow, you guys are great! Thanks for all the responses,
            I was able to get it to work quickly. I ended up using the very sweet, short piece of code from Charles:
             
            my ($mtime, $ctime) = (lstat $file)[8, 9];

            Thanks again, Cyndie
            -----Original Message-----
            From: Charles K. Clarkson [mailto:c_clarkson@...]
            Sent: Monday, January 29, 2001 7:49 PM
            To: perl-beginner@yahoogroups.com
            Subject: Re: [PBML] Re: retaining file modification time


            From: "Dan Boger" <dan@...>
            > On Tue, Jan 30, 2001 at 02:19:41AM -0000, daymobrew@... wrote:
            > > And to avoid unnecessary variables (less clutter if using 'strict')
            > > you can do:
            > >
            > > ($UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed,
            > > $UnUsed, $atime, $mtime, $ctime, $UnUsed, $UnUsed) = lstat $the_file;
            > > utime ($atime, $mtime, $the_file);
            > >
            > > There is probably a way to shorten all of this (other than an array on
            > > the left side) but I don't know it.
            >
            > how about something like this:
            >
            > ($atime,$mtime) = @(lstat($the_file))[8,9];
            >
            > untested, but this, or very similar should work... :)

            This worked for me:
            my ($mtime, $ctime) = (lstat $file)[8, 9];

            HTH,
            Charles K. Clarkson


          • Smith, Sheldon
            FYI: undef *can* be used on the left side of an assignment. It consumes a scalar value without the overhead of a scalar variable. See the example in
            Message 5 of 6 , Feb 7, 2001
            • 0 Attachment
              FYI: "undef" *can* be used on the left side of an assignment. It consumes a
              scalar value without the overhead of a scalar variable. See the example in
              "perlfunc":
              (undef, undef, undef, undef, undef, undef, undef,
              undef, $atime, $mtime, $ctime, undef, undef) =
              lstat $the_file;

              The slice shown "@(lstat($the_file))[8,9]" *is* cleaner....

              > -----Original Message-----
              > From: Charles K. Clarkson [mailto:c_clarkson@...]
              > Sent: Monday, January 29, 2001 10:49 PM
              > To: perl-beginner@yahoogroups.com
              > Subject: Re: [PBML] Re: retaining file modification time
              >
              >
              >
              > From: "Dan Boger" <dan@...>
              > > On Tue, Jan 30, 2001 at 02:19:41AM -0000, daymobrew@... wrote:
              > > > And to avoid unnecessary variables (less clutter if using
              > 'strict')
              > > > you can do:
              > > >
              > > > ($UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed, $UnUsed,
              > > > $UnUsed, $atime, $mtime, $ctime, $UnUsed, $UnUsed) =
              > lstat $the_file;
              > > > utime ($atime, $mtime, $the_file);
              > > >
              > > > There is probably a way to shorten all of this (other
              > than an array on
              > > > the left side) but I don't know it.
              > >
              > > how about something like this:
              > >
              > > ($atime,$mtime) = @(lstat($the_file))[8,9];
              > >
              > > untested, but this, or very similar should work... :)
              >
              > This worked for me:
              > my ($mtime, $ctime) = (lstat $file)[8, 9];
            Your message has been successfully submitted and would be delivered to recipients shortly.