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

Re^2: Idiomatic Perl?

by hippo (Bishop)
on Mar 20, 2018 at 16:34 UTC ( [id://1211351]=note: print w/replies, xml ) Need Help??


in reply to Re: Idiomatic Perl?
in thread Idiomatic Perl?

my $answer = ($str =~ /$pattern/); if ($answer) { print "Yes!"; } else { print "No."; }

I think the ternary here would be even more idiomatic. You can replace those 6 lines with just one:

print $str =~ /$pattern/ ? "Yes!" : "No.";

Log In?
Username:
Password:

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

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

    No recent polls found