Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Quick syntax error in 13 lines of code

by Anonymous Monk
on Sep 30, 2011 at 14:09 UTC ( [id://928816]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Can someone help me fix the syntax error in the below code? This is my first time using given/when and it just says syntax error hear ") and syntax error near ") {" which makes no sense to me.
while(1) { print "input: "; my $in = <STDIN>; chomp($in); given($in) { when (/l/) { print "\nlegs"; } when (/h/) { print "\nhead"; } when (/b/) { print "\nbody"; } when (/s/) { print "\nspecial"; } } }

Replies are listed 'Best First'.
Re: Quick syntax error in 13 lines of code
by toolic (Bishop) on Sep 30, 2011 at 14:15 UTC
Re: Quick syntax error in 13 lines of code
by GrandFather (Saint) on Oct 01, 2011 at 03:19 UTC

    You have to turn on new features in Perl 5.10. Toolic indicated one way. Another way is to turn on all the 5.10 features so the usual strictures boilerplate extends to include use 5.010;:

    use strict; use warnings; use 5.010; while (1) { print "input: "; my $in = <STDIN>; chomp ($in); given ($in) { when (/l/) {print "\nlegs";} when (/h/) {print "\nhead";} when (/b/) {print "\nbody";} when (/s/) {print "\nspecial";} } }
    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://928816]
Approved by toolic
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-26 08:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found