[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] File creation



At 6:48 pm +0100 16.12.97, Adam Reynolds wrote:
> ... the script has to create 5 new
>files and a folder to put them in.  I've made a script to send emails of
>information but can't work out how to create new files.
>There must be something obvious I'm missing here, can somebody help ??

You can make new folders with:

	'mkdir'

i.e.

	mkdir("Macintosh HD:New Folder",0755)

(the '0755' is a UNIX file mode; think of it as a magic number and don't
worry too much about what it actually means).

To create a file, do something like:

	$myfile = "Macintosh HD:New Folder:MyFile.txt";
	open(OUT,">$myfile") ||
	    die "can't open '$myfile' for output: $!";
	print OUT "Hello world\n";
	close(OUT);

The key ingredient is the '>' that comes before the filename, which tells
Perl that you want to open an output stream.

All this is covered in simple and friendly fashion in "Programming Perl" by
Wall, Christiansen & Schwartz, pub. O'Reilly, colloquially known as "The
Blue Camel" (for reasons that will become obvious). For a very large number
of Perl-related questions (including basic ones such as this), this book is
the FM that you need to R and will often tell you everything you need to
know. Don't start the interpreter without it, as they say.

	A

--
angus@pobox.com                                   http://pobox.com/~angus/

 "The Paris slums are a gathering place for             George Orwell
  eccentric people - people who have fallen           "Down and out in
  into solitary half-mad grooves of life, and          Paris and London"
  given up trying to be normal or decent."



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch