On Sun, Oct 27, 2013 at 03:27:49PM +0100, Dr.Ruud wrote: > On 2013-10-27 04:00, Mayuresh Kathe wrote: > > >#!/usr/bin/perl -w > > > >use strict; > >use warnings; > > > >my $exponent = $ARGV[0]; > >my $number = 2; > >my $result = $number; > > > >if ( not defined $exponent ) { > > die "Usage: $0 <exponent>\n"; > >} > > You have a die() there, so no indent needed. Alternative: > > # assertions > defined $exponent > or die "Usage: $0 <exponent>\n"; > > > >else { > > for ( my $count = 1 ; $count < $exponent ; $count++ ) { > > $result = $result * $number; > > } > > print "$result\n"; > >} > > > >exit(0); > >---------------------------------------------------------------------- > > The code would then look more like: > > #!/usr/bin/perl > use strict; > use warnings; > > my $exponent = $ARGV[0]; > my $number = 2; > my $result = $number; > > # assertions > defined $exponent > or die "Usage: $0 <exponent>\n"; > > $result *= $number for 2 .. $exponent; > > print "$result\n"; > > __END__ > > The code acts funny with exponents <= 0, or (for example) 1.5. > > See also perlop, about the ** operator.
Thanks for the tip Dr. Ruud, but, I've still not reached that level of Perl programming maturity to run with such stuff... :) I'll get there eventually, that's for sure. Best, ~Mayuresh -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/