[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Answer to previous question
Ok, I admit, I only did that to goad Steve into posting an
elegant one-liner. :-)
--- Steven Pritchard <steve@silug.org> wrote:
> On Mon, Aug 05, 2002 at 10:18:16PM -0500, William
> Underwood wrote:
> > chomp $_;
> > print OUTPUT (join ('.', (reverse (split (/./, $_ )))))
> ."\r\n";
>
> That's more or less how I'd do it, except you forgot to
> escape the
> '.'. The first argument to split is taken as a regular
> expression
> when it is in //, and '.' in a regex matches any
> character.
>
> Here's a one-liner that I would probably use:
>
> perl -lne 'print join(".", reverse(split /\./))'
>
> Or, if you want to edit files directly...
>
> perl -i -lpe '$_=join(".", reverse(split /\./))'
> file1 file2 [...]
>
> Add an extension after -i to have it save copies of the
> originals
> ("-i.orig" instead of just "-i", for example).
>
> Note that split works on $_ if you don't give it a second
> argument.
>
> Steve
> --
> steve@silug.org | Southern Illinois Linux Users
> Group
> (618)398-7360 | See web site for meeting
> details.
> Steven Pritchard | http://www.silug.org/
>
> -
> To unsubscribe, send email to majordomo@silug.org with
> "unsubscribe silug-discuss" in the body.
__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com
-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.