Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

File::SimpleTouch module..

by zakzebrowski (Curate)
on Sep 17, 2003 at 12:29 UTC ( [id://292099]=perlquestion: print w/replies, xml ) Need Help??

zakzebrowski has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Yes, there is already a File::Touch module, however I was unable to get it to work correctly on a system that I was using, so I created a File::Simpletouch module, which is cross platform compatible, and it writes the character 'a' to a file, to ensure that a file will indeed be created. Would this be valuable to other people and any namespace issues?

Thanks Zak

----
Zak
undef$/;$mmm="J\nutsu\nutss\nuts\nutst\nuts A\nutsn\nutso\nutst\nutsh\ +nutse\nutsr\nuts P\nutse\nutsr\nutsl\nuts H\nutsa\nutsc\nutsk\nutse\n +utsr\nuts";open($DOH,"<",\$mmm);$_=$forbbiden=<$DOH>;s/\nuts//g;print +;

Replies are listed 'Best First'.
Re: File::SimpleTouch module..
by adrianh (Chancellor) on Sep 17, 2003 at 12:33 UTC
    Would this be valuable to other people and any namespace issues?

    Without seeing the code - who knows...

    Also, a bug report and/or patch to File::Touch would probably be more useful.

      The problem is intelectuall rights. I can't distribute a module without going through the aproval process, so I can't share it until I distribute it... (It's basicaly just exporting 'touch', and then the sub is touch{my $fn = shift; open(OUT,..) print OUT "A"; close (OUT); The past few times I've contacted module authors directly, I haven't had good luck with getting them to write a patch, though the amount of spam that I use from the account I write the email has gone up signifigantly... Also, it appears that the module's author had a different intention when writing modules (The author seems to be more concerned about time of file activitiy versus just simply touching the file, which is all I'm concerned about.)...

      ----
      Zak
      undef$/;$mmm="J\nutsu\nutss\nuts\nutst\nuts A\nutsn\nutso\nutst\nutsh\ +nutse\nutsr\nuts P\nutse\nutsr\nutsl\nuts H\nutsa\nutsc\nutsk\nutse\n +utsr\nuts";open($DOH,"<",\$mmm);$_=$forbbiden=<$DOH>;s/\nuts//g;print +;
        Well, that's certainly not what any Unix person would expect from touching a file. Touching a file that already exists should leave the file unmodified. It just updates the last modification time. Also, touching a non-existing file creates an empty file, not a file with a single letter in it. Finally, touch has the ability to set the last modification (and access) time to a user specified time.

        You might want to have a look at http://www.perl.com/language/ppt/src/touch/index.html. If that has any OS dependencies, I'd like to know.

        Abigail

        A module that opens a file, prints one character and then closes the file shouldn't be related in name to File::Touch. Call it File::NotTouch::Open::Write::Close or something. That way people will know that it is specail purpose code that has nothing to do with the touch(1) command. Otherwise, submit a bug report to the author of Touch::File (with a patch if you can) or shell out the touch command. But please, please don't contribute that clutter to a namespace that poor unsuspecting souls will confuse with a simple interface to touch(1).

        -- am
Re: File::SimpleTouch module..
by tachyon (Chancellor) on Sep 17, 2003 at 14:36 UTC

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://292099]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found