Ben Crane wrote:
>
> Hi all,
Hello,
> Anyone know how to do a wildcard file::copy? E.g. I
> want to copy a file with a certain name but different
> extensions.
>
> I have tried concatenating ".*" to the end of a
> filename (without an extension obviously) but it
> fails.
> This is what I had in mind...it's just a scribble and
> not exactly the way the code will go.
>
> $string2 = "$string[1]".".*";
^ ^
^ ^
> copy("$string2","$destination") || warn "could not copy files: $!";
^ ^ ^ ^
^ ^ ^ ^
perldoc -q "What\'s wrong with always quoting \"\\$vars\"?"
You can't simply use a wildcard in a string, you have to expand the wildcard
to a list and iterate over the list. Something like:
use File::Copy;
my $filename = 'filename';
# use glob to expand wildcard
for my $file ( <$filename.*> ) {
# copy each individual file
copy( $file, "$filename.newext" ) or warn "Cannot copy $file: $!";
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>