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

can perl make new files

by maddfisherman (Sexton)
on Aug 17, 2001 at 03:24 UTC ( [id://105566]=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: can perl make new files
by CheeseLord (Deacon) on Aug 17, 2001 at 03:27 UTC

    Indeed it can. Like this:

    open FILE, "> newfilename";

    If you need more information, look at open, or ask a more detailed question so we can help you out better.

    His Royal Cheeziness

Re: can perl make new files
by tachyon (Chancellor) on Aug 17, 2001 at 04:10 UTC

    Here is a short script that demonstates the basics of file handling. When you run this script it reads itself in, writes a copy to a file the the same name and a .clone extension and then opens this new file and appends a message to it.

    # $0 contains the name of the running script (ie this one) # $! contains error messages, if any # open file for reading open ME, "<$0" or die "Can't open myself, Perl says $!\n"; my @essence = <ME>; close ME; # open file for writing (clobber existing, create if required) # name will be whatever this script called with .clone extension open MY, ">$0.clone" or die "Failed to clone myself $!\n"; print MY @essence; close MY; # open file for appending (add to end of file) open CLONE, ">>$0.clone" or die "Clone has disappeared $!\n"; print CLONE "\n\nI am just a clone of the program $0\n"; print CLONE "Just Another Perl Hacker\n", scalar localtime; close CLONE;

    cheers

    tachyon

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

(ichimunki) Re: can perl make new files
by ichimunki (Priest) on Aug 17, 2001 at 04:29 UTC
    To get a sense of all the things Perl can do, poke around Code Catacombs (for example scripts) and the Library (for information about Perl itself)-- in the Library pay special attention to perlfunc. If you have Perl installed on your computer, you can get the same information that you will find in the Library by typing 'perldoc' at a command line. If you are curious about a specific function and you think you know the name of the function, you can do 'perldoc -f function-name'.
Re: can perl make new files
by perigeeV (Hermit) on Aug 17, 2001 at 04:20 UTC
    For the sake of completeness I'll add sysopen, but based on you're question I'd stay with plain open. Try the supplied tutorial that comes with perl.
Re: can perl make new files
by RayRay459 (Pilgrim) on Aug 17, 2001 at 19:27 UTC
    if you use an open(File,$newfilename) || die "Can't create $newfilename: $!";
    that should do it.
    Ray

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found