Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: STDIN method?

by janx (Monk)
on Oct 17, 2002 at 20:42 UTC ( [id://206139]=note: print w/replies, xml ) Need Help??


in reply to STDIN method?

No, sorry. There is no built-in case/switch statement (yet - in Perl 6 there will be, it's called given).
If you don't mind source filters though, there is the excellent module Switch.pm by Damian Conway.

Otherwise you will have to use if/elsif statements.

Be aware:

> $choice=<STDIN>; > if ($choice="1") { > $choice="Turkey"; > } > else choice="2"...etx
= assigns, it does not compare!
Use eq for string comparison (or == for a numeric one).

janx

Log In?
Username:
Password:

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

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

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.