Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: how to print only 47 and another number will rejected and when user give 47 that number only print ?

by marto (Cardinal)
on Dec 10, 2013 at 15:02 UTC ( [id://1066442]=note: print w/replies, xml ) Need Help??


in reply to how to print only 47 and another number will rejected and when user give 47 that number only print ?

#!/usr/bin/perl use strict; use warnings; print "Enter a number:"; my $input = <STDIN>; chomp $input; print "47\n" if ( $input == 47 );

This probably isn't what you want, I can't tell exactly what you're looking for based on what you've asked here and in the CB. This sounds like a homework assignment, I suspect the best course of action would be to study your notes, speak to your tutor or other students. See also How do I post a question effectively?.

  • Comment on Re: how to print only 47 and another number will rejected and when user give 47 that number only print ?
  • Download Code

Replies are listed 'Best First'.
OT: TOO COMPLEX! (Was Re^2: how to print only 47 and another number...)
by roboticus (Chancellor) on Dec 10, 2013 at 18:05 UTC

    marto:

    OVERLY COMPLEX! I think you could have simplified it to[1]:

    #!/usr/bin/perl use strict; use warnings; print "Enter a number:"; my $input = <STDIN>; print "47\n";

    In fact, when I read your response, I was transported back in time to high school. My friends and I formed a small informal computer club where we each created programs for the amusement of others. My friend Tony created "Super Star Trek 4.71" which amused the hell out of me. I no longer have the source code to it, as little output from the TTY[2] still lingers at the house. But a close approximation in perl[3] would be like:

    #!/usr/bin/perl use strict; use warnings; use Time::HiRes 'usleep'; $|=1; my $A; sub PR1NT { my $msg = shift; my @chars = split //,$msg; while (defined(my $t = shift @chars)) { usleep 100000; print $t; } } sub INPUT { print "? "; my $a = <>; return $a; } L0010: PR1NT "WELCOME TO SUPER STAR TREK VERSION 4.71\n"; L0015: PR1NT "\n"; L0020: PR1NT "A SPACE ADVENTURE SURE TO THRILL THE SOUL!\n"; L0030: PR1NT "COPYRIGHT 1979 BY ANTHONY D. ENNIS\n"; L0040: PR1NT "\n"; L0050: PR1NT "WOULD YOU LIKE INSTRUCTIONS"; L0060: $A = INPUT(); L0070: PR1NT "\n"; L0080: PR1NT "WHAT IS YOUR FAVORITE NUMBER"; L0090: $A = INPUT(); L0100: PR1NT "YOU WIN!!!!\n"; L0110: PR1NT "\n"; L0120: PR1NT "WOULD YOU LIKE TO PLAY AGAIN"; L0130: $A = INPUT(); L0140: PR1NT "\n"; L0150: goto L0010;

    Notes:

    [1] I could've left out the use warnings/errors boilerplate, but we wouldn't want to give people bad habits, would we?

    [2] Last year at about this time, I dug up a printout of his D&D program from the same era and gave it to him. Now he has an Android version on his phone. He needs to give me a copy of it! I hate to think of how many rolls of paper our computer club wasted on that game. ;^)

    [3] Yep, I actually wasted 15 minutes of my life recreating Tony's joke game.

    The rendition of his game here is from memory, so it's obviously not exactly the same. But I'm sure it's not far from the mark!

    Update: I forgot the "just kidding" note. This was just a joke response because marto triggered an ancient memory.

    Update: Had some "junk" in the star trek program, now removed. (Looks like I pasted a copy of the first code snippet into the second one.) Thanks to N-Wing for catching it! Also made a couple tweaks to make it a little closer to the original.

    Late update: (Late==2018-06-07) I forgot to mention that the original program was in BASIC. (Our high school club was based on a time-share account on an HP-2000 with their version of BASIC. Obviously, I perlified it a bit...)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1066442]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-16 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found