DEV Community

Discussion on: Daily Challenge #22 - Simple Pig Latin

Collapse
 
yzhernand profile image
Yozen Hernandez

Perl one-liner as well

say join(" ", map { s/(\w)(\w+)/\2\1ay/r } split /\s/, "Pig latin is cool")

#igPay atinlay siay oolcay

This one handles leaving punctuation alone, so this would work as well:

say join(" ", map { s/(\w)(\w+)/\2\1ay/r } split /\s/, '"Pig" latin is cool')

#"igPay" atinlay siay oolcay
Collapse
 
choroba profile image
E. Choroba

No need to split and join:

say '"Pig" latin is cool' =~ s/(\w)(\w+)/$2$1ay/gr;
Collapse
 
yzhernand profile image
Yozen Hernandez

Of course. Thanks!