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

[MacPerl] File creation



According to Adam Reynolds:
> 
> Hiya,
> 
> I'm fairly new at scripting with PERL and I'm trying to create a script
> for a client so that they can build their own web-pages.  I've got a
> form where they can input text, heading etc, I've finished the routines
> to format and add headers and footers to the pages, I just need to write
> the information into a file.  However 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 ??

Ok, a couple of things:

1. You _must_ have the Perl blue book.  If you don't have
it - get it.  All of these questions are answered in the
book.  :-)

2. To create files:

	open( THEFILE, ">my.file" ) || die $!;

3. To create folders:

	mkdir "this:is:my:directory";

4. To expand on the above:

#!perl
#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#
	mkdir "this:is:my:directory";
	for( $i=0; $i<5; $i++ ){
		open( THEFILE, "my.file.$i" ) || die $!;
		print THEFILE "Merry Christmas!\n";
		print THEFILE "Happy New Years!\n";
		print THEFILE "Ho-ho-ho!\n";
		print THEFILE "Jingle Bells!  Batman smells!  Errrrr...oops! ;-)\n";
		close( THEFILE );
		}

	exit( 0 );
#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#

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