in reply to Re: Functions in Perl
in thread Functions in Perl

Yikes! OOP is overkill here. This is all you need:
sub printargs { my $i = 1; printf "%d %s\n", $i++, $_ foreach @_; }

Replies are listed 'Best First'.
Re: Re: Functions in Perl
by ihb (Deacon) on May 26, 2004 at 04:45 UTC

    That doesn't do what Gunth's OO code does. His code makes an object that holds the counter that keeps increasing for every call to &print. So the second time it continues where it stopped the first time. Your code has the equivalent result of throwing away the object after each use, i.e. Example::->new->(...).

    My closure example below shows the equivalent of the OO example.

    ihb