Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

"touching" a file

by drock (Beadle)
on Jun 16, 2004 at 18:54 UTC ( #367374=perlquestion: print w/replies, xml ) Need Help??

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

Is there an ideal whay just to create a file with having to go through openening a filehandle and then using > thank you!

Replies are listed 'Best First'.
Re: "touching" a file
by sacked (Hermit) on Jun 16, 2004 at 18:58 UTC
Re: "touching" a file
by spartan (Pilgrim) on Jun 16, 2004 at 19:15 UTC
    I've used the following with great success:
    open FH, ">>/full/path/to/file";

    Please note, I cannot take credit for this snippet, it was given to me by a kind person in the CB months ago.

    Very funny Scotty... Now PLEASE beam down my PANTS!
      your sig made me burst out laughing... lmao

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Re: "touching" a file
by ambrus (Abbot) on Jun 17, 2004 at 06:18 UTC

    You cannot usually create a regular file without opening it (this does not apply to a directory). There is only one way around this I know, and that only works for the super-user: the mknod syscall.

    Update: added readmore. You don't want to know why.

      Why the ($n="filename") and not just "filename"?

        Perl 5.6.1 gives me "Modification of a read-only value attempted" without the assignment.

        From perldoc perlfunc syscall:

        You can't use a string literal (or other read-only string) as an argument to "syscall" because Perl has to assume that any string pointer might be written through.

        (Update:) you can probably get around this with unpack"i",pack"p","filename" but I haven't tried.

Re: "touching" a file
by halley (Prior) on Jun 16, 2004 at 18:58 UTC
    Your question is not particularly clear. If you want the operating system to mark a file as having been modified, you're usually going to have to open the file for writing.

    [ e d @ h a l l e y . c c ]

      Erm, perldoc -f utime.

      Actually, perldoc -f utime :)

      The more you know, brought to you by perldoc and perlmonks :)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2023-09-27 05:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found