in reply to Re^10: Thx, St. Larry, for the Beauty of Sigils
in thread Thx, St. Larry, for the Beauty of Sigils

I have trouble calling something "anonymous" which is accessible by a named variable.

perlglossary states

anonymous

Used to describe a referent that is not directly accessible through a named variable. Such a referent must be indirectly accessible through at least one hard reference. When the last hard reference goes away, the anonymous referent is destroyed without pity.

But I just recalled that Perl tends to use the label "__ANON__" for subs which were not bound to a package at creation time (i.e. created the usual way with sub name {} )

DB<22> use Carp qw/confess/ DB<23> $inner = sub { confess "INNER" } DB<24> sub outer { $inner->() } DB<25> outer() INNER at (eval 32)[C:/Perl_524/lib/perl5db.pl:737] line 2. main::__ANON__[(eval 32)[C:/Perl_524/lib/perl5db.pl:737]:2]() +called at (eval 33)[C:/Perl_524/lib/perl5db.pl:737] line 2 main::outer() called at (eval 34)[C:/Perl_524/lib/perl5db.pl:7 +37] line 2 ... #shortened outer(); ... #shortened DB<26> *inner = $inner DB<27> inner() INNER at (eval 32)[C:/Perl_524/lib/perl5db.pl:737] line 2. main::__ANON__[(eval 32)[C:/Perl_524/lib/perl5db.pl:737]:2]() +called at (eval 36)[C:/Perl_524/lib/perl5db.pl:737] line 2 ... #shortened inner(); ... #shortened

I think this is a confusing terminology which might have made sense in the time of Perl4.

But I see your point now.

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

PS: Would be interesting to know if lexical subs are handled correctly here. (UPDATE: yes they are)

Replies are listed 'Best First'.
Re^12: Thx, St. Larry, for the Beauty of Sigils
by shmem (Chancellor) on Jul 28, 2019 at 10:46 UTC
    I think this is a confusing terminology which might have made sense in the time of Perl4.

    perl 4 did not have references at all. Back in those days building structures, e.g. multilevel hashes, was cumbersome. One leftover of these days is the global $SUBSEP or $; (see perlvar). References were introduced with perl5.0 which was a big step forward.

    update

    Regarding the block you quote from perlglossary - that's why I said To get hold of an anonymous variable beyond a single statement, its reference has to be stored in a named scalar variable..

    What the paragraph doesn't mention is that anonymous variables which are created but not stored somewhere keep hanging around, unaccessible, until their scope ends, i.e. their reference count is increased at creation time. Consider:

    use 5.10.0; $| = 1; # make a scalar reference (blessed for DESTROY to be triggered) say bless \do { my $x }; # anonymous scalar gone? nope! say "done"; sub DESTROY { warn "destroying $_[0]\n"; } __END__ main=SCALAR(0x55f1ce2d6450) done destroying main=SCALAR(0x55f1ce2d6450)

    versus

    use 5.10.0; $| = 1; { # make a scalar reference (blessed for DESTROY to be triggered) say bless \do { my $x }; } # anonymous scalar gone! say "done"; sub DESTROY { warn "destroying $_[0]\n"; } __END__ main=SCALAR(0x563bee102450) destroying main=SCALAR(0x563bee102450) done

    This is arguably a bug.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'