Hi friends! In our last blog learning session, we grabbed
some knowledge about the flow of control in PERL programming by using ‘if-else’
statements. Let us understand today these ‘if-else’ statements by means of some
examples.
Consider you are asked to build a program which can classify
the customers in a bank as premium, important and regular customer on the basis
of the balance they have in their bank accounts. Classification is to be made
like this:
“those customers with amount deposited over $1,000,000
are to be treated as premium; those having amount deposited between $500,000
and $1,000,000 are to be treated as important customer; and finally, those
left, i.e., customers with deposits below $500,000 are to be treated as regular
customers.”
This problem can be converted into a PERL program which
can be used to distinguish the various classes of customers. Let us see how it
is done:
if ($balance > 1000000)
{
print “\nPremium Customer.”;
}
elsif ($balance > 500000)
{
print “\nImportant Customer.”;
}
else
{
Print “\nRegular Customer.”;
}
In the program illustrated above, the flow is designed in
such a way that there is the need of only one condition to be specified in the
body of execution. ‘Body of Execution’ is the block below each condition, it is
included in the curly-brackets ( { <body> } ).
One more thing to notice here is that we do not put
terminator (;) after the if or elsif or else statement. It is because the
statement as a whole does not terminates at the same line, if found correct, it’s
body will be executed, which is in the next line starting with ‘{‘ and ending
with ‘}’. It is a common mistake to put terminator after the flow statement.
One more that I want to discuss today is the use of
comments in our programs. Suppose you are working on a big-big and complex
program which uses various formulae and statements. It is a usual thing that
you may not be able to grasp your own coding if viewed later. So, to keep our
program meaningful to us and to other programmers, we use some statements which
help us in grabbing the idea about our program. These statements are completely
ignored by the PERL interpreter.
In PERL, comments begin with ‘#’ symbol. In other words,
if you put ‘#’ in a line, all the characters after become invisible to
interpreter. Let us re-write the above program using comments to make it more
illustrative.
if ($balance > 1000000)
# first condition
{
print “\nPremium Customer.”; #
Body of first condition
}
elsif ($balance > 500000)
# second condition
{
print “\nImportant Customer.”;
# Body of second condition
}
Else # Final condition
{
Print “\nRegular Customer.”; # Body
of final condition
}
This concludes today’s learning session on PERL learning
blog. Hope you are finding these learning sessions interesting and easy to
understand.
With Warm Regards,
Yajur Kumar
(PERL Programming Expert)
Yajur Kumar
(PERL Programming Expert)
Thank you friend! Due to busy schedule I was unable to update my blog. But, now I've got some free-time, and promise to update my this learning blog very soon.
ReplyDeleteThank you for bookmarking!
ReplyDeleteNice blog! Thanks for sharing this valuable information
Angularjs Training in Bangalore
Angularjs classes in pune
Angularjs Training in hyderabad
Angularjs Training in Gurgaon
Angularjs Training in delhi
Thanks for sharing this wonderful information. I too learn something new from your post..
ReplyDeleteInformatica Training in Chennai
Informatica Training in Bangalore
Informatica Course in Chennai
Informatica Course in Bangalore
Informatica Training Institute in Chennai
Informatica Training Institutes in Bangalore
Informatica ETL Tool
Data integration
ETL Tool
ReplyDeleteGet inspired by your blog. Keep doing like this....
Spoken English Classes in Bangalore
Spoken English Classes in Pune
spoken english centre in Hyderabad
English Speaking Course in Gurgaon
English speaking course in Delhi
ReplyDeleteGreat post. keep sharing such a worthy information
cyber security course in bangalore
cyber security training in chennai
perfect and excellent thoughts, thanks for sharing your knowledge
ReplyDeleteInplant Training In Chennai
Inplant Course In Chennai
ReplyDeleteThis blog gives me some valuable information,thanks a lot.
Oracle Certification in Chennai
oracle certification courses online
oracle course in Coimbatore
Mindblowing blog very useful thanks
ReplyDeleteSoftware testing training in OMR
Software testing training in chennai
This post is so attractive and informative.keep updating more information...
ReplyDeleteFull Stack Developer Training In Mumbai
Full Stack Developer Training In Ahmedabad
Full Stack Developer Training In Kochi
Full Stack Developer Training In Trivandrum
Full Stack Development Course In Kolkata
ReplyDeleteThank you, This was the best and most interesting course. please continue to share your thoughts.
RPA Course in Chennai
RPA Online Course
RPA Course In Bangalore
ReplyDeleteNice post Thank for sharing
DevOps Online Training
DevOps Training in Chennai
DevOps Training in Bangalore