in reply to Re^7: Access a global variable from a subroutine when used as "for" iterator
in thread Access a global variable from a subroutine when used as "for" iterator

Perl has two different kinds of variables, private variables declared with my and package variables (usually) declared with our

for sources, e.g. "Scoping" see

Update

And an excellent overview can be found in

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

  • Comment on Re^8: Access a global variable from a subroutine when used as "for" iterator (updated)
  • Select or Download Code

Replies are listed 'Best First'.
Re^9: Access a global variable from a subroutine when used as "for" iterator
by hippo (Archbishop) on Dec 22, 2023 at 08:45 UTC

    Well that's confusing. Aren't these self-contradictory?

    • main:: and other package s are namespaces not scopes ...
    • variables do not belong to namespaces
    • special variables always belong to main::

    I can't reconcile these 3 statements, sorry.

    Post-update: reads much better now, thanks.


    🦛

      Hi

      Thanks corrected, somehow the "my" got lost

      > > my variables do not belong to namespaces

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery