touching a file should create it (as an empty file) if it does not exist or update its access and modification time to now if it does.

The utility of a piece of code that presumably does this:

sub touch { open F, ">>$_[0]" or return undef; seek F, 0, 2; my $length = tell F; print F 'A'; truncate F, $length; close F; return 1; } # presuming that the utime() function used in File::Touch is broken on + your system # otherwise it would just be: utime($a, $m, $file);

as a module seems a little dubious to me. I could write the code in far less time that it would take to download and install a module. On unix why not just shell to touch? I presume you want something for Win32 and this does the job.

Although it sound from your post like you are changing the contents of the file which if so is so bad as to defy belief. I could not imagine a circumstance where I would put up with random 'A' chars peppered through my file just because I wanted to change its M time. In text files this would be extremely annoying. For everything else it would probably break the file.

This snippet should work on any platform the lets you use seek to find EOF, tell to get the POS and truncate to undo the 'change' you made to the file. The net effect is touch like.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: File::SimpleTouch module.. by tachyon
in thread File::SimpleTouch module.. by zakzebrowski

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.