So I was wondering if there is a difference in use between a Perl class method and a regular routine from a standard module. Is there a time when you will use one over the other? In this example, I assume that no object methods are present in any of the modules.
A quick little main class here:
#!/usr/local/bin/perl use strict; use warnings; use Foo; use Bar; my $arg1 = "blah"; my ($str1, $str2); $str1 = Foo::subroutine($arg1); $str2 = Bar->subroutine($arg1); exit(0);
Foo package will contain my regular routine call
use strict; use warnings; package Foo; sub subroutine { my $arg = shift; my $string = "Ordinary subroutine arg is $arg\n"; return $string; } 1;
The batch panel will contain a class method call
use strict; use warnings; package Bar; sub subroutine { my $class = shift; my $arg = shift; my $string = "Class method arg is $arg\n"; return $string; } 1;
Usually, if I write Perl code, I would just use the class method parameter (for example, the Bar example), but I began to reflect on this issue after reading the code from a former employee who used the syntax, as in the Foo example. Both seem to do the same in their essence, but seem to do more than they seem at first glance.
source share