> True, but irrelevant. What makes them global is that they can be accessed from anywhere.

All package variables can be accessed everywhere. As I said

> > This means that package vars can be manipulated outside the sub.

> your example of a global variable uses our, which creates a lexically-scoped variable.

Now this is indeed "irrelevant". They create a lexical alias to a package var.

They are still globally accessible via full-qualified name.

> And did you read the page?

I even cited the original sources.

Anyway ...

... my original question wasn't answered, if "a function using global variables (which are "non local") is a closure"

Given that the original sources talk about binding "free variables" which are "bound" I tend to say "kind of". They are bound in the Perl's Op-Tree to their symbol table entry.

But a (the?) central idea of closures is that of encapsulation and protection of those variables from external manipulations and other side effects. And this is not given with with package variables.

A way out of this conundrum is to realize that Perl is not Lisp, and that "Closure" in Perl's context is a short for "lexical closure".

Let's have a look what Larry says in Perl Glossary

I disagree about the "anonymous", a closure doesn't loose it's features if we name it a posteriori like with *name = $sub_ref

But this definition is certainly stressing the "lexical" character of closures, with variables which survive even out-of-scope.

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


In reply to Re^7: Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube by LanX
in thread Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.