[32638] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3914 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 3 09:09:27 2013

Date: Wed, 3 Apr 2013 06:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 3 Apr 2013     Volume: 11 Number: 3914

Today's topics:
    Re: "if" as modifier causes incorrect tainted messages? <ben@morrow.me.uk>
        multiple text replacements from a hash <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
    Re: multiple text replacements from a hash <rweikusat@mssgmbh.com>
    Re: multiple text replacements from a hash <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
        perlcc for perl 5.12.3 for Mac OS X 10.7.5 jomarbueyes@hotmail.com
    Re: perlcc for perl 5.12.3 for Mac OS X 10.7.5 <ben@morrow.me.uk>
    Re: perlcc for perl 5.12.3 for Mac OS X 10.7.5 jomarbueyes@hotmail.com
    Re: perlcc for perl 5.12.3 for Mac OS X 10.7.5 <ben@morrow.me.uk>
        regarding Class::Accessor::Faster <rweikusat@mssgmbh.com>
    Re: reporting bugs <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 1 Apr 2013 17:43:08 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: "if" as modifier causes incorrect tainted messages?
Message-Id: <s1qo2a-of2.ln1@anubis.morrow.me.uk>


Quoth bwooster47@gmail.com:
> On Thursday, 28 March 2013 18:37:17 UTC-4, Ben Morrow  wrote:
> > whole expression is considered tainted (to avoid having to make taint
> > checks for every operator) so the eval (in my case) is disallowed. See
> > https://rt.perl.org/rt3/Public/Bug/Display.html?id=17867 .
> 
> Thanks, in case anyone from http://perldoc.perl.org/perlsec.html is
> reading, would be nice if that page explicitly had this particular
> example.
> I should show that if modifier maintains untainted-ness, while an
> if-statement is fine.
> That doc does mention that the phrase you mention above, but it also
> says that ternary operation ?: works differently: "Since code with a
> ternary conditional... is essentially an if-statement". From that, some
> people might make the incorrect jump that and if-modifier is also
> essentially an if-statement so that should be fine too! But it isn't...

That statement is talking about something slightly different: assigning
a ?: with a tainted condition doesn't taint the assigned-to value:

    perl -Te'my $x = $^X ? 1 : 0; $x and eval 1'

and in fact this applies to 'and' and 'or' as well:

    perl -Te'my $x = ($^X and 1); $x and eval 1'

and to assignments performed under an if modifier:

    perl -Te'my $x = 1 if $^X; $x and eval 1'

However, a tainted condition will still forbid unsafe operations in
either half of the ?: itself:

    perl -Te'$^X ? eval 1 : ""'     # FAILS
    perl -Te'!$^X ? "" : eval 1'    # FAILS

Ben



------------------------------

Date: Mon, 1 Apr 2013 21:24:12 +0300
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: multiple text replacements from a hash
Message-Id: <kjcjcg$20l7$1@news.ntua.gr>

Hello,

I have a hash holding "from" - "to" text pieces.
I want to replace on a given text all the "from" parts with the "to".
The following piece of code is working, but I know it is doing not necessary 
loops, can you help me to do it better ;



use strict;
use warnings;
use feature qw/say/;

my $text    = '172.16.0.36   customer1.com   company.comcompany.com  erw 
172.16.0.36customer1.com';

my %Replace    = (
'10.1.1.21'    => '192.168.0.9',
'255.255.0.0'    => '255.255.255.0',
'customer1.com'    => 'local.lan',
'172.16.0.1'    => '192.168.0.1',
'company.com'    => 'local.lan',
'10.1.31.100'    => '192.168.0.7',
'172.16.0.36'    => '192.168.0.7',
'10.1.18.105'    => '192.168.0.1',
'255.255.240.0'    => '255.255.255.0',
'172.16.0.2'    => '192.168.0.9');





# We find the min and max hash lengths to avoid later as many iterations is 
possible
my $Min_length;
my $Max_length    = 0;
foreach my $property (keys %Replace) {
$Max_length = length $Replace{$property} if length $Replace{$property} > 
$Max_length;
$Min_length //= $Max_length;
$Min_length = length $Replace{$property} if length $Replace{$property} < 
$Min_length;
}



