Michael Alipio am Mittwoch, 24. Januar 2007 04:21:
> From: John W. Krahn <[EMAIL PROTECTED]>
> Sent: Wednesday, January 24, 2007 10:57:51 AM
> >  Yes, the substitution operator (s///) returns true (1) or false ('') in
> > either list or scalar context.  To do want you want you have to do the
> > assignment first and then do the substitution:
> >
> >  my $newname = $_;
> >  $newname =~ s/^\w+-//;
> >
> >  Or in one statement:
> >
> >  ( my $newname = $_ ) =~ s/^\w+-//;
>
> I've already figured that one out. However, I want to use variables for my
> regexp pattern. So I can replace "axis" with whatever I my first program
> argument is.
[...]

Hi Michael

> find (\&renamefiles, './');
> my $name = shift;

You initialize $name after the call to find(), so renamefiles() has nothing in 
$name. Switch these lines (and test the user provided contents of $name)

> sub renamefiles{
>   if ($_ =~ /$name/){

if ($_ =~ /\Q$name\E/){

just in case $name contains chars that are special to the regex engine.

>     my $oldname = $_;
>     $_ =~ s/\w+-//;
>     #rename ($oldname, $_)
>     print "$oldname will be renamed to $_\n";
>   }
> }
>
> I got many of this:
>
> Use of uninitialized value in regexp compilation at test.pl line 11.

Dani

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to