Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: split string using optimized code or perl one liner

by Eily (Monsignor)
on Feb 22, 2017 at 14:03 UTC ( [id://1182526] : note . print w/replies, xml ) Need Help??


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

Is it about efficiency or number of lines? In the first case, you'll have to Benchmark a bunch of solutions. Otherwise, TIMTOWTDI.

$string = 'www.perlmonks.org.split.reduce.code.check'; print join " ", reverse( $string =~ /(\w+)/g); $, = " "; print reverse (split /[.]/, $string); my $out; $out = "$_ $out" for split /[.]/, $string; # Extra space at the end th +ough print $out;