in reply to differences between ways of calling subroutines

If you use &, then you're bypassing any prototyping that might have been set up for the function. If there's no prototyping, then there's no difference. :)

------
/me wants to be the brightest bulb in the chandelier!

Replies are listed 'Best First'.
Re: Re: subroutine call
by arturo (Vicar) on Aug 03, 2001 at 21:38 UTC

    You can also "override"1 a builtin with the &foo() syntax. You can also pass your current @_ through with it, if you leave off the parens.

    sub time { print "Is on my side\n"; print &bar, "\n"; } sub bar { my ($baz) = @_; uc $baz; } &time('yes it is'); # prints 'Is on my side', a newline, followed by ' +YES IT IS'

    HTH

    1 OK, maybe it's not truly overriding, because of the special syntax you have to use to call it.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
      thanks
Re: Re: subroutine call
by Anonymous Monk on Aug 03, 2001 at 21:26 UTC
      &foo;

      will call your subroutine with the @_ array set to the arguments of the caller.

      an example

      bar("a","b"); sub bar { foo(); &foo(); &foo; } sub foo { ($a, $b)=@_; print "$a, $b\n"; }
      the call to bar will now print
      ,
      ,
      a, b
      
      Try doing a search on prototyping. Or, you could just click on prototyping, which will end up doing the same thing, eventually. :)

      ------
      /me wants to be the brightest bulb in the chandelier!