in reply to I'm getting some weird error

&$myFunction->();

That should be written as:

$myFunction->(@_);

Replies are listed 'Best First'.
Re^2: I'm getting some weird error
by harangzsolt33 (Deacon) on Dec 05, 2018 at 07:49 UTC
    Thank you! Yes, that works now. But I don't understand why mine didn't work. It was saying
    printList was called. Hey, I am from Italy! 1 2 3 4 Can't use string ("1") as a subroutine ref while "strict refs" in use +at C:\DESKTOP\test.pl line 16. Press any key to continue . . .

    I wasn't trying to use "1" as a sub ref. What is that all about???

      You called your subroutine, and then tried to call its result again, as a subroutine:

      &$subref; # this calls the subroutine &$subref->(); # this calls the subroutine and tries to call the result + again, as a subroutine

      Using & is a bad idea in most cases.

      Perl offers two ways to dereference (most) datatypes.
      • with the right sigil like &$code_ref(ARGS)
      • with a deref arrow + bracket $code_ref->(ARGS)
      Same for hashes and arrays.

      You mixed both (and Corion explained what happend)

      See perlreftut and References quick reference for more.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice