Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Interactive Perl script

by Utilitarian (Vicar)
on Aug 27, 2009 at 15:54 UTC ( [id://791697]=note: print w/replies, xml ) Need Help??


in reply to Interactive Perl script

Okay as a fellow Irish Arsenal fan I'll help, but really you should show what you have tried as this site is for those interested in learning Perl rather than those interested in getting code for free</rant>
#!/usr/bin/perl use strict; use warnings; sub confirm{ my $question=shift; my $reply = ""; print "$question (y/n)?"; while ($reply !~ m/^[yn]/i){ # allow for pedants who reply "yes" or + "now" chomp($reply=<STDIN>); } return $reply=~m/^y/i ? 1 : undef; } print confirm("can you write device drivers")?"wow, you must be very s +killed\n":"neither can i, i am just shell script\n";
BTW: the Dublin Perl mongers group is holding a re-inauguration at OSBarCamp, feel free to come along.

Replies are listed 'Best First'.
Re^2: Interactive Perl script
by Irishboy24 (Sexton) on Aug 27, 2009 at 16:02 UTC

    Hey, Thank you very much. your response was really helpful. appreciate your help. BTW i am Indian, i just like the way the Irish drink and am a very very big fan of Arsenal. cheers for your reply!! thanks! Go Gunners

      Ahh, you probably won't be in Dublin for OSBarCamp so.
      While my script answers your immediate question, the point of it was to understand all the elements within it.
      • use strict and warnings, seems a pain at first but it will do 70% of your debugging
      • When you have something like a confirmation dialog make a routine out of it, because you'll need to do it again. These routines can ultimately be built up into your own modules which take the drudgery out of development
      • The ternary operator is quite useful(<condition>?true:false;)
      • But as has been said above, in order to learn you have to make your own mistakes and the satisfaction of solving a puzzle is a great memory enforcement
      BTW: Arshavin, brilliant or what ;)

Log In?
Username:
Password:

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

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

    No recent polls found