$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.

Regards,
Emeka

On Tue, Aug 30, 2011 at 4:30 PM, Rob Dixon <rob.di...@gmx.com> wrote:

> On 30/08/2011 16:02, Shawn H Corey wrote:
>
>> On 11-08-30 05:38 AM, Narasimha Madineedi wrote:
>>
>>> Hi all,
>>>
>>> I have a string like *"abcd efgh ijkl mnop"* i want to reverse the
>>> string like this "*dcba hgfe lkji ponm*"
>>>
>>> can any one tell me how to get the required output? thanks in
>>> advance......
>>>
>>>
>> perl -e'@words=split/\s+/,$ARGV[0];**$_=reverse$_
>> for@words;print"@words\n";' 'abcd efgh ijkl mnop'
>>
>
> Please remember that the default parameters for 'split' are almost
> always what is required. Splitting on /\s+/ is almost the same, but will
> return an empty initial field if the object string has leading
> whitespace. perldoc -f split says this:
>
>  As a special case, specifying a PATTERN of space (' ') will split on
>> white space just as "split" with no arguments does. ... A "split" on
>> "/\s+/" is like a "split(' ')" except that any leading whitespace
>> produces a null first field. A "split" with no arguments really does
>> a "split(' ', $_)" internally.
>>
>
> So to extract all non-whitespace substrings from $ARGV[0] you should write
>
>  split ' ', $string;
>
>
> Rob
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 
*Satajanus  Nig. Ltd


*

Reply via email to