any help?
From: Matthew Siddall (ms003h3818_at_blueyonder.co.uk)
Date: 08/13/04
- Next message: omoore: "Re: any help?"
- Previous message: omoore: "Re: How to refresh a window using Win32::GUI"
- Next in thread: omoore: "Re: any help?"
- Reply: omoore: "Re: any help?"
- Reply: Chris Cole: "Re: any help?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 13 Aug 2004 10:54:10 GMT
Hiya all,
I'm trying to teach myself some perl so I can write cgi script eventually to
modify files on a remote server. I'm trying to grasp certain things, so I
have written a subroutine to create a file and pre-fill it with certain
values, based on the arguments given to the subroutine. Each file I create
has the file name as it's first line (for ease of access among other things)
and I'm trying to write a subroutine to let me change the name of the file,
including changing the first line of the file.
So far, i have been able to do all that by creating a new file and writing
the data across one line at a time (using a for loop) but I can't get it to
delete the old file. I've looked everywhere I could think of on the
documentation, and I can't see a delete file command (there is a delete
command, but it seemed to reference variables, and I don't want to screw
things up). I tried renaming the file so I could then delete it manually
later, but for some reason it won't rename it, even if I close the file
before trying (I thought it may be because the file is still open).
I'm running win2000 with Activestate ActivePerl 5.8, and I'm almost
completely new to it, so if you can offer any help I'd be grateful.
The code I have so far is:
open(LOG, ">>log.txt") or die "can't open logfile: $!";
# ren(a, b) creates a copy of file a called b and changes the first line to
b then marks a for deletion
sub ren {
my $old = shift;
my $new = shift;
print LOG "rename $old -> $new \n";
open OLD, "< $old" or die "cannot open $old :$!";
open NEW, "> $new" or die "cannot open $new :$!";
my $line = <OLD>;
print NEW "$new \n";
while (<OLD>)
{
print NEW "$_";
}
my $newname = "deleted";
renf($old, $newname);
}
# renf(a, b) renames file a to b
sub renf {
$a = shift;
$b = shift;
rename($a, $b);
print LOG "renamed $a to $b \n";
}
ren(mike, martin);
____
mike was the name of a random file I created to test this.
Thanks,
Matt
- Next message: omoore: "Re: any help?"
- Previous message: omoore: "Re: How to refresh a window using Win32::GUI"
- Next in thread: omoore: "Re: any help?"
- Reply: omoore: "Re: any help?"
- Reply: Chris Cole: "Re: any help?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|