On 30/08/2011 17:54, Emeka wrote:
$s =~ s{(\w+)}{scalar reverse($1)}eg; --- From Shlomi Fish
perl -e'@words=split/\s+/,$ARGV[0];$_=reverse$_
for@words;print"@words\n";' 'abcd efgh ijkl mnop' Shawn Corey
print join ' ', map scalar reverse($_), split ' ', $str; Rob Dixon
It is time we explain our codes ... I don't think that Narasimha will
easily wrap his head around the first two.
(Once again Emeka, please bottom-post your responses and edit what you
are quoting to what is relevant. Thanks :)
I agree. It is a shame that senior and supposedly wise contributors here
feel the need to boost their egos by posting obscure code. It is
primarily a /beginners/ list, and should be treated as such. If you
cannot teach then please hold off from showing us your wares. Perl
already has a reputation for being incomprehensible without people who
should know better proving that they are right.
In particular I believe Perl should be treated as a programming
language. Its flexibility allows a short script to be passed on the
command line but, unless the question requires it, a perl -e "script"
solution is an ugly way to express a solution. In particular it does not
allow us to insist on the mandatory
use strict;
use warnings;
header, and the consequent declaration of lexical variables.
Rob
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/