Gossamer Forum
Home : General : Perl Programming :

Perl Test

(Page 1 of 2)
> >
Quote Reply
Perl Test
Ok this is just a quick thing I was playing with...

I have the following:

local $_ = '? it do you Can . ordering needs that message up mixed a is This';

Is anyone up for getting it to read:

This is a mixed up message that needs ordering. Can you do it?

....in the least amount of code?...this is a pretty easy one but I challenged Drew :)
Quote Reply
Re: [Paul] Perl Test In reply to
In the final text, do you want the space before the dot and the question mark or not?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Perl Test In reply to
Nope. The one after/before the . is ok but not the ?

FWIW I did it in 22 characters including the print and ;

Last edited by:

Paul: May 1, 2002, 5:36 AM
Quote Reply
Re: [Paul] Perl Test In reply to
Oops sorry let me rephrase that...there is a typo in the code above which adds an extra space before the dot. You can delete that and then no, no spaces are allowed.

So:

Can .

Should be:

Can.

Last edited by:

Paul: May 1, 2002, 5:39 AM
Quote Reply
Re: [Paul] Perl Test In reply to
print reverse $_;

?

- wil
Quote Reply
Re: [Wil] Perl Test In reply to
No that is wrong - it won't change anything :) ...it will print the original sentence.

Last edited by:

Paul: May 1, 2002, 5:45 AM
Quote Reply
Re: [Paul] Perl Test In reply to
Complete guess...but may work Tongue

@split = split(" ", $_);
reverse @split;
foreach (@split) { print $_ }

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Paul] Perl Test In reply to
print scalar reverse <$_>;

Or something silly like that <g>.

- wil
Quote Reply
Re: [Andy.] Perl Test In reply to
Remember your target is 22 characters, you aren't writing an essay Angelic

But in any case yours prints:

?itdoyouCan.orderingneedsthatmessageupmixedaisThis

Last edited by:

Paul: May 1, 2002, 5:49 AM
Quote Reply
Re: [Wil] Perl Test In reply to
Nope that prints:

sihT si a dexim pu egassem taht sdeen gniredro .naC uoy od ti ?

...and without the <> is the same.
Quote Reply
Re: [Paul] Perl Test In reply to
all I can get is:
Code:
print join " ", reverse split / /;

--Philip
Links 2.0 moderator
Quote Reply
Re: [sponge] Perl Test In reply to
Aww you are so close...keep going :)

A really simple change can let you remove the join.

Last edited by:

Paul: May 1, 2002, 5:54 AM
Quote Reply
Re: [Paul] Perl Test In reply to
Code:
$,=' ';print reverse split;
but still too long...

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Perl Test In reply to
Ahh you fell into Drews trap...look closely at what it prints...it isn't actually right.

This is a mixed up message that needs ordering Can. you do it ?

Edit: Ok Drew was using the original code as he didn't see the change in post 4...did you miss that too?

Last edited by:

Paul: May 1, 2002, 6:12 AM
Quote Reply
Re: [Paul] Perl Test In reply to
Yes, I missed that..... I'm trying....

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Perl Test In reply to
The space after the dot is ok in the final answer as that is good grammar anyway :)

eg....

It should look like:

This is a mixed up message that needs ordering. Can you do it?
Quote Reply
Re: [Paul] Perl Test In reply to
print reverse split / /;

- wil
Quote Reply
Re: [Wil] Perl Test In reply to
Test em out first you'd save yourself time :) ....no it doesn't work.

Edit: (Close though).

Last edited by:

Paul: May 1, 2002, 6:42 AM
Quote Reply
Re: [Paul] Perl Test In reply to
Code:
print reverse split/\b/;
sort of...

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Perl Test In reply to
Yay you got it :)

Why did you say "sort of" ?

Last edited by:

Paul: May 1, 2002, 7:13 AM
Quote Reply
Re: [Paul] Perl Test In reply to
That's 24 characters my dear. You said you had 22.... gives us your answer!

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Perl Test In reply to
I didn't include whitespace in my count.

Last edited by:

Paul: May 1, 2002, 7:14 AM
Quote Reply
Re: [Paul] Perl Test In reply to
OK.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Perl Test In reply to
Out of interest, how did you end up with it?....trial and error?
Quote Reply
Re: [Paul] Perl Test In reply to
Yes, and http://www.perldoc.com/....6.1/pod/perlre.html

Ivan
-----
Iyengar Yoga Resources / GT Plugins
> >