----- Original Message ---- From: John W. Krahn <[EMAIL PROTECTED]> To: Perl Beginners <beginners@perl.org> Sent: Wednesday, January 24, 2007 10:57:51 AM Subject: Re: trouble with list context assignment for substitution inside File::Find &wanted function
> 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. Changed this:1 find (\&renamefiles, './'); sub renamefiles{ if ($_ =~ /axis/){ my $oldname = $_; $_ =~ s/\w+-//; #rename ($oldname, $_) print "$oldname will be renamed to $_\n"; } } To this: find (\&renamefiles, './'); my $name = shift; sub renamefiles{ if ($_ =~ /$name/){ my $oldname = $_; $_ =~ s/\w+-//; #rename ($oldname, $_) print "$oldname will be renamed to $_\n"; } } And if I do a #perl rename.pl axis I got many of this: Use of uninitialized value in regexp compilation at test.pl line 11. Even if I specify "axis" in my $name instead of shift, I'm getting the same error What's wrong with using variables in regexp patterns?? John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ ____________________________________________________________________________________ Yahoo! Music Unlimited Access over 1 million songs. http://music.yahoo.com/unlimited