in reply to Quick question on a Perl Code!

Those aren't arguments, they're prototypes

perldoc -f sub

sub NAME BLOCK
sub NAME (PROTO) BLOCK
sub NAME : ATTRS BLOCK
sub NAME (PROTO) : ATTRS BLOCK
        This is subroutine definition, not a real function *per se*.
        Without a BLOCK it's just a forward declaration. Without a NAME,
        it's an anonymous function declaration, and does actually return
        a value: the CODE ref of the closure you just created.

        See perlsub and perlref for details about subroutines and
        references, and attributes and Attribute::Handlers for more
        information about attributes.

Replies are listed 'Best First'.
Re^2: Quick question on a Perl Code!
by dudydude (Novice) on Jul 13, 2011 at 22:51 UTC

    They are subroutines, I just didn't bother to copy and paste the whole code

      Reread what he said.

      Arguments are what you pass to a subroutine. They're not being passed to the subroutine as you said. They're part of the subroutine's declaration.

      I'll elaborate
      sub fudge($){ print @_ }
      that is a function declaration -- it doesn't print anything
      fudge(1); fudge 2;
      those are function calls, it prints 1 then prints 2

      If you wrote

      fudge 1,2;
      the prototype ($) ensures fudge only gets 1 argument

      If you try to force the issue with

      fudge(1,2);
      You'll get an error
      $ perl -le " sub fudge($){print @_} fudge(1,2); Too many arguments for main::fudge at -e line 1, near "2)" Execution of -e aborted due to compilation errors.
      Next time, when you get links, follow them, read them, its what we all do :)

        Thanks, I am a newbie just a week programming with Perl and some stuff are still confusing to me! THANKS :o)