develooper Front page | perl.golf | Postings from March 2006

Re: file renamer (i'm a newbie)

Thread Previous | Thread Next
From:
Eric Waguespack
Date:
March 25, 2006 00:36
Subject:
Re: file renamer (i'm a newbie)
Message ID:
1c246150603250035r6700acfeq94c8103c89590167@mail.gmail.com
that is pretty cool... I'll have to remember it.

On 3/25/06, Andrew Savige <ajsavige@yahoo.com.au> wrote:
> --- Eric Waguespack wrote:
> > ok...
> >
> > #!/usr/bin/perl -nl
> > $o=$_;y/ /_/;-e||print("renaming $o ===> $_")&&rename$o,$_
> >
> >
> > ok so you are looping around <> and adding newlines...
> > saving the name as $o
> > y is an alias for tr
> > checking if the file exists with -e
> > || print msg && rename.
> >
> > very nice, thanks a lot.
>
> Yep. To aid sight in this case, Deparse is your friend:
>
> # perl -MO=Deparse f.pl
>
> BEGIN { $/ = "\n"; $\ = "\n"; }
> LINE: while (defined($_ = <ARGV>)) {
>     chomp $_;
>     $o = $_;
>     tr/ /_/;
>     print "renaming $o ===> $_" and rename $o, $_ unless -e $_;
> }
> f.pl syntax OK
>
> Cheers,
> /-\
>
>
>
>
>
>
>
>
> ____________________________________________________
> On Yahoo!7
> Messenger - Make free PC-to-PC calls to your friends overseas.
> http://au.messenger.yahoo.com
>
>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About