Re: failed substitution
- From: boyd <tbmoore9@xxxxxxxxxxx>
- Date: Fri, 24 Nov 2006 22:04:01 GMT
In article <4566F811.7444.309FC868@xxxxxxxxxxxxxxxxxxxxxxx>,
dermot@xxxxxxxxxxxxxxxx (Beginner) wrote:
Hi,
Here the script, there isn't much to it. Can anyone explain why the
substitute fails?
TIA
Dp.
#!/bin/perl
# Active State 5.8.6.811
use strict;
use warnings;
use File::Basename;
my $dir = 'D:/Temp/jpegs/thumbs/';
my @files = glob("${dir}*.jpg");
foreach my $f (@files) {
(my $l) = ($f =~ /([a-z]|[a-z][a-z])\.jpg/);
(my $new = $f) =~ s/$l/_a/;
my $basef = basename($f);
my $basenew = basename($new);
print "$basef -> $basenew $l\n";
}
Strange. It worked for me - I used your data as input and got:
DSC00092a.jpg -> DSC00092_a.jpg a
DSC00093b.jpg -> DSC00093_a.jpg b
DSC00094c.jpg -> DSC00094_a.jpg c
DSC00095d.jpg -> DSC00095_a.jpg d
DSC00096e.jpg -> DSC00096_a.jpg e
DSC00097f.jpg -> DSC00097_a.jpg f
DSC00098g.jpg -> DSC00098_a.jpg g
DSC00099h.jpg -> DSC00099_a.jpg h
DSC00100i.jpg -> DSC00100_a.jpg i
DSC00101j.jpg -> DSC00101_a.jpg j
DSC00102k.jpg -> DSC00102_a.jpg k
DSC00103l.jpg -> DSC00103_a.jpg l
as expected. Maybe you have some hidden characters or something.
By the way, the regexp parser would have less work to do with:
(my $l) = ($f =~ /([a-z]|[a-z][a-z])\.jpg$/);
(in other words, tell it that the string ends in jpg).
Boyd
.
- References:
- failed substitution
- From: Beginner
- failed substitution
- Prev by Date: goto return ?
- Next by Date: Re: goto return ?
- Previous by thread: failed substitution
- Next by thread: Re: failed substitution
- Index(es):
Relevant Pages
|
|