Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- From: Jim Gibson <jimsgibson@xxxxxxxxx>
- Date: Tue, 19 May 2009 12:23:21 -0700
In article <6gu5159pssd62mpdciatfarh4dp0g5hb6l@xxxxxxx>, Geoff Cox
<gcox@xxxxxxxxxx> wrote:
On Tue, 19 May 2009 06:58:37 -0500, Tad J McClellan
<tadmc@xxxxxxxxxxxxxx> wrote:
If you change the requirements, the code wil likely need to be changed.
( my $name = $_ ) =~ s/\.zip$/.doc/i or return;
That is vestigial.
It used to have a purpose, but now has no purpose.
If you no longer want to replace with "doc", then you need to remove
code that replaces with "doc".
Tad,
I don't understand this. The code below gives an xls extension to the
new files where the original zip file conatined an xls file, a ppt
extension to those which contained a ppt file and a doc extension to
those which contained a doc file and the same base name as the
original zip files - but! It only works if the
( my $name = $_ ) =~ s/\.zip$/.doc/i or return;
line is present. If it isn't I get
can't call method "memberNames" on an undefined value at ***
What is happening?!
That line, besides copying the value in $_ to $name and changing the
last four characters from '.zip' to '.doc', also executes the return
statement if the s/.../.../ substitute operator returns a false value.
In other words, if $_ does not end in '.zip', none of the remaining
statements are executed for that file.
So you are attempting to process non-zip files (or directories) as a
zip file, hence the later errors. You need to put something like:
return unless /\.zip$/;
as the first line of your subroutine. With this line, only zip files
will be processed.
use warnings;
use strict;
use File::Find;
use Archive::Zip;
my $dir = 'c:/a-temp2/docs';
find( sub {
( my $name = $_ ) =~ s/\.zip$/.doc/i or return;
my $zip = Archive::Zip->new( $_ );
my($arch_ext) = ($zip->memberNames)[ 0 ]; ***
$arch_ext =~ s/.*\.//; # strip all but the extension
my $basename = $_;
$basename =~ s/\..*//; # strip off the extension
$zip->extractMember( ($zip->memberNames)[ 0 ],
"$basename.$arch_ext" );
unlink $_ or warn "Cannot delete $_: $!";
}, $dir );
--
Jim Gibson
.
- Follow-Ups:
- References:
- Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- From: Geoff Cox
- Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- From: Tad J McClellan
- Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- From: Geoff Cox
- Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- From: Tad J McClellan
- Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- From: Geoff Cox
- Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- Prev by Date: Re: ampersand subroutine
- Next by Date: Re: ampersand subroutine
- Previous by thread: Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- Next by thread: Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- Index(es):
Relevant Pages
|