my $offset = 0;
while ( $offset < length $text) {
my $offset_walk = 0;
#say "*$offset* $text";

    for (my $i = $Max_length; $i >= $Min_length; $i--) {
    my $piece = substr($text, $offset, $i);

        if ( exists $Replace{$piece} ) {
        substr($text, $offset, $i, $Replace{$piece});
        $offset_walk = length $Replace{$piece};
        last
        }
    }

$offset += $offset_walk == 0 ? 1 : $offset_walk;
}


say $text; 



------------------------------

Date: Mon, 01 Apr 2013 20:10:35 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: multiple text replacements from a hash
Message-Id: <87a9piqd78.fsf@sapphire.mobileactivedefense.com>

"George Mpouras"
<nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
writes:

> I have a hash holding "from" - "to" text pieces.
> I want to replace on a given text all the "from" parts with the
> "to".
>
> my $text    = '172.16.0.36   customer1.com   company.comcompany.com
> erw 172.16.0.36customer1.com';
>
> my %Replace    = (
> '10.1.1.21'    => '192.168.0.9',
> '255.255.0.0'    => '255.255.255.0',
> 'customer1.com'    => 'local.lan',
> '172.16.0.1'    => '192.168.0.1',
> 'company.com'    => 'local.lan',
> '10.1.31.100'    => '192.168.0.7',
> '172.16.0.36'    => '192.168.0.7',
> '10.1.18.105'    => '192.168.0.1',
> '255.255.240.0'    => '255.255.255.0',
> '172.16.0.2'    => '192.168.0.9');

Considering that none of your keys is a prefix of another key, the
obvious idea would be to collect them all into a regex:

my $re = join('|', map { quotemeta($_) } keys(%Replace));
$re = qr/($re)/;

and do all replacements with the single s/// statement

$text =~ s/$re/$Replace{$+}/g;

If you had keys which are prefixes of other key, you could use

my $re = join('|', map { quotemeta($_) } sort { $b cmp $a } keys(%Replace));

to prefer the longer match or

my $re = join('|', map { quotemeta($_) } sort keys(%Replace));

to prefer the shorter.

Another good idea might be to use an existing macro (pre-)processor,
eg, m4, for tasks like this.


------------------------------

Date: Mon, 1 Apr 2013 22:36:54 +0300
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: Re: multiple text replacements from a hash
Message-Id: <kjcnkq$2ka3$1@news.ntua.gr>


clever, I have taken a wrong path.


------------------------------

Date: Mon, 1 Apr 2013 14:10:34 -0700 (PDT)
From: jomarbueyes@hotmail.com
Subject: perlcc for perl 5.12.3 for Mac OS X 10.7.5
Message-Id: <bf162f21-d16f-4922-88d1-543ce2604a73@googlegroups.com>

Hi all,

Is there a Perl compiler (perlcc) for Perl 5.12.3 running under Mac OS X 10=
 .7.5? From the Linux prompt I tried: which perlcc; perldoc perlcc; perldoc =
-f perlcc;  perldoc -q perlcc; and perldoc -q compiler. Neither inquiry ret=
urn a hint of the presence of the compiler or where to find it. I searched =
CPAN for perlcc and the query came back with Perl 5.8. Our local computer c=
luster still runs Perl 5.8 and does have a perlcc, which doesn't help me fo=
r several reasons.

If there is a compiler for Perl 5.12.3 under Mac OS X 10.7.5, where can I f=
ind it? If not for Perl 5.12.N, is there a perlcc for later Perl versions?

Thank you in advance,

Jomar


------------------------------

Date: Mon, 1 Apr 2013 23:10:18 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: perlcc for perl 5.12.3 for Mac OS X 10.7.5
Message-Id: <a7dp2a-lj6.ln1@anubis.morrow.me.uk>


Quoth jomarbueyes@hotmail.com:
> 
> Is there a Perl compiler (perlcc) for Perl 5.12.3 running under Mac OS X
> 10.7.5?

Nope. perlcc never worked properly, and has been removed. If you just
want to package your app up into a single executable, you might try PAR.

(That said, it ought to be possible to build a Mac OS .app with a
complete perl+modules distribution inside it, such that it would run
independently of the system perl. You would need at a minimum to build a
perl with -Duserelocatableinc, and it would probably be worth looking at
the Strawberry Portable builds to see what they do. 

Given that Mac OS always has perl, it also ought to be possible to build
a .app with just the required non-core modules in, including if
necessary several versioned arch trees for the versions of perl supplied
with the versions of Mac OS you want to support.

I really like the concept of application directories. Comes of being
brought up on RISC OS...)

Ben



------------------------------

Date: Tue, 2 Apr 2013 04:24:07 -0700 (PDT)
From: jomarbueyes@hotmail.com
Subject: Re: perlcc for perl 5.12.3 for Mac OS X 10.7.5
Message-Id: <a1498906-5786-42e9-b52d-f56211056a93@googlegroups.com>

On Monday, April 1, 2013 6:10:18 PM UTC-4, Ben Morrow wrote:
> Quoth jomarbueyes
> 
> > 
> 
> > Is there a Perl compiler (perlcc) for Perl 5.12.3 running under Mac OS X
> 
> > 10.7.5?
> 
> 
> 
> Nope. perlcc never worked properly, and has been removed. If you just
> 
> want to package your app up into a single executable, you might try PAR.
> 
> 
> 
> (That said, it ought to be possible to build a Mac OS .app with a
> 
> complete perl+modules distribution inside it, such that it would run
> 
> independently of the system perl. You would need at a minimum to build a
> 
> perl with -Duserelocatableinc, and it would probably be worth looking at
> 
> the Strawberry Portable builds to see what they do. 
> 
> 
> 
> Given that Mac OS always has perl, it also ought to be possible to build
> 
> a .app with just the required non-core modules in, including if
> 
> necessary several versioned arch trees for the versions of perl supplied
> 
> with the versions of Mac OS you want to support.
> 
> 
> 
> I really like the concept of application directories. Comes of being
> 
> brought up on RISC OS...)
> 
> 
> 
> Ben

Hi Ben,

Thank you for your response. I'll download and instal PAR and will also investigate re-building Perl with the -Duserelocatableinc option (or might as well build a more recent Perl version).

Thank you again,

Jomar


------------------------------

Date: Tue, 2 Apr 2013 14:29:48 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: perlcc for perl 5.12.3 for Mac OS X 10.7.5
Message-Id: <c33r2a-1vp.ln1@anubis.morrow.me.uk>

[Please find out how to stop GGroups from double-spacing quotes.]

Quoth jomarbueyes@hotmail.com:
> On Monday, April 1, 2013 6:10:18 PM UTC-4, Ben Morrow wrote:
> > Quoth jomarbueyes
> > 
> > > Is there a Perl compiler (perlcc) for Perl 5.12.3 running under Mac OS X
> > > 10.7.5?
> > 
> > Nope. perlcc never worked properly, and has been removed. If you just
> > want to package your app up into a single executable, you might try PAR.
> > 
> > (That said, it ought to be possible to build a Mac OS .app with a
> > complete perl+modules distribution inside it, such that it would run
> > independently of the system perl. You would need at a minimum to build a
> > perl with -Duserelocatableinc, and it would probably be worth looking at
> > the Strawberry Portable builds to see what they do. 
> > 
> > Given that Mac OS always has perl, it also ought to be possible to build
> > a .app with just the required non-core modules in, including if
> > necessary several versioned arch trees for the versions of perl supplied
> > with the versions of Mac OS you want to support.
> > 
> > I really like the concept of application directories. Comes of being
> > brought up on RISC OS...)
> 
> Thank you for your response. I'll download and instal PAR and will also
> investigate re-building Perl with the -Duserelocatableinc option (or
> might as well build a more recent Perl version).

Although both those suggestions were made off-the-cuff, if you're trying
to ship a .app (for a GUI program, I assume? What are you using?) I
would actually recommend the second option: just ship the modules needed
to run your app on the system perl. 

AFAIK -Duserelocatableinc is not yet a turn-key solution; if you do
decide to use it, my recommendation to look at Strawberry's Portable
builds was a serious one, since I believe they had to make other
modifications to get everything to work, and I believe there are still
caveats about where the resulting binary will run from. In particular, I
don't think any part of the perl toolchain will yet put up with spaces
in paths, which means your .app can't have a space in its name, and if
the user moves it somewhere with a space in the path things will break.

Using the system perl avoids all the problems of relocating perl itself:
the system perl is installed where it was built to be installed, and all
you need to do is arrange to add a directory somewhere under your .app
to @INC. The only slightly tricky bit would be populating that
directory: you need to find out which versions of perl are used by which
versions of Mac OS, build a private @INC tree for each of those versions
with all the modules you require, and then merge those trees into a
single @INC entry. Since perl keeps binary modules under versioned
directories, this should be fairly straightforward, assuming you have
access to all the versions of Mac OS you want to ship for. For building
a self-contained copy of all non-core modules you require, you may want
to look at App::cpanminus and the -L option to cpanm.

Ben



------------------------------

Date: Tue, 02 Apr 2013 20:58:28 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: regarding Class::Accessor::Faster
Message-Id: <87sj38902j.fsf@sapphire.mobileactivedefense.com>

As far as I could determine, this

http://cpansearch.perl.org/src/KASEI/Class-Accessor-0.34/lib/Class/Accessor/Faster.pm

is not only not concerned with data inheritance at all (eg, the first
generated accessor for a package will always access array element #0,
or, in other words, classes using this derived from classes also using
this will stomp on the array slots of their parent classes) but - in
addition - really badly or at least very 'unimaginatively' coded. Eg,
created accessor methods are closures referencing a 'read-only' scalar
variable when they could be compiled to access the slot whose number
is stored in $n directly.



------------------------------

Date: Mon, 1 Apr 2013 22:58:42 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: reporting bugs
Message-Id: <ihcp2a-lj6.ln1@anubis.morrow.me.uk>

[alt.barcodes removed, since this is about Perl process]

Quoth Ivan Shmakov <oneingray@gmail.com>:
> >>>>> Ben Morrow <ben@morrow.me.uk> writes:
> 
>  > <pet peeve> The correct place to file a bug in a Perl module is in
>  > its CPAN bug tracker, or, in this case, in the zbar Sourceforce
>  > tracker.
> 
> 	BTW, there's a longstanding bug filed at the CPAN RT [2] (along
> 	with a patch.)  However, it appears to be filed against
> 	libwww-perl, while it actually belongs to Net-HTTP.
> 
> 	The question is: how do I reassign it?
> 
> [2] https://rt.cpan.org/Public/Bug/Display.html?id=29468

You can't; in fact, it looks like the way rt.cpan.org is set up noone
can move a ticket from one queue to another. The best you could do is
file a separate bug against Net-HTTP, referencing the LWP bug; but since
both dists are maintained by Gisle Aas I'm not sure there'd be much
point.

>  > Filing a bug with some random distro is Not Helpful, since such
>  > reports frequently don't find their way upstream.
[...]
> 	* the issue may indeed be specific to the distribution's build;
> 	  (naturally, building from the upstream sources for every bug
> 	  being I report just to check that it wasn't introduced by the
> 	  packagers is hardly an option.)

Obviously you have a different approach from me. I would consider
building the latest upstream release from source, and probably the
latest upstream equivalent of CVS HEAD, a basic prerequisite for
reporting a bug. After all, it's almost certainly the first thing you'll
be asked to do in any case, and a patch which doesn't apply to HEAD is
probably nearly worthless.

I suppose that in principle 'I'm using a distro; I'm paying them (or
not) to sort out whose bug it is and get it fixed upstream' ought to be
a reasonable argument, but in practice distros tend to be extremely
unreliable about sending bugs upstream, probably because they have had
their own share of flaky upstreams to deal with.

> 	Alas, even for the Perl modules, the CPAN RT is not always the
> 	preferred but tracker.  Consider, e. g.:
> 
> --cut: https://rt.cpan.org/Public/Bug/Display.html?id=79999 --
>     Please report issues via github at
>     https://github.com/gbarr/perl-Convert-ASN1/issues
> --cut: https://rt.cpan.org/Public/Bug/Display.html?id=79999 --

There are fields in META.{yml,json} which let a CPAN dist indicate where
its preferred bugtracker is. search.cpan.org will honour these fields if
they are present, so the 'View/Report Bugs' link on the page for
Convert-ASN1 will take you to that github bugtracker. I don't believe
there is currently any support for forwarding the bug-*@rt.cpan.org
emails, though; this is at least in part because modules often outlive
their original authors, and having somewhere to track bugs once the
author has disappeared is useful.

Ben



------------------------------

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 3914
***************************************


home help back first fref pref prev next nref lref last post