in reply to Subroutines vs Modules

After reading all of these helpful replies, I decided to try out a subroutine and attempt to better understand the syntax by adding comment:
#! /usr/bin/perl -w sub of_all_things { print "You called me!\n"; #will print this when called $one*$two; #Here are the workings that will return value } $one = 12; $two = 10; $three=&of_all_things; #return value $four=2*$three; #using the return value print "2 x 120 = $four\n";

OUTPUT:
You called me! 2 x 120 = 240

This seems to work out on my box, but I am most concerned as to whether my comments are aiming at in the right direction?


Es gibt mehr im Leben als Bücher, weißt du. Aber nicht viel mehr. - (Die Smiths)"

Replies are listed 'Best First'.
Re^2: Subroutines vs Modules
by Argel (Prior) on Dec 30, 2005 at 21:22 UTC
    That works but better practice (i.e. coding style, etc.) would be:
    #! /usr/bin/perl use strict; use warnings; #//////////////////////////////////////// sub whoami { print "Just entered subroutine ", (caller(1))[3], "\n"; return; } #//////////////////////////////////////// sub one_times_two { whoami(); my( $one, $two ) = @_; return $one * $two; } #//////////////////////////////////////// my $one = 12; my $two = 10; my $three = one_times_two( $one, $two ); my $four = 2 * $three; print "2 x $three = $four\n"; exit 0;
    With output:
    Just entered subroutine main::one_times_two 2 x 120 = 240
    Note: I beleive you need Perl 5.6 or greater for "use warnings".

    -- Argel