On Thu, 11 Aug 2011 23:30:32 -0700, John W. Krahn wrote:
> Peter Scott wrote:
>> On Thu, 11 Aug 2011 16:17:51 -0700, siegfried wrote:
>>> Is there a way to do it with less typing? How can I do it without
>>> creating a temporary variable "@p"? Thanks, siegfried
>>>
>>> find /xyz -exec perl -e 'foreach(@ARGV){ my @p=split "/"; rename $_,
>>> "./$p[$#p].txt" } '
>>
>> Try this:
>>
>> find /xyz -type f -print0 | perl -F/ -0lane 'rename $_,"$F[-1].txt" or
>> warn $!'
> 
> That won't work as that reads the contents of the files and not the file
> names.

No, STDIN is the list of filenames; Perl's not taking that as @ARGV.  
Observe:

$ ls -lR /tmp/xxx
/tmp/xxx:
total 4
-rw-rw-r-- 1 peter peter    0 Aug 14 11:04 a
drwxrwxr-x 2 peter peter 4096 Aug 14 11:04 yyy

/tmp/xxx/yyy:
total 0
-rw-rw-r-- 1 peter peter 0 Aug 14 11:04 b
$ pwd
/tmp/zzz
$ find /tmp/xxx -type f -print0 | perl -F/ -0lane 'rename $_,"$F[-1].txt" 
or warn $!'
$ ls -l
total 0
-rw-rw-r-- 1 peter peter 0 Aug 14 11:04 a.txt
-rw-rw-r-- 1 peter peter 0 Aug 14 11:04 b.txt
$ ls -lR /tmp/xxx
/tmp/xxx:
total 4
drwxrwxr-x 2 peter peter 4096 Aug 14 11:05 yyy

/tmp/xxx/yyy:
total 0

-- 
Peter Scott
http://www.perlmedic.com/     http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl4/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to