Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: split string using optimized code or perl one liner (updated)

by haukex (Archbishop)
on Feb 22, 2017 at 14:11 UTC ( [id://1182527] : note . print w/replies, xml ) Need Help??


in reply to split string using optimized code or perl one liner

Hi madtoperl,

A oneliner you say?

$ echo abc.def.ghi.jkl.mno | \ perl -lne 'print join ".", reverse split /\./' mno.jkl.ghi.def.abc

Update: Golfed a tiny bit. If your shell causes you trouble with the backslash, try -F"[.]" instead.

$ echo abc.def.ghi.jkl.mno | \ perl -F'\.' -lpe'$_=join".",reverse@F' mno.jkl.ghi.def.abc

Documentation of the switches is in perlrun.

Regards,
-- Hauke D