in reply to Re: Common Beginner Mistakes
in thread Common Beginner Mistakes
One could write many variations on the theme:#! /usr/local/bin/perl use strict; sub print_percentage { my ($total, $part) = @_; if (int($total) != 0){ printf ("It's about %.2f%%\n", $part/$total *100.); } else{ print "Bad usage: $total == 0!!! Cannot divide by '$total'.\n" +; } } print_percentage(100, 50); print_percentage("oops", 50); ;1
#! /usr/local/bin/perl use strict; if ("38" == 38){ print "hit the jackpot!\n"; } else { print "hit elsewhere....\n"; } ;1
|
---|