Michael Alipio wrote:
> Hi,

Hello,

> I have a directory which contains several files.
> 
> client1-2006-05-19.log.gz
> client1-2006-05-20.log.gz  
> client1-2006-07-29.log.gz  
> client1-2006-10-05.log.gz
> client1-2006-05-21.log.gz
> 
> 
> I want strip all of "axisglobal-" in their filenames.
> 
> What I did was:
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> use File::Find;
> 
> 
> find (\&renamefiles, './');
> 
> 
> sub renamefiles{
> (my $newname) = $_ =~ s/^\w+-//g;
> #rename ($_, $newname);
> print $newname;
> }
> 
> When I try printing the $newname which supposedly will print
>  only "2006-N-N.log.gz", it instead prints a scalar value of
> 1, as if parenthesis around "my $newname" does not exists.
> And so, uncommenting the "rename" did do anything to my files.
> 
> Any explanation to this?

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+-//;


> Do you have a perl one-liner to rename all files into their
> filenames with stripped "^\w+".

No.



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/


Reply via email to