CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Perl operator 'x'

 



rajshah13
New User

Nov 19, 2012, 5:55 PM

Post #1 of 8 (2198 views)
Perl operator 'x' Can't Post

how can i produce and print the line: '666:666:666:god help us!'
without printing any number 6 and with only one : with perl script ?


FishMonger
Veteran / Moderator

Nov 20, 2012, 6:41 AM

Post #2 of 8 (2196 views)
Re: [rajshah13] Perl operator 'x' [In reply to] Can't Post

See: perldoc -f join
http://perldoc.perl.org/functions/join.html


Laurent_R
Veteran / Moderator

Nov 20, 2012, 10:16 AM

Post #3 of 8 (2192 views)
Re: [rajshah13] Perl operator 'x' [In reply to] Can't Post

An example not even using 6:


Code
my $nb = 777 - 111; 
my $line = $nb . ":";
$line = $line x 3;
$line = $line . "God";


;-)


(This post was edited by Laurent_R on Nov 20, 2012, 10:32 AM)


FishMonger
Veteran / Moderator

Nov 20, 2012, 10:47 AM

Post #4 of 8 (2187 views)
Re: [Laurent_R] Perl operator 'x' [In reply to] Can't Post

I was holding off providing a solution because this is clearly a homework assignment where the OP hasn't shown any attempt.

Since "the cat's out of the bag", I'll show one anyway.


Code
print join ':', (555+111) x 3, 'god help us!';



(This post was edited by FishMonger on Nov 20, 2012, 10:48 AM)


Laurent_R
Veteran / Moderator

Nov 20, 2012, 2:06 PM

Post #5 of 8 (2178 views)
Re: [FishMonger] Perl operator 'x' [In reply to] Can't Post

Yeah, I did not think about possible homework, but now that you say it, it is fairly clear.

At the same time, the solution I suggested does work, but was not meant to be very serious, but more as a clue on how it could be done. I realize now that it can be used as an answer to an assignment, even though there could be better ones. For one, the x operator could be better used, but I won't say more.


rovf
Veteran

Nov 21, 2012, 1:31 AM

Post #6 of 8 (2164 views)
Re: [FishMonger] Perl operator 'x' [In reply to] Can't Post

This doesn't fulfil the OPs specification. Note that the problem spec says:


Quote
... without printing any number 6


Your code doesn't use the number 6, but certainly prints it.

I think it is very hard to print 666 without printing a 6. Maybe a solution would be to do a print 999 and ask the user to turn the monitor upside down....


FishMonger
Veteran / Moderator

Nov 21, 2012, 8:17 AM

Post #7 of 8 (2157 views)
Re: [rovf] Perl operator 'x' [In reply to] Can't Post


Quote
I think it is very hard to print 666 without printing a 6. Maybe a solution would be to do a print 999 and ask the user to turn the monitor upside down....


I like that idea. :o)


Laurent_R
Veteran / Moderator

Nov 21, 2012, 10:18 AM

Post #8 of 8 (2153 views)
Re: [rovf] Perl operator 'x' [In reply to] Can't Post

Well, yes, I noticed that, but I took it to mean without using 6 in the program. It does not make much sense otherwise.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives