[33103] in Perl-Users-Digest
Perl-Users Digest, Issue: 4379 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 26 03:09:20 2015
Date: Thu, 26 Feb 2015 00:09:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 26 Feb 2015 Volume: 11 Number: 4379
Today's topics:
del old files and empty dirs <gravitalsun@hotmail.foo>
Re: del old files and empty dirs <m@rtij.nl.invlalid>
Re: del old files and empty dirs <rweikusat@mobileactivedefense.com>
Re: del old files and empty dirs <gravitalsun@hotmail.foo>
Re: del old files and empty dirs <rweikusat@mobileactivedefense.com>
Re: del old files and empty dirs <gravitalsun@hotmail.foo>
Re: del old files and empty dirs <gravitalsun@hotmail.foo>
How does this bizarre script work? <see.my.sig@for.my.address>
Re: How does this bizarre script work? <gravitalsun@hotmail.foo>
Re: How does this bizarre script work? <gravitalsun@hotmail.foo>
Re: How does this bizarre script work? <rweikusat@mobileactivedefense.com>
Re: How does this bizarre script work? <rweikusat@mobileactivedefense.com>
Re: How does this bizarre script work? <gravitalsun@hotmail.foo>
Re: How does this bizarre script work? <see.my.sig@for.my.address>
Re: How does this bizarre script work? <see.my.sig@for.my.address>
Re: How does this bizarre script work? <bauhaus@futureapps.invalid>
Re: How does this bizarre script work? <bauhaus@futureapps.invalid>
Re: How does this bizarre script work? <m@rtij.nl.invlalid>
Re: How does this bizarre script work? <rweikusat@mobileactivedefense.com>
Re: How does this bizarre script work? <rweikusat@mobileactivedefense.com>
Re: How does this bizarre script work? <news@lawshouse.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 26 Feb 2015 00:20:52 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: del old files and empty dirs
Message-Id: <mclhs4$2l3s$1@news.ntua.gr>
This should delete files older than so much days and empty directories.
What do you think;
use File::Find;
Delete_files_older_than_days_and_empty_dirs( '/work/backup', 20);
sub Delete_files_older_than_days_and_empty_dirs
{
my $days= exists $_[1] ? $_[1]=~/^\d+$/ ? $_[1]: die "Second argument
\"$_[1]\" is not a number\n" : die "Missing second argument (days to
keep)\n";
my $dir = -d $_[0] ? $_[0] : return undef;
my @nodes;
File::Find::find({
# Delete old files
wanted=>sub {
unlink $File::Find::name if (-f $File::Find::name) && $days < -M _},
# Delete empty directories
postprocess=>sub {
return if $File::Find::dir eq $dir;
@nodes = glob "$File::Find::dir/*";
rmdir $File::Find::dir unless @nodes}
,no_chdir=>1, bydepth=>1, follow=>0}, $dir)
}
------------------------------
Date: Wed, 25 Feb 2015 23:49:36 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: del old files and empty dirs
Message-Id: <0502sb-1of.ln1@news.rtij.nl>
On Thu, 26 Feb 2015 00:20:52 +0200, George Mpouras wrote:
> This should delete files older than so much days and empty directories.
> What do you think;
It needs proper indentation before I will even look at it.
M4
------------------------------
Date: Wed, 25 Feb 2015 22:56:58 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: del old files and empty dirs
Message-Id: <87vbipeh1h.fsf@doppelsaurus.mobileactivedefense.com>
George Mpouras <gravitalsun@hotmail.foo> writes:
> This should delete files older than so much days and empty
> directories. What do you think;
>
>
> use File::Find;
> Delete_files_older_than_days_and_empty_dirs( '/work/backup', 20);
>
> sub Delete_files_older_than_days_and_empty_dirs
> {
> my $days= exists $_[1] ? $_[1]=~/^\d+$/ ? $_[1]: die "Second argument
> \"$_[1]\" is not a number\n" : die "Missing second argument (days to
> keep)\n";
> my $dir = -d $_[0] ? $_[0] : return undef;
Leaving questions about sensible style at the statement level aside, I
think subroutines shouldn't check their arguments at run time: Such
checks should be done while compiling the code and insofar the compiler
can't do enough, remaining cases of "wrong calls" should be sorted out
by debugging.
------------------------------
Date: Thu, 26 Feb 2015 01:43:18 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: del old files and empty dirs
Message-Id: <mclmmo$1s1$1@news.ntua.gr>
On 26/2/2015 12:56 πμ, Rainer Weikusat wrote:
> George Mpouras <gravitalsun@hotmail.foo> writes:
>> This should delete files older than so much days and empty
>> directories. What do you think;
>>
>>
>> use File::Find;
>> Delete_files_older_than_days_and_empty_dirs( '/work/backup', 20);
>>
>> sub Delete_files_older_than_days_and_empty_dirs
>> {
>> my $days= exists $_[1] ? $_[1]=~/^\d+$/ ? $_[1]: die "Second argument
>> \"$_[1]\" is not a number\n" : die "Missing second argument (days to
>> keep)\n";
>> my $dir = -d $_[0] ? $_[0] : return undef;
>
> Leaving questions about sensible style at the statement level aside, I
> think subroutines shouldn't check their arguments at run time: Such
> checks should be done while compiling the code and insofar the compiler
> can't do enough, remaining cases of "wrong calls" should be sorted out
> by debugging.
>
the style ? the args ? the problem is the dir double cheking to find if
it is empty.
------------------------------
Date: Wed, 25 Feb 2015 23:57:56 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: del old files and empty dirs
Message-Id: <87r3tdee7v.fsf@doppelsaurus.mobileactivedefense.com>
George Mpouras <gravitalsun@hotmail.foo> writes:
> On 26/2/2015 12:56 πμ, Rainer Weikusat wrote:
>> George Mpouras <gravitalsun@hotmail.foo> writes:
>>> This should delete files older than so much days and empty
>>> directories. What do you think;
>>>
>>>
>>> use File::Find;
>>> Delete_files_older_than_days_and_empty_dirs( '/work/backup', 20);
>>>
>>> sub Delete_files_older_than_days_and_empty_dirs
>>> {
>>> my $days= exists $_[1] ? $_[1]=~/^\d+$/ ? $_[1]: die "Second argument
>>> \"$_[1]\" is not a number\n" : die "Missing second argument (days to
>>> keep)\n";
>>> my $dir = -d $_[0] ? $_[0] : return undef;
>>
>> Leaving questions about sensible style at the statement level aside, I
>> think subroutines shouldn't check their arguments at run time: Such
>> checks should be done while compiling the code and insofar the compiler
>> can't do enough, remaining cases of "wrong calls" should be sorted out
>> by debugging.
>>
> the style ? the args ?
I figured pointing out that this is on TOCTOU race after the other, till
the very end of the subroutine, would be rather useless.
> the problem is the dir double cheking to find if it is empty.
That's useless. "The directory being empty now" doesn't mean "the
directorie's still emptyY 0.000007s from now and vice-versa. You can
just do an rmdir: If that suceeds, the directory was empty at the time
of the attempt, otherwise, it wasn't.
------------------------------
Date: Thu, 26 Feb 2015 08:50:27 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: del old files and empty dirs
Message-Id: <mcmfml$b29$1@news.ntua.gr>
On 26/2/2015 01:57, Rainer Weikusat wrote:
> directorie's still emptyY 0.000007s from now and vice-versa. You can
> just do an rmdir: If that suceeds, the directory was empty at the time
> of the attempt, otherwise, it wasn't.
>
correct but doing an rmdir in case it is not needed you have loose time
------------------------------
Date: Thu, 26 Feb 2015 09:40:03 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: del old files and empty dirs
Message-Id: <mcmijk$k6n$1@news.ntua.gr>
On 26/2/2015 01:57, Rainer Weikusat wrote:
> George Mpouras <gravitalsun@hotmail.foo> writes:
This is a much faster version, there is no more double checking per dir.
There is a an even faster approch without File::Find but have an
issue. anyway
use File::Find;
Delete_files_older_than_days_and_empty_dirs( '/logs/data/backup', 5);
sub Delete_files_older_than_days_and_empty_dirs
{
my $dir = shift;
my $days = shift;
my $clear = 1;
File::Find::find({no_chdir=>1,bydepth=>1,follow=>0,
# Delete old files
wanted=>sub {
return unless -f $File::Find::name;
$days < -M _ ? (unlink $File::Find::name):($clear=0)
},
# Delete empty directories
postprocess=>sub {
return if $File::Find::dir eq $dir;
$clear ? (rmdir $File::Find::dir):($clear=1)
}},$dir)
}
------------------------------
Date: Tue, 24 Feb 2015 12:58:01 -0800
From: Robbie Hatley <see.my.sig@for.my.address>
Subject: How does this bizarre script work?
Message-Id: <BIqdnUteFb9QeHHJnZ2dnUVZ57ydnZ2d@giganews.com>
I managed to get the bizarre script below to print
e = 2.71828
but I don't understand how it's working. The Camel Book hints
that the "constant" is actually a subroutine, but if I try to
"call" it, it fails; but if I deref with $ it succeeds. So which
"slot" of the typeglob is the ref to 2.71828 being stored in?
#! /usr/bin/perl
use v5.14;
use strict;
use warnings;
no strict "refs";
*{'main::$%^&*'} = \2.71828;
say "e = ", ${$main::{'$%^&*'}};
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley
------------------------------
Date: Tue, 24 Feb 2015 23:40:19 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: How does this bizarre script work?
Message-Id: <mcir42$2nhd$1@news.ntua.gr>
On 24/2/2015 10:58 μμ, Robbie Hatley wrote:
>
>
>
> #! /usr/bin/perl
> use v5.14;
> use strict;
> use warnings;
> no strict "refs";
> *{'main::$%^&*'} = \2.71828;
> say "e = ", ${$main::{'$%^&*'}};
>
not a big mistery !
*{'@$%^&*<'} = \3.1459;
print ${ pack 'H14','4024255e262a3c' }
------------------------------
Date: Tue, 24 Feb 2015 23:41:31 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: How does this bizarre script work?
Message-Id: <mcir6a$2nhd$2@news.ntua.gr>
its only a common string as glob reference
------------------------------
Date: Tue, 24 Feb 2015 21:46:22 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: How does this bizarre script work?
Message-Id: <87mw43ugnl.fsf@doppelsaurus.mobileactivedefense.com>
Robbie Hatley <see.my.sig@for.my.address> writes:
> I managed to get the bizarre script below to print
> e = 2.71828
> but I don't understand how it's working. The Camel Book hints
> that the "constant" is actually a subroutine, but if I try to
> "call" it, it fails; but if I deref with $ it succeeds. So which
> "slot" of the typeglob is the ref to 2.71828 being stored in?
>
> #! /usr/bin/perl
> use v5.14;
> use strict;
> use warnings;
> no strict "refs";
> *{'main::$%^&*'} = \2.71828;
> say "e = ", ${$main::{'$%^&*'}};
You aren't really creating a constant (you'd also need to do that from a
BEGIN block to enable the compiler to inline it). What you're doing is
assigned a reference to a scalar to a glob. This sets the scalar-slot of
the glob to this reference. When using the variable created in this way
later on, the value is reproduced.
Code which creates an actual constant (method poached from constant.pm)
---------
BEGIN {
$::{A} = \1.23;
}
print A;
----------
[the symbol table of a package with name Name is a hash named %Name::,
as a special-case, the symbol table of package main can also be referred
to as %::]
This A can also be called and it's expanded inline:
[rw@doppelsaurus]/tmp#perl -MO=Concise,-exec x
1 <0> enter
2 <;> nextstate(main 2 x:5) v:{
3 <0> pushmark s
4 <$> const[NV 1.23] s*
5 <@> print vK
6 <@> leave[1 ref] vKP/REFC
------------------------------
Date: Tue, 24 Feb 2015 21:50:40 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: How does this bizarre script work?
Message-Id: <87ioeruggf.fsf@doppelsaurus.mobileactivedefense.com>
George Mpouras <gravitalsun@hotmail.foo> writes:
> On 24/2/2015 10:58 μμ, Robbie Hatley wrote:
>>
>> #! /usr/bin/perl
>> use v5.14;
>> use strict;
>> use warnings;
>> no strict "refs";
>> *{'main::$%^&*'} = \2.71828;
>> say "e = ", ${$main::{'$%^&*'}};
>>
>
>
> not a big mistery !
>
>
> *{'@$%^&*<'} = \3.1459;
> print ${ pack 'H14','4024255e262a3c' }
*{"\0\0\0"} = \"\0";
print(ord(substr(${"\0\0\0"}, 0, 1)), "\n");
[SCNR]
------------------------------
Date: Wed, 25 Feb 2015 00:41:54 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: How does this bizarre script work?
Message-Id: <mciunk$78$1@news.ntua.gr>
On 24/2/2015 11:50 μμ, Rainer Weikusat wrote:
> George Mpouras <gravitalsun@hotmail.foo> writes:
>> On 24/2/2015 10:58 μμ, Robbie Hatley wrote:
>>>
>>> #! /usr/bin/perl
>>> use v5.14;
>>> use strict;
>>> use warnings;
>>> no strict "refs";
>>> *{'main::$%^&*'} = \2.71828;
>>> say "e = ", ${$main::{'$%^&*'}};
>>>
>>
>>
>> not a big mistery !
>>
>>
>> *{'@$%^&*<'} = \3.1459;
>> print ${ pack 'H14','4024255e262a3c' }
>
> *{"\0\0\0"} = \"\0";
> print(ord(substr(${"\0\0\0"}, 0, 1)), "\n");
!!
------------------------------
Date: Tue, 24 Feb 2015 21:35:20 -0800
From: Robbie Hatley <see.my.sig@for.my.address>
Subject: Re: How does this bizarre script work?
Message-Id: <a4ednVhU__KRwnDJnZ2dnUVZ572dnZ2d@giganews.com>
On 2/24/2015 1:46 PM, Rainer Weikusat wrote:
> Robbie Hatley <see.my.sig@for.my.address> writes:
>
> > #! /usr/bin/perl
> > use v5.14;
> > use strict;
> > use warnings;
> > no strict "refs";
> > *{'main::$%^&*'} = \2.71828;
> > say "e = ", ${$main::{'$%^&*'}};
>
> You aren't really creating a constant (you'd also need to do that from a
> BEGIN block to enable the compiler to inline it). What you're doing is
> assigned a reference to a scalar to a glob. This sets the scalar-slot of
> the glob to this reference. When using the variable created in this way
> later on, the value is reproduced.
Ok, that meshes with what I was able to determine while traveling to work
on a bus today:
#! /usr/bin/perl
use v5.14;
no strict;
no warnings;
*main::pi = \3.1415926535;
say ( "pi SCALAR = ", ${*main::pi{SCALAR}} ) if defined *main::pi{SCALAR};
say ( "pi ARRAY = ", @{*main::pi{ARRAY} } ) if defined *main::pi{ARRAY};
say ( "pi HASH = ", %{*main::pi{HASH} } ) if defined *main::pi{HASH};
say ( "pi CODE = ", &{*main::pi{CODE} } ) if defined *main::pi{CODE};
*main::e = sub(){2.71828182845905};
say ( "e SCALAR = ", ${*main::e{SCALAR} } ) if defined *main::e{SCALAR};
say ( "e ARRAY = ", @{*main::e{ARRAY} } ) if defined *main::e{ARRAY};
say ( "e HASH = ", %{*main::e{HASH} } ) if defined *main::e{HASH};
say ( "e CODE = ", &{*main::e{CODE} } ) if defined *main::e{CODE};
say ( "pi * e = ", $pi * &e );
Prints:
Aragorn@Ketch
/rhe
%symbolic-identifier-test.perl
pi SCALAR = 3.1415926535
e SCALAR =
e CODE = 2.71828182845905
pi * e = 8.5397342224295
Aragorn@Ketch
/rhe
%
So the pi is a scalar, the e is code, and a mysterious defined but
uninitialized scalar $e also exists.
Seems that I misread the paragraph in The Camel Book that deals with
these two kinds of "constant" (SCALAR ref to string/number, and CODE
ref to subroutine returning string/number) on page 391 (Ch 10 "Packages",
section on "Symbol Tables"). The wording is somewhat fuzzy.
> Code which creates an actual constant (method poached from constant.pm)
>
> ---------
> BEGIN {
> $::{A} = \1.23;
> }
>
> print A;
> ----------
Looks to me like that's doing pretty much the same thing as
*main::A = \1.23;
I believe both versions put a ref to 1.23 into the 'SCALAR' slot
in the 'A' typeglob in the 'main' package, no?
Let me test that......
HMMMMMM.... no...... actually, it's storing the 1.23 in
main{A}->{CODE}
So it's a subroutine. Weird. Why is it a subroutine?
> [the symbol table of a package with name Name is a hash named %Name::,
> as a special-case, the symbol table of package main can also be referred
> to as %::]
That much I've learned in the past few days in my reading.
> This A can also be called and it's expanded inline:
>
> [rw@doppelsaurus]/tmp#perl -MO=Concise,-exec x
> 1 <0> enter
> 2 <;> nextstate(main 2 x:5) v:{
> 3 <0> pushmark s
> 4 <$> const[NV 1.23] s*
> 5 <@> print vK
> 6 <@> leave[1 ref] vKP/REFC
Ah, I see you're electing to B::Concise here. :-) Perl internal OP
codes, eh? I can't understand most of that, but I see we enter,
then do some stuff involving 1.23, then make like a tree and leave.
I'm not fully getting what "inlining" would mean here. That the
number 1.23 is substituted at any point in the code which calls A() ?
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley
------------------------------
Date: Tue, 24 Feb 2015 22:18:39 -0800
From: Robbie Hatley <see.my.sig@for.my.address>
Subject: Re: How does this bizarre script work?
Message-Id: <fLCdncrg7N6u9HDJnZ2dnUVZ57ydnZ2d@giganews.com>
On 2/24/2015 1:50 PM, Rainer Weikusat wrote:
> *{"\0\0\0"} = \"\0";
> print(ord(substr(${"\0\0\0"}, 0, 1)), "\n");
Triple-Null "identifier", eh? Fine. But why stop there?
Symbol table hashes apparently can use ANYTHING as a key,
even an entire valid Perl program such as:
say "Cheese!";
#! /usr/bin/perl
use v5.14;
use strict;
use warnings;
no strict "refs";
*{'say "Cheese!";'} =
\"Robbie Hatley Proposes Practical Perl Programs";
say ( ${'say "Cheese!";'} );
*{q<Don't you dare call this subroutine!>} =
sub(){say 'I TOLD YOU NOT TO CALL THIS SUBROUTINE!!!';};
say ( &{q<Don't you dare call this subroutine!>} );
I'm not sure if that's any too "practical"... but it works. :-)
(Though, it does also print a mysterious extra "1".)
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley
------------------------------
Date: Wed, 25 Feb 2015 13:32:18 +0100
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: How does this bizarre script work?
Message-Id: <mckfb6$5e6$1@dont-email.me>
On 25.02.15 07:18, Robbie Hatley wrote:
> But why stop there?
> Symbol table hashes apparently can use ANYTHING as a key,
> even an entire valid Perl program
Go the full distance, then, in particular during winter ;-)
*{*::Y = do $0} = \ 1;
print STDOUT *{ $::Y }, "\n";
------------------------------
Date: Wed, 25 Feb 2015 13:52:10 +0100
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: How does this bizarre script work?
Message-Id: <mckggd$9bj$1@dont-email.me>
On 25.02.15 07:18, Robbie Hatley wrote:
> But why stop there?
> Symbol table hashes apparently can use ANYTHING as a key,
> even an entire valid Perl program
Got the full length, then, and test your Perl during winter:
*{do $0} = \ 1;
print STDOUT ${do $0}, "\n";
------------------------------
Date: Wed, 25 Feb 2015 14:22:13 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: How does this bizarre script work?
Message-Id: <5tu0sb-bjo.ln1@news.rtij.nl>
On Tue, 24 Feb 2015 22:18:39 -0800, Robbie Hatley wrote:
> *{q<Don't you dare call this subroutine!>} =
> sub(){say 'I TOLD YOU NOT TO CALL THIS SUBROUTINE!!!';};
>
> say ( &{q<Don't you dare call this subroutine!>} );
>
>
>
> I'm not sure if that's any too "practical"... but it works. :-)
> (Though, it does also print a mysterious extra "1".)
The '1' is the return value of the say in the sub.
Been there, done that, got the mysterious extra 1. :-)
M4
------------------------------
Date: Wed, 25 Feb 2015 17:10:47 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: How does this bizarre script work?
Message-Id: <87sidtgbmw.fsf@doppelsaurus.mobileactivedefense.com>
Robbie Hatley <see.my.sig@for.my.address> writes:
> On 2/24/2015 1:46 PM, Rainer Weikusat wrote:
[...]
>> Code which creates an actual constant (method poached from constant.pm)
>>
>> ---------
>> BEGIN {
>> $::{A} = \1.23;
>> }
>>
>> print A;
>> ----------
>
> Looks to me like that's doing pretty much the same thing as
> *main::A = \1.23;
> I believe both versions put a ref to 1.23 into the 'SCALAR' slot
> in the 'A' typeglob in the 'main' package, no?
>
> Let me test that......
>
> HMMMMMM.... no...... actually, it's storing the 1.23 in
> main{A}->{CODE}
> So it's a subroutine. Weird. Why is it a subroutine?
It actually isn't (I couldn't resist the temptation using 3.14 instead
of 2.72):
[rw@doppelsaurus]/tmp#perl -MDevel::Peek -le 'BEGIN { $::{e} = \3.14; } print e + 1; Dump($::{e})'
4.14
SV = IV(0x623940) at 0x623950
REFCNT = 1
FLAGS = (ROK)
RV = 0x623908
SV = PVNV(0x605ed0) at 0x623908
REFCNT = 1
FLAGS = (NOK,READONLY,pIOK,pNOK)
IV = 3
NV = 3.14
PV = 0
This symbol table entry doesn't even store a glob but just a reference
to a scalar and for as long as no other properties of e are accessed, it
remains in this way, otherwise, the reference to a scalar is replaced
with a GV (could be referred to as 'reference to a glob) and a
subroutine returning the value is created instead:
[rw@doppelsaurus]/tmp#perl -MDevel::Peek -le 'BEGIN { $::{e} = \3.14; } $s = *e{CODE}; print $s->() + 1; Dump($::{e})'
4.14
SV = PVGV(0x65f570) at 0x623980
REFCNT = 2
FLAGS = (RMG,MULTI,IN_PAD)
MAGIC = 0x62b2f0
MG_VIRTUAL = &PL_vtbl_backref
MG_TYPE = PERL_MAGIC_backref(<)
MG_OBJ = 0x623968
NAME = "e"
NAMELEN = 1
GvSTASH = 0x606800 "main"
GP = 0x62b680
SV = 0x0
REFCNT = 1
IO = 0x0
FORM = 0x0
AV = 0x0
HV = 0x0
CV = 0x623968
CVGEN = 0x0
LINE = 1
FILE = "-e"
FLAGS = 0xa
EGV = 0x623980 "e"
>> This A can also be called and it's expanded inline:
>>
>> [rw@doppelsaurus]/tmp#perl -MO=Concise,-exec x
>> 1 <0> enter
>> 2 <;> nextstate(main 2 x:5) v:{
>> 3 <0> pushmark s
>> 4 <$> const[NV 1.23] s*
>> 5 <@> print vK
>> 6 <@> leave[1 ref] vKP/REFC
>
> Ah, I see you're electing to B::Concise here. :-) Perl internal OP
> codes, eh? I can't understand most of that, but I see we enter,
> then do some stuff involving 1.23, then make like a tree and leave.
> I'm not fully getting what "inlining" would mean here. That the
> number 1.23 is substituted at any point in the code which calls A() ?
That's more or less accurate. The actual procedure is more like this:
The compiler builds an op-tree from the source code. In case some
subtree of this op-tree can be evaluated at compile time, this is done
and the subtree replaced with a single op pusing the resulting value
onto the stack.
[rw@doppelsaurus]/tmp#perl -MO=Concise,-exec -e 'print 1 + 1.45 / length("AAA")'
1 <0> enter
2 <;> nextstate(main 1 -e:1) v:{
3 <0> pushmark s
4 <$> const[NV 1.48333333333333] s
5 <@> print vK
6 <@> leave[1 ref] vKP/REFC
At least in theory as this doesn't work for all operators (eg,
apparently, perl 5.14.2 can't deal with x operators at compile time).
------------------------------
Date: Wed, 25 Feb 2015 17:21:17 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: How does this bizarre script work?
Message-Id: <87oaohgb5e.fsf@doppelsaurus.mobileactivedefense.com>
"G.B." <bauhaus@futureapps.invalid> writes:
> On 25.02.15 07:18, Robbie Hatley wrote:
>> But why stop there?
>> Symbol table hashes apparently can use ANYTHING as a key,
>> even an entire valid Perl program
>
> Got the full length, then, and test your Perl during winter:
>
> *{do $0} = \ 1;
> print STDOUT ${do $0}, "\n";
"Where's the punchline"? AFAICT, this is a script which executes itself
recursively until the process gets killed because the system ran out of
memory (depending on 'the system', there's a chance that this will kill
some other process).
------------------------------
Date: Wed, 25 Feb 2015 20:01:43 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: How does this bizarre script work?
Message-Id: <7fidnXQsUYG6t3PJnZ2dnUVZ8sqdnZ2d@giganews.com>
On 24/02/15 20:58, Robbie Hatley wrote:
> *{'main::$%^&*'} = \2.71828;
> say "e = ", ${$main::{'$%^&*'}};
If you're going to write stuff as obscure as this, you really should be
coding in APL.
--
Henry Law Manchester, England
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4379
***************************************