[27346] in Perl-Users-Digest
Perl-Users Digest, Issue: 9053 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 15 00:06:03 2006
Date: Tue, 14 Mar 2006 21:05:08 -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 Tue, 14 Mar 2006 Volume: 10 Number: 9053
Today's topics:
$zip->AddTreeMatching() speed? <Patrick_member@newsguy.com>
Re: $zip->AddTreeMatching() speed? <1usa@llenroc.ude.invalid>
Re: A Problem With GD robic0
Can I skip tokens in RegExp backreferences? <invalid@earthlink.net.invalid>
Re: Can I skip tokens in RegExp backreferences? <1usa@llenroc.ude.invalid>
Re: Can I skip tokens in RegExp backreferences? <rvtol+news@isolution.nl>
Re: Can I skip tokens in RegExp backreferences? (Rick Scott)
Re: Can I skip tokens in RegExp backreferences? robic0
Re: Can I skip tokens in RegExp backreferences? robic0
Re: manipulating JPEG images robic0
Re: Toggle flags (WAS: A Problem With GD) robic0
Re: Toggle flags (WAS: A Problem With GD) <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 Mar 2006 16:32:59 -0800
From: Patrick Flaherty <Patrick_member@newsguy.com>
Subject: $zip->AddTreeMatching() speed?
Message-Id: <dv7nbr0bhc@drn.newsguy.com>
Hi,
Using perl to archive a bunch of things in a bunch of locations (into a ZIP
file).
Was using functions (for each tree) such as this:
sub process_file_develtree {
$this_file = $File::Find::name;
if ($this_file =~ m/.*\.(bas$|cpp$|pl$|[ce]$|xml$|sql$|vba$|vbs$)/i) {
print $this_file . "\n";
$zip->addFile($this_file);
}
}
The above, I found, gave me absolute pathnames in the ZIP file. And on my
target machine I never found a way of unziping except to do an unzip -l. Get
the name and then extract to stdout and capture the file that way.
Looking then more closely at the ZIP module, it _seems_ the only way to get
relative pathnames is to use
$zip->addTreeMatching( '.', undef,
'\.(bas$|cpp$|pl$|[ce]$|xml$|sql$|vba$|vbs$)'; );
The undef being the key (to relative pathnames).
This works. But it seems _much_ slower.
Explanations? Ideas?
thanx.
pat
------------------------------
Date: Wed, 15 Mar 2006 02:08:45 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: $zip->AddTreeMatching() speed?
Message-Id: <Xns9786D7393BAEasu1cornelledu@127.0.0.1>
Patrick Flaherty <Patrick_member@newsguy.com> wrote in
news:dv7nbr0bhc@drn.newsguy.com:
> Using perl to archive a bunch of things in a bunch of locations (into
> a ZIP file).
>
> Was using functions (for each tree) such as this:
It would have been better if you had posted a short but complete script.
> sub process_file_develtree {
> $this_file = $File::Find::name;
> if ($this_file =~
> m/.*\.(bas$|cpp$|pl$|[ce]$|xml$|sql$|vba$|vbs$)/i) {
This is unnecessarily hard to read:
/\.(bas|cpp|pl|[ce]|xml|sql|vba|vbc)\z/i
should better.
> print $this_file . "\n";
> $zip->addFile($this_file);
> }
> }
>
> The above, I found, gave me absolute pathnames in the ZIP file. And
> on my target machine I never found a way of unziping except to do an
> unzip -l. Get the name and then extract to stdout and capture the
> file that way.
>
> Looking then more closely at the ZIP module, it _seems_ the only way
> to get relative pathnames
The fact that you want relative pathnames means all of these files live
under the same root. What is wrong with a chdir to that directory?
>
> $zip->addTreeMatching( '.', undef,
> '\.(bas$|cpp$|pl$|[ce]$|xml$|sql$|vba$|vbs$)'; );
Why not mention which module you are using? I am going to assume
Archive::Zip. I am also not going to bother with writing separate
implementations and profiling them, but instead take your word that this
is slow.
In that case, I wonder why you don't want to use the second, optional,
argument to addFile:
#!/usr/bin/perl
use strict;
use warnings;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use File::Find;
use File::Spec::Functions qw( catfile canonpath );
chdir or die "Cannot chdir to $ENV{HOME}: $!";
my $zip = Archive::Zip->new;
find(\&zip_adder, '.');
$zip->writeToFileNamed('test.zip') == AZ_OK
or die "Cannot write to test.zip: $!";
sub zip_adder {
my $this = canonpath $File::Find::name;
if ( $this =~ /\.pl\z/i ) {
$zip->addFile(catfile($ENV{HOME}, $this), $this)
or warn "Cannot add $this\n";
}
}
__END__
D:\Home\asu1\UseNet\clpmisc> zip-test.pl
D:\Home\asu1\UseNet\clpmisc> unzip -l ..\..\test.zip
...
308 11/10/05 17:48 UseNet/clpmisc/proc/mon.pl
676 11/10/05 18:07 UseNet/clpmisc/proc/proc.pl
339 02/21/05 18:10 UseNet/clpmisc/s/c.pl
368 02/21/05 18:10 UseNet/clpmisc/s/s.pl
774 04/14/05 13:11 UseNet/clpmisc/Scalar-Util-Clone-0.04/Makefile.PL
112 01/31/06 17:01 UseNet/clpmisc/t/t.pl
544 03/15/05 15:18 UseNet/clpmisc/T1/Makefile.PL
383 01/25/05 15:34 UseNet/clpmisc/test/myren.pl
...
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 14 Mar 2006 18:21:33 -0800
From: robic0
Subject: Re: A Problem With GD
Message-Id: <tpte12t1iuud5ore910gn4c3rkgen3mjs8@4ax.com>
On Mon, 13 Mar 2006 01:37:51 -0600, Mark Manning <markem@airmail.net> wrote:
>robic0 wrote:
>
>> On Sun, 26 Feb 2006 12:57:16 +1100, "Sisyphus" <sisyphus1@nomail.afraid.org> wrote:
>>
>>
>> Too bad can't macro in perl, a simple RGB(255,255,255) gets a nice
>> 24-bit color register value.
>>
>> sub RGB { return $red<<16|$green<<8|$blue }
>
>Isn't eval similar in nature to macros in that they can be expanded during
>execution? I know - it's not a substitution as in a true define statement - but
>generally speaking wouldn't eval equate to a macro? (Not that using evals is a
>good thing in most programs. Just wondering.)
>
Sure is. Its also used to "catch" exceptions generated from a (usually module)
known exception throwing module.
But given the RGB function above, calling RGB(255,255,255) would be more appropriate.
The difference is evals are mostly used, if its your purpose, to dynamically
generate unknown code at runtime, then its evaluated. In the RGB case its a known form.
In C/C++, macros are used for "substitution" by the pre-compiler. All instances of the
macro are substituted for "real" code before compiling. Thats why there's always the
perviable, "Beware of Macro's sideaffects" by certain documentation, since many C/C++
constructs are macro's that are not intrinsics. For instance, long, short and byte
are macro's.
Again, there is no "strong" typing in Perl, so people make the same mistakes as in
Javascript. For instance some Swedish guy tried to convice me there are bool variable
types in Perl (Jue).
Rob
------------------------------
Date: Wed, 15 Mar 2006 01:12:40 GMT
From: Someone Else <invalid@earthlink.net.invalid>
Subject: Can I skip tokens in RegExp backreferences?
Message-Id: <cSJRf.4199$sL2.327@newsread2.news.atl.earthlink.net>
What I want to do is to use a regular expression like:
/([+-]\s*\d+)/;
to parse some fairly complicated algebraic expressions; but I
don't want to capture the \s* as part of $1. In other words, I
would like either "+ 32" or "+32" to store "+32" in $1. (I've
extracted the salient feature. The real problem is much more
complicated, but the details are essentially irrelevant to my
question. See below if you're interested.)
What I am looking for is something like:
/([+-](?:\s*)\d+)/;
but not quite. Not only don't I want to capture the \s* in $2,
but I want to exclude it from the enclosing $1.
Any ideas?
Semi-irrelevant details follow:
In the simple example above it's easy to ignore $2. The real
application is more like:
@a = /\s*([+-]\s*\d+)/g;
In that case it's still easy to use:
@a = /\s*([+-])\s*(\d+)/g;
and then concatenate every pair of entries in @a. But as I said,
the real application is much more complicated. It involves
parsing 40 MB files written in an arcane linear programming
language, with floating-point coefficients, variable names that
can include nearly any printable character, extending over many
lines, interspersed with relational symbols, etc.. So I'd really
like to avoid a lot of pre- or post-processing.
-- David
To make invalid valid, reverse the letters
------------------------------
Date: Wed, 15 Mar 2006 01:37:58 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Can I skip tokens in RegExp backreferences?
Message-Id: <Xns9786D20121DB2asu1cornelledu@127.0.0.1>
Someone Else <invalid@earthlink.net.invalid> wrote in news:cSJRf.4199
$sL2.327@newsread2.news.atl.earthlink.net:
> What I want to do is to use a regular expression like:
>
> /([+-]\s*\d+)/;
...
> What I am looking for is something like:
>
> /([+-](?:\s*)\d+)/;
#!/usr/bin/perl
use strict;
use warnings;
my $s = '+ 42';
$s =~ /([+-])\s*(\d+)/;
print "$1$2\n";
> In the simple example above it's easy to ignore $2. The real
> application is more like:
>
> @a = /\s*([+-]\s*\d+)/g;
...
> But as I said, the real application is much more complicated.
Why not state the precise problem instead of throwing variations at us?
Is there anything wrong with:
#!/usr/bin/perl
use strict;
use warnings;
my $s = '+ 42 -89 + 35 -12';
my @s;
while ( $s =~ /([+-])\s*(\d+)/g ) {
push @s, "$1$2";
}
print "@s\n";
__END__
Or even:
#!/usr/bin/perl
use strict;
use warnings;
my $s = '+ 42 -89 + 35 -12';
$s =~ s/([+-])\s*(\d+)/$1$2/g;
print "$s\n";
__END__
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 15 Mar 2006 02:48:53 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Can I skip tokens in RegExp backreferences?
Message-Id: <dv7vjm.1l8.1@news.isolution.nl>
Someone Else schreef:
> What I want to do is to use a regular expression like:
>
> /([+-]\s*\d+)/;
>
> to parse some fairly complicated algebraic expressions; but I
> don't want to capture the \s* as part of $1. [...]
> it's still easy to use:
>
> @a = /\s*([+-])\s*(\d+)/g;
>
> and then concatenate every pair of entries in @a. But as I said,
> the real application is much more complicated.
If that second approach is not feasible, and I can't guess why not, than
you'd better add a step:
1. remove all meaningless whitespace etc.
s/([+-])[[:blank:]]+(\d)/$1$2/g;
2. do the captures
But my real advise is to use Yacc/Lex, because then you can convert 40
MB in a few seconds.
--
Affijn, Ruud
"Gewoon is een tijger."
echo 014C8A26C5DB87DBE85A93DBF |perl -pe 'tr/0-9A-F/JunkshoP cartel,/'
------------------------------
Date: Wed, 15 Mar 2006 02:19:48 -0000
From: rick@shadowspar.dyndns.org (Rick Scott)
Subject: Re: Can I skip tokens in RegExp backreferences?
Message-Id: <1142388290.42bFFEfA.15598@shadowspar>
(Someone Else <invalid@earthlink.net.invalid> uttered:)
> What I am looking for is something like:
>
> /([+-](?:\s*)\d+)/;
>
> but not quite. Not only don't I want to capture the \s* in $2,
> but I want to exclude it from the enclosing $1.
>
> Any ideas?
>
> ...it's still easy to use:
>
> @a = /\s*([+-])\s*(\d+)/g;
>
> and then concatenate every pair of entries in @a.
That's exactly the solution I was about to suggest -- capture two
groups, then concatenate them.
> But as I said, the real application is much more complicated. It
> involves parsing 40 MB files written in an arcane linear
> programming language, with floating-point coefficients, variable
> names that can include nearly any printable character, extending
> over many lines, interspersed with relational symbols, etc.. So
> I'd really like to avoid a lot of pre- or post-processing.
Have you tried and benchmarked this simpler solution yet? Looking for
more efficient ways to do things is always laudable, but until you
know whether or not your solution is intractably slow, you don't
really know whether or not you actually have a problem worth solving.
Cheers,
Rick
--
key CF8F8A75 / print C5C1 F87D 5056 D2C0 D5CE D58F 970F 04D1 CF8F 8A75
..we need to focus on humans, on how humans care about doing
programming or operating the application of the machines.
We are the masters. They are the slaves. :Matz
------------------------------
Date: Tue, 14 Mar 2006 18:55:23 -0800
From: robic0
Subject: Re: Can I skip tokens in RegExp backreferences?
Message-Id: <960f1218rhde9h9gus6d1s3d7n8tj5io4u@4ax.com>
On Wed, 15 Mar 2006 01:12:40 GMT, Someone Else <invalid@earthlink.net.invalid> wrote:
>What I want to do is to use a regular expression like:
>
> /([+-]\s*\d+)/;
>
>to parse some fairly complicated algebraic expressions; but I
>don't want to capture the \s* as part of $1. In other words, I
>would like either "+ 32" or "+32" to store "+32" in $1. (I've
>extracted the salient feature. The real problem is much more
>complicated, but the details are essentially irrelevant to my
>question. See below if you're interested.)
>
>What I am looking for is something like:
>
> /([+-](?:\s*)\d+)/;
>
>but not quite. Not only don't I want to capture the \s* in $2,
>but I want to exclude it from the enclosing $1.
>
>Any ideas?
>
>Semi-irrelevant details follow:
>
>In the simple example above it's easy to ignore $2. The real
>application is more like:
>
> @a = /\s*([+-]\s*\d+)/g;
>
>In that case it's still easy to use:
>
> @a = /\s*([+-])\s*(\d+)/g;
>
>and then concatenate every pair of entries in @a. But as I said,
>the real application is much more complicated. It involves
>parsing 40 MB files written in an arcane linear programming
>language, with floating-point coefficients, variable names that
>can include nearly any printable character, extending over many
>lines, interspersed with relational symbols, etc.. So I'd really
>like to avoid a lot of pre- or post-processing.
>
>-- David
>To make invalid valid, reverse the letters
if ($var ~= s/([+-]*?)\s*?(\d+?)/$1$2/) {
print "found: $var\n";
else {
print "no match found: $var\n";
}
But you bettern need to know what text you will be dealing with.
To include \s*, zero or more white spaces, indicates that you
can't guarantee the [+-] character class nor the numbers.
Do as much as you can with the regex, but complement it with
residual error checking.
What level of certainty or accuracy do you expect and anticipate?
To my experience there is neither. So this basically is an useless
solution based on your problem statement. If you don't understand
what was just stated, then it means as much to you as that.
------------------------------
Date: Tue, 14 Mar 2006 19:04:18 -0800
From: robic0
Subject: Re: Can I skip tokens in RegExp backreferences?
Message-Id: <3u0f12h6pqrcu4v0t7e8epolgd6aj4qi6t@4ax.com>
On Tue, 14 Mar 2006 18:55:23 -0800, robic0 wrote:
>On Wed, 15 Mar 2006 01:12:40 GMT, Someone Else <invalid@earthlink.net.invalid> wrote:
>
>>What I want to do is to use a regular expression like:
>>
>> /([+-]\s*\d+)/;
>>
>>to parse some fairly complicated algebraic expressions; but I
>>don't want to capture the \s* as part of $1. In other words, I
>>would like either "+ 32" or "+32" to store "+32" in $1. (I've
>>extracted the salient feature. The real problem is much more
>>complicated, but the details are essentially irrelevant to my
>>question. See below if you're interested.)
>>
>>What I am looking for is something like:
>>
>> /([+-](?:\s*)\d+)/;
>>
>>but not quite. Not only don't I want to capture the \s* in $2,
>>but I want to exclude it from the enclosing $1.
>>
>>Any ideas?
>>
>>Semi-irrelevant details follow:
>>
>>In the simple example above it's easy to ignore $2. The real
>>application is more like:
>>
>> @a = /\s*([+-]\s*\d+)/g;
>>
>>In that case it's still easy to use:
>>
>> @a = /\s*([+-])\s*(\d+)/g;
>>
>>and then concatenate every pair of entries in @a. But as I said,
>>the real application is much more complicated. It involves
>>parsing 40 MB files written in an arcane linear programming
>>language, with floating-point coefficients, variable names that
>>can include nearly any printable character, extending over many
>>lines, interspersed with relational symbols, etc.. So I'd really
>>like to avoid a lot of pre- or post-processing.
>>
>>-- David
>>To make invalid valid, reverse the letters
>
>if ($var ~= s/([+-]*?)\s*?(\d+?)/$1$2/) {
=~
- good wine boys!
> print "found: $var\n";
>else {
> print "no match found: $var\n";
>}
>
>But you bettern need to know what text you will be dealing with.
>To include \s*, zero or more white spaces, indicates that you
>can't guarantee the [+-] character class nor the numbers.
>Do as much as you can with the regex, but complement it with
>residual error checking.
>
>What level of certainty or accuracy do you expect and anticipate?
>To my experience there is neither. So this basically is an useless
>solution based on your problem statement. If you don't understand
>what was just stated, then it means as much to you as that.
Too many english corrections to make. I need a proof reader full time.
Anybody wants a job let me know. I pay dirt for dirt.
------------------------------
Date: Tue, 14 Mar 2006 18:32:04 -0800
From: robic0
Subject: Re: manipulating JPEG images
Message-Id: <6tue129acggg4imrro1ps83e3gfuvbss7r@4ax.com>
On Tue, 14 Mar 2006 19:07:43 -0800, "Murray R. Van Luyn" <vanluynm@NOSPAM.iinet.net.au> wrote:
>For an assignment I'm required to find out how to remove camera shake from
>JPEG images using Perl.
Hey, I can never get the last few drops of piss from my dick when I take a
leak, think you could write a perl program for me?
No but seriously, I mean come on..... Its a hardware thing. Real time camera
shake is removed from the framebuffer via jitter routines in the electronics.
Have you gone onto Doom9.com and explored filters (plugins for frameserverving)
written in asm?
>
>I'm stumped! I'm not after a solution, but would really appreciate direction
>to sources of information that may help me to figure out how to accomplish
>this task.
>
>Regards,
>Murray R. Van Luyn.
>
------------------------------
Date: Tue, 14 Mar 2006 18:05:45 -0800
From: robic0
Subject: Re: Toggle flags (WAS: A Problem With GD)
Message-Id: <nhse12dkjb6rr801pullj7t23ao161els9@4ax.com>
On Sun, 12 Mar 2006 02:51:24 GMT, "Jürgen Exner" <jurgenex@hotmail.com> wrote:
>robic0 wrote:
>> There is no such thing as a "boolean" type in Perl.
>
>True.
>But there are nevertheless boolean values that can be expressed in Perl data
>types.
>
I don't think this is nor ever was true (forgive the pun) in Perl.
I'm probably wrong buy I'm going to use your own words to tie your argument
into a knot.
>> This:
>> "$var = !$var;" ,
>> is exactly:
>> $var = 1 - $var;
>> in Perl, I think, if $var == 0 or 1.
>
>Well, did you try it? Because it is not.
>Boolean values are _not_ represented as numbers. This becomes quite obvious
>when you try to print them.
>
>> So in Perl, !(not) as a TRUE referrs to it being 0.
>> For example, what does this translate to in Perl (?):
>>
>> $var = -7;
>> $var = !$var;
>
>$var now has the logical value false. Where's the problem?
Whats the logical value of "false" in Perl?
quote:
">robic0 wrote:
>> There is no such thing as a "boolean" type in Perl.
>
>True.
>But there are nevertheless boolean values that can be expressed in Perl data
>types.
"
So tell me again what logical value $var has? Does it have the logical value true?
Is it a boolean scalar?
For instance in C++:
bool bval = true; // "true" is a bool value
if (1) bval = false; // "false" is a bool value
How would you "typecast" a Perl variable as bool?
Or is there a distinction between if ($var) and if ($var == 1) and if ($var > 0)
.. ?
Thought Perl was like javascript a little, variant types.
>
>jue
>
------------------------------
Date: Wed, 15 Mar 2006 02:44:40 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Toggle flags (WAS: A Problem With GD)
Message-Id: <scLRf.17541$wH5.9045@trnddc02>
robic0 wrote:
>> $var now has the logical value false. Where's the problem?
> Whats the logical value of "false" in Perl?
Are you talking about the text that is composed of the letters f, a, l, s,
and e?
Because that string is not empty it's logical value is true.
> quote:
> ">robic0 wrote:
>>> There is no such thing as a "boolean" type in Perl.
>>
>> True.
>> But there are nevertheless boolean values that can be expressed in
>> Perl data types.
>
> So tell me again what logical value $var has? Does it have the
> logical value true?
You mean after assigning a non-empty string to it? It evaluates to the
logical value of true.
> Is it a boolean scalar?
No, it is scalar. You happen to assign a string to it.
If used in boolean context then the boolean value of that scalar will be
used which happens to be true because the text is non-empty.
> For instance in C++:
>
> bool bval = true; // "true" is a bool value
> if (1) bval = false; // "false" is a bool value
What does C++ have to do with data types in Perl?
> How would you "typecast" a Perl variable as bool?
You just use it in boolean context.
> Or is there a distinction between if ($var) and if ($var == 1) and if
> ($var > 0) .. ?
Absolutely. There is a very major difference. If you haven't figured that
one out yet, then maybe you should go back to basics.
if ($var): this uses $var in boolean context. If $var was assigned the text
"false" then this is a non-empty text which evaluates to the boolean value
true.
if ($var == 1) and if ($var > 0) : these use $var in numerical context. If
$var was assigned the text "false" then the numerical value of this scalar
is 0, thus both conditions are false.
if ($var eq "false"): you didn't ask for this one, but this uses $var in
string context. If and only if $var was assigned the text "false" then the
textual comparison will yield true.
jue
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 V10 Issue 9053
***************************************