SPUG: Problem deleting files

Matt Tucker tuck at whistlingfish.net
Thu Nov 30 23:48:56 CST 2000


-- rick.croote at philips.com spake thusly:

> To backup what Tim said, more so, don't use unlink <$oldfile>, use
> unlink $oldfile or unlink ($oldfile).

This wouldn't work, because he's trying to delete files using globbing. 
The following would work:

    my $oldfiles = 'foo.*';
    unlink < $oldfiles >;

As would:

    use File::Glob qw(:glob);

    my $oldfiles = 'foo.*';
    unlink glob($oldfiles);

The first one gives a warning for some reason (haven't looked into why), but the second doesn't.

As for why the code isn't working, does it have something to do with mixing up shell variables and perl variables?

Doing the following in Perl:

    $oldfile="../html/wrt_archive/weekly_archive/*to$twodaysback*.*";
    unlink glob($oldfile) or warn "Can't delete '$oldfile': $!\n";

and the following on the command line:

    rm ../html/wrt_archive/weekly_archive/*to$twodaysback*.*

What exactly is the $twodaysback variable, and where is it coming from?

Although on second thought, if this isn't set in Perl, you'd just be doing:

    rm ../html/wrt_archive/weekly_archive/*to*.*

which should work. Trying doing:

    system "ls ../html/wrt_archive/weekly_archive/";

to make sure you're in the right directory, and see what you get.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://mail.pm.org/archives/spug-list/attachments/20001130/b853497f/attachment.bin


More information about the spug-list mailing list