in reply to Dereferencing code refs with & vs. ->()

To address the actual question, the advantage of using $ref -> () instead of &$ref() is that the former obeys the strict references pragma and the latter will generate an error when using strict references.
  • Comment on Re: Dereferencing code refs with & vs. ->()

Replies are listed 'Best First'.
Re^2: Dereferencing code refs with & vs. ->()
by Moron (Curate) on Sep 23, 2005 at 09:11 UTC
    (oops forgot to log in when posting the above)

    Update: Actually it is more complicated than that - I should have inserted a qualifying clause rather than implying this is true for all cases, but alas I did not post it under this account and can't update it anymore.

    -M

    Free your mind

Re^2: Dereferencing code refs with & vs. ->()
by Anonymous Monk on Sep 23, 2005 at 09:44 UTC
    Bullshit.
    #!/usr/bin/perl use strict; use warnings; my $ref = sub {print "Hello, world\n"}; $ref->(); &$ref(); # Look ma, I am using strict! __END__ Hello, world Hello, world
    But:
    #!/usr/bin/perl use strict; use warnings; sub hello {print "Hello, world\n"}; my $ref = "hello"; $ref->(); __END__ Can't use string ("hello") as a subroutine ref while "strict refs" in +use

      Maybe you could have said something more civil than "bullshit"? Politeness is free, and the payback is large, try it, you might like it.

      ---
      $world=~s/war/peace/g

      A reply falls below the community's threshold of quality. You may see it by logging in.