Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: One liner help

by toolic (Bishop)
on Oct 08, 2014 at 18:39 UTC ( [id://1103201]=note: print w/replies, xml ) Need Help??


in reply to One liner help

Probably not short enough to be worth it, but this works for me on unix (perl v5.12.2), and I think it has a chance to work on windows, too:
perl -anF"/\./" -E "chomp@F;say join q{.},reverse@F" zones.txt 10.100.1 10.100.2 10.100.3

Replies are listed 'Best First'.
Re^2: One liner help
by VinsWorldcom (Prior) on Oct 08, 2014 at 19:55 UTC

    Thanks. I did it slightly modified borrowing the -l from kennethk above:

    (Windows 7 x64 / Strawberry Perl v5.18.1 MSWin32-x64-multi-thread)

    VinsWorldcomC:\Users\VinsWorldcom\tmp> perl -alnF"/\./" -e "print join + q{.}, reverse @F" zones.txt 10.100.1 10.100.2 10.100.3
      Nice. And golf it down with -E/say:
      perl -anlF"/\./" -E"say join q{.},reverse@F" zones.txt
        Golf? -p and $_= save you one space over -n and say:
        perl -aplF"/\./" -E"$_=join q{.},reverse@F" zones.txt
        and a manual split takes less than -F (assuming you don't get flags for free):
        perl -lpE"$_=join q{.},reverse split/\./" zones.txt
        Using $, in place of join saves you 2, except then you lose $_=
        perl -lnE"$,=q{.};say reverse split/\./" zones.txt
        but you still win w/ a regex:
        perl -pE"s/(.+)\.(.+)\.(.+)/$3.$2.$1/" zones.txt
        and to me, that one seems a whole lot more obvious than the other offerings.

        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1103201]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found