For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2007 > trouble with list context assignment for substitution inside File::Find &wanted f









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author trouble with list context assignment for substitution inside File::Find &wanted f
Michael Alipio

2007-01-23, 10:00 pm

Hi,


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 myfiles.

Any explanation to this?
Do you have a perl one-liner to rename all files into their filenames with stripped "^\w+"... thanks.


Thanks.








________________________________________
________________________________________
____
Do you Yahoo!?
Everyone israving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com