[31107] in Perl-Users-Digest
Perl-Users Digest, Issue: 2352 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 19 00:09:46 2009
Date: Sat, 18 Apr 2009 21:09:10 -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 Sat, 18 Apr 2009 Volume: 11 Number: 2352
Today's topics:
Re: A Perl module for autoformatting C program <struggleyb.nku@gmail.com>
Comparing all hash keys to a string <dalyea@gmail.com>
Re: Comparing all hash keys to a string <myusenet@trashmail.net>
Re: Comparing all hash keys to a string <tadmc@seesig.invalid>
Re: Comparing all hash keys to a string <ben@morrow.me.uk>
Re: Comparing all hash keys to a string <benkasminbullock@gmail.com>
Re: dmake.exe: Error: -- 'C:\Perl\libConfig.pm' not fou <sisyphus359@gmail.com>
Re: generic variable name possible? <whynot@pozharski.name>
Graphics programming <bernie@fantasyfarm.com>
Re: Graphics programming <ben@morrow.me.uk>
Re: I'm looking for a Perl Book... I think. <someone@somewhere.nb.ca>
Re: I'm looking for a Perl Book... I think. <benkasminbullock@gmail.com>
Re: I'm looking for a Perl Book... I think. <tadmc@seesig.invalid>
Re: I'm looking for a Perl Book... I think. <tadmc@seesig.invalid>
Re: What does `my' do?! <ben@morrow.me.uk>
Re: What does `my' do?! derykus@gmail.com
Re: What does `my' do?! <nospam-abuse@ilyaz.org>
Re: What does `my' do?! <nospam-abuse@ilyaz.org>
Re: What does `my' do?! <ben@morrow.me.uk>
Re: What does `my' do?! <nospam-abuse@ilyaz.org>
Re: What's wrong with the following regular expression? <haoniukun@gmail.com>
Re: What's wrong with the following regular expression? <haoniukun@gmail.com>
Re: What's wrong with the following regular expression? <haoniukun@gmail.com>
Re: What's wrong with the following regular expression? <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 18 Apr 2009 20:00:37 -0700 (PDT)
From: byang <struggleyb.nku@gmail.com>
Subject: Re: A Perl module for autoformatting C program
Message-Id: <a84795a2-7402-40d7-8985-8e353139e0e2@b6g2000pre.googlegroups.com>
On 4=D4=C218=C8=D5, =CF=C2=CE=E711=CA=B113=B7=D6, Ben Morrow <b...@morrow.m=
e.uk> wrote:
> Quoth byang <struggleyb....@gmail.com>:
>
> > Hi,
> > After some searching, I did not find such a module that used for
> > formatting C program. I have a set of C program files, which are total
> > mess. I intend to use Perl to autoformat them, help please. Thanks!
>
> What's wrong with indent(1)? While PErl is a flexible and useful
> language, it seems silly to reinvent something that's already been
> implemented perfectly well.
It is great, but I don't want my work dependent on too many external
applications. And does indent available on all Unix-like system?
Thanks!
Regards!
Bo
------------------------------
Date: Sat, 18 Apr 2009 15:32:36 -0700 (PDT)
From: "dalyea@gmail.com" <dalyea@gmail.com>
Subject: Comparing all hash keys to a string
Message-Id: <e9afc71b-04b8-4355-b8ed-4a2421cf7b4c@y6g2000prf.googlegroups.com>
I frequently do something like this:
foreach my $key (keys %hash) {
if ($string=~/$key/i) {
do_something;
}
}
Is there an easy and fast and more compact way to compare all
the keys of a hash to a string? Something like:
my @found=grep /$_/ $string, keys %hash;
where @found would contain all the matching keys from the
hash found in $string.
Thanks, I've always wanted to find a better way to do this.
------------------------------
Date: Sun, 19 Apr 2009 00:36:13 +0200
From: Anton Ramunda <myusenet@trashmail.net>
Subject: Re: Comparing all hash keys to a string
Message-Id: <ABsGl.34463$Rh1.20950@newsfe10.ams2>
dalyea@gmail.com schrieb:
> I frequently do something like this:
>
> foreach my $key (keys %hash) {
> if ($string=~/$key/i) {
> do_something;
> }
> }
>
> Is there an easy and fast and more compact way to compare all
> the keys of a hash to a string? Something like:
>
> my @found=grep /$_/ $string, keys %hash;
>
> where @found would contain all the matching keys from the
> hash found in $string.
>
> Thanks, I've always wanted to find a better way to do this.
What you try to do remembers me to a pointer function call like in C.
The best would to put the function address of "do_something();" function
as value in the key of your hash table:
Then instead of the foreach and if calls simply execute:
$key{$string}();
It would be more faster than to parse strings. But your string should
then match exactly the entry in the hash table.
I'm not sure if its this what you want.
--
Best regards,
Anton
E-Mail: myusenet@trashmail.net
------------------------------
Date: Sat, 18 Apr 2009 17:54:39 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Comparing all hash keys to a string
Message-Id: <slrngukmhf.955.tadmc@tadmc30.sbcglobal.net>
dalyea@gmail.com <dalyea@gmail.com> wrote:
> I frequently do something like this:
>
> foreach my $key (keys %hash) {
> if ($string=~/$key/i) {
> do_something;
> }
> }
>
> Is there an easy and fast and more compact way to compare all
> the keys of a hash to a string? Something like:
>
> my @found=grep /$_/ $string, keys %hash;
>
> where @found would contain all the matching keys from the
> hash found in $string.
my @found = map {$string =~ /$_/gi} keys %hash;
or
my @found = map {$string =~ /\b$_\b/gi} keys %hash;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sat, 18 Apr 2009 23:49:49 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Comparing all hash keys to a string
Message-Id: <d12qb6-1e8.ln1@osiris.mauzo.dyndns.org>
Quoth "dalyea@gmail.com" <dalyea@gmail.com>:
> I frequently do something like this:
>
> foreach my $key (keys %hash) {
> if ($string=~/$key/i) {
> do_something;
> }
> }
>
> Is there an easy and fast and more compact way to compare all
> the keys of a hash to a string? Something like:
>
> my @found=grep /$_/ $string, keys %hash;
>
> where @found would contain all the matching keys from the
> hash found in $string.
Do you know about the =~ operator? It allows you to perform pattern
matches on variables other than $_. In this case you want
my @found = grep $string =~ /$_/i, keys %hash;
Ben
------------------------------
Date: 19 Apr 2009 02:15:39 GMT
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Comparing all hash keys to a string
Message-Id: <49ea894b$0$694$c5fe31e7@read01.usenet4all.se>
On Sat, 18 Apr 2009 17:54:39 -0500, Tad J McClellan wrote:
> my @found = map {$string =~ /$_/gi} keys %hash;
> or
> my @found = map {$string =~ /\b$_\b/gi} keys %hash;
This is a very compact solution. Another possibility which might be
faster if you have a lot of keys and the hash does not change is to build
a regular expression from the hash keys as follows:
#!/home/ben/software/install/bin/perl
use warnings;
use strict;
my %hash = qw/ba be bu be bo ca di du de do Monster Monkey Brad Pitt/;
# Long version
my @sortedbylength = sort {length($b) <=> length($a)} keys %hash;
my $matchingexpression = '('.join ("|", @sortedbylength).')';
print "$matchingexpression\n";
my $string = "ba bill bo brad tiny monster";
my @matches = ($string =~ /$matchingexpression/gi);
print "@matches\n";
# Shorter version
my $m='('.join ('|',(sort {length $b <=> length $a} keys %hash)).')';
my @matches2 = ($string =~ /$m/gi);
print "@matches2\n";
------------------------------
Date: Sat, 18 Apr 2009 15:27:41 -0700 (PDT)
From: sisyphus <sisyphus359@gmail.com>
Subject: Re: dmake.exe: Error: -- 'C:\Perl\libConfig.pm' not found, and can't be made
Message-Id: <2c76e7c4-56bf-48e4-9f2c-7764e4401719@v23g2000pro.googlegroups.com>
On Apr 19, 6:30=A0am, tus...@gmail.com wrote:
> dmake.exe: =A0Error: -- `C:\Perl\libConfig.pm' not found
What does 'dmake -V' output ?
With my build of 1004 (where I *don't* have the problem you've
reported) it outputs:
#########################
dmake.exe - Version 4.11-20080107-SHAY (Windows / MS Visual C++)
Copyright (c) 1990,...,1997 by WTI Corp.
Default Configuration:
MAXLINELENGTH :=3D 32766
MAXPROCESSLIMIT :=3D 4
MAXPROCESS :=3D 1
.IMPORT .IGNORE: DMAKEROOT
.MAKEFILES : makefile.mk makefile
.SOURCE : .NULL
DMAKEROOT *=3D $(ABSMAKECMD:d)startup
MAKESTARTUP :=3D $(DMAKEROOT)\startup.mk
Please read the NEWS file for the latest release notes.
#########################
Is there anything at http://www.perlmonks.org/index.pl?node_id=3D603230
that helps ? (If so, what ? It would be nice to get to the bottom of
this error once and for all :-)
Cheers,
Rob
------------------------------
Date: Sun, 19 Apr 2009 00:28:33 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: generic variable name possible?
Message-Id: <slrngukhg3.90k.whynot@orphan.zombinet>
On 2009-04-18, ela <ela@yantai.org> wrote:
>
> While I succeeded in producing generic file names, I found that I cannot
> name the file pointer ($PROBLEMFP in the following codes) generically. I
> have to keep unknown number of file pointers (depending on the number of
> lines in modellist, not known beforehand) open and therefore I have to
> create "n" $PROBLEMFP's. Is it possible to achieve this in Perl?
>
>
>
> #!/usr/bin/perl
where is yours C<use strict;> and C<use warnings;>?
> my ( $iteration, $modellist ) = @ARGV;
>
> open( my $FPM, '<', "$modellist") or die "could not open '$modellist' $!";
>
> $lineM = <$FPM>;
> @models = split(/\t/, $lineM);
Strange, $modellist seems to be one-line of tab-separated filenames?
my %index;
> foreach (@models) {
> $modelscript = $_ . "_script.txt";
> $modellog = $_ . ".log";
$index{$_}{script} = $_ . "_script.txt";
$index{$_}{log} = $_ . ".log";
> ##########################
> open( my $PROBLEMFP, '>', "$modelscript") or die "could not open
> '$modelscript' $!";
Note lack of double-quotes around filename
open $index{$_}{fh}, '>', $index{script} or
die "could not open '$index{script}': $!";
And now most fascinating part, you can't
print $index{$_}{fh} "bwahaha\n";
read C<perldoc -f print> for solution. And be careful, number of open
filehandles is limited.
--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
------------------------------
Date: Sat, 18 Apr 2009 20:00:57 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Graphics programming
Message-Id: <48qku4p118v83ggh7rhoehtuu92r29tlqs@library.airnews.net>
My graphics skills are WAY rusty, and so I was thinking that instead of
struggling through GD:: and friends that I might get a text to help walk me
through it. Amazon has two Perl graphics books, Graphics Programming with
Perl by Martien Verbruggen and Perl Graphics Programming: Creating SVG, SWF
(Flash), JPEG and PNG files with Perl by Shawn Wallace. Both are quite old
[from 2002]. Any preferences on which of the two is better? I *THINK* I
don't need all that much help with things like homogeneous coordinates and
transforms and such than with the computer machinations necessary to get
objects rendered. Also, do either of the two cover 3D graphics?
THANKS! /bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: Sun, 19 Apr 2009 01:18:24 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Graphics programming
Message-Id: <g77qb6-l4a.ln1@osiris.mauzo.dyndns.org>
Quoth Bernie Cosell <bernie@fantasyfarm.com>:
> My graphics skills are WAY rusty, and so I was thinking that instead of
> struggling through GD:: and friends that I might get a text to help walk me
> through it. Amazon has two Perl graphics books, Graphics Programming with
> Perl by Martien Verbruggen and Perl Graphics Programming: Creating SVG, SWF
> (Flash), JPEG and PNG files with Perl by Shawn Wallace. Both are quite old
> [from 2002]. Any preferences on which of the two is better? I *THINK* I
> don't need all that much help with things like homogeneous coordinates and
> transforms and such than with the computer machinations necessary to get
> objects rendered. Also, do either of the two cover 3D graphics?
This isn't a book recommendation, but if you want to render 3D graphics
you may want to look at the OpenGL and OpenGL::Image modules. After that
I guess you'll need to find an OpenGL book, if you don't already have
one :).
Ben
------------------------------
Date: Sat, 18 Apr 2009 21:28:45 -0300
From: "Guy" <someone@somewhere.nb.ca>
Subject: Re: I'm looking for a Perl Book... I think.
Message-Id: <49ea7036$0$20972$9a566e8b@news.aliant.net>
> You don't need a 'server'. You just need a computer: the one you're
> posting from will probably do fine. If it's running Win32, you can get
> perl from strawberryperl.com; if it's a Mac, you've almost certainly got
> perl installed already. If it's running something else, let us know and
> we'll see if anyone knows how to get perl installed on it.
I'm running windows XP. I remember years ago I had installed winNT on a 2nd
computer and used its web server (apache I think) to test my scripts at
home. I don't have that option now and had never heard of StrawberryPerl. So
I tried Strawberry Perl as you suggested - I guess there's all sorts of Perl
flavors (no pun intended)!
I also did the following according to info I found, not sure what it did or
if I had to:
perl -MCPAN -e shell
install Bundle::CPAN
Then I checked my path and the version.
path
perl -v
Then I executed a "Hello World" script and it worked.
I'll be darned!
Guy
------------------------------
Date: 19 Apr 2009 01:40:54 GMT
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: I'm looking for a Perl Book... I think.
Message-Id: <49ea8125$0$694$c5fe31e7@read01.usenet4all.se>
On Fri, 17 Apr 2009 20:22:02 -0300, Guy wrote:
> But I see stuff like this, which appears to be related to cgi.pm, and
which
> I never really learned.
> use CGI qw/:standard/;
> $q = new CGI;
> @names = $q->param;
> $value = $q->param('t01');
> print $q->header,
> $q->start_html('hello world'),
> $q->end_html;
>
> Do I need a new book on Perl, or do I need a book on CGI.pm (if such a
thing
> exists). I'd like to understand this $q=new CGI stuff.
What you are trying to understand is so-called "object oriented perl".
The "new" creates a CGI object.
The "$q->param" etc. call the methods of the CGI object. Methods are
functions with a first argument $q, and the syntax "$q->param" is the
same as "param($q)".
You don't need a book to understand this.
------------------------------
Date: Sat, 18 Apr 2009 21:10:21 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: I'm looking for a Perl Book... I think.
Message-Id: <slrngul20d.b5v.tadmc@tadmc30.sbcglobal.net>
Guy <someone@somewhere.nb.ca> wrote:
Please provide an attribution when you quote someone.
>> perl from strawberryperl.com;
> I guess there's all sorts of Perl
> flavors
All Perls are oyster flavored of course.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sat, 18 Apr 2009 22:42:10 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: I'm looking for a Perl Book... I think.
Message-Id: <slrngul7ci.b5v.tadmc@tadmc30.sbcglobal.net>
Ben Bullock <benkasminbullock@gmail.com> wrote:
> and the syntax "$q->param" is the
> same as "param($q)".
No it isn't.
(and you do not need to know anything about a method's special
first argument in order to use an object oriented module.
You need to know that if you are going to _write_ an OO module.
)
-------------------------
#!/usr/bin/perl
use warnings;
use strict;
package Q;
sub new { bless {}, 'Q' }
sub param { print $_[0], "\n" }
package main;
my $q = Q->new();
$q->param();
Q::param($q);
param($q);
-------------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sat, 18 Apr 2009 23:47:21 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: What does `my' do?!
Message-Id: <ps1qb6-1e8.ln1@osiris.mauzo.dyndns.org>
Quoth Xho Jingleheimerschmidt <xhoster@gmail.com>:
[re: closures and named subs]
>
> You could change the named sub def to:
>
> eval q{sub foo {$x}};
<snip>
>
> You could put the anonymous sub def in a begin block, to prevent it from
> being compiled. It can't be done as elegantly as the string eval
> above, because you need to somewhere to stash value, but it can be done.
>
<snip>
>
> Sure, anonymous subs are more useful in such situations, but I think
> that what triggers recompilation is an accident of the language, and not
> the essence of a closure. I think the essence of a closure is what it
> does with lexical variables at the time it is compiled. So I think a
> named sub is still a closure, it is just one that has an implicit BEGIN
> block around it, and so only compiles once unless you take steps to
> change that.
Ummm... I'm having trouble here arguing only from Perl-visible
behaviour :). The important point as I see it is that an anon sub has
CvCLONE set, so when the 'sub' statement is executed at runtime a new CV
is created with a pointer to the original optree (which was compiled at
compile time) and a new pad with refs to the currently-outer lexicals.
Certainly this behaviour is not an accident: there is considerable
effort expended to make closures function properly.
The question is, what difference does that make to a Perl programmer?
One difference I think is important but you may not between
for my $x (1..2) {
push @cvs, sub { $x };
}
and
for my $x (1..2) {
eval "sub foo { \$x }";
push @cvs = \&foo;
}
is that in the first case the anon sub is only compiled at compile time,
and both copies get the same optree, whereas in the second they are
(separately) compiled at runtime and each gets a different optree (that
happen to do the same thing). I would say that the first gives multiple
instances of a single closure, whereas the second gives multiple subrefs
that happen to do similar things to different variables. When I put it
like that it's hard not to say the distinction is purely academic :).
Ben
------------------------------
Date: Sat, 18 Apr 2009 16:03:42 -0700 (PDT)
From: derykus@gmail.com
Subject: Re: What does `my' do?!
Message-Id: <a661bdab-2bbd-4ec1-886a-b89cfd63b2e8@d25g2000prn.googlegroups.com>
On Apr 18, 1:32=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Ilya Zakharevich <nospam-ab...@ilyaz.org>:
>
>
>
> > Another sigh... =A0*If* the things were this simple...
>
> > =A0 perl -wle "my $x =3D 12, $x =3D 13; print $x"
> > =A0 Name "main::x" used only once: possible typo at -e line 1.
> > =A0 12
>
> > So `my $x' has a runtime effect too: it puts the "new" $x on
> > stack - as different from plain `$x', which puts the "current" $x on
> > stack. =A0And to muddy things yet more, the switch of the "current" $x
> > to the new value happens at time of `;' - which I consider a very
> > brain-damaged decision...
>
> Even weirder:
>
> =A0 =A0 ~% perl -le'$x =3D ($x =3D 5) + 1; print $x'
> =A0 =A0 6
> =A0 =A0 ~% perl -le'my $x =3D (my $x =3D 5) + 1; print $x'
> =A0 =A0 5
> ~%
>
> :)
Hm,
perl -wle 'my $x =3D (my $x =3D 5) + 1; print $x'
"my" variable $x masks earlier declaration in same statement at -e
line 1.
But I see your smiley ... punchline ?
--
Charles DeRykus
------------------------------
Date: Sat, 18 Apr 2009 23:48:36 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrngukpmk.a5b.nospam-abuse@chorin.math.berkeley.edu>
On 2009-04-18, Nathan Keel <nat.k@gm.ml> wrote:
> Ilya Zakharevich wrote:
>
>> Another sigh... *If* the things were this simple...
>>
>> perl -wle "my $x = 12, $x = 13; print $x"
>> Name "main::x" used only once: possible typo at -e line 1.
>> 12
>
> Things are *nearly* that simple. While your points are valid in that
> there's more to it, who in the world would write code like that?
I would do all the time, if it were possible...
defined (my $foo = bar) and some_call($foo).
Thanks for your praises,
Ilya
------------------------------
Date: Sat, 18 Apr 2009 23:56:38 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrngukq5m.a5b.nospam-abuse@chorin.math.berkeley.edu>
On 2009-04-18, Ben Morrow <ben@morrow.me.uk> wrote:
> for my $x (1..2) {
> push @cvs, sub { $x };
> }
>
> and
>
> for my $x (1..2) {
> eval "sub foo { \$x }";
> push @cvs = \&foo;
> }
>
> is that in the first case the anon sub is only compiled at compile time,
> and both copies get the same optree, whereas in the second they are
> (separately) compiled at runtime and each gets a different optree (that
> happen to do the same thing). I would say that the first gives multiple
> instances of a single closure, whereas the second gives multiple subrefs
> that happen to do similar things to different variables. When I put it
> like that it's hard not to say the distinction is purely academic :).
Now try this with 1..1e7 ... Or with -w...
Ilya
------------------------------
Date: Sun, 19 Apr 2009 01:12:27 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: What does `my' do?!
Message-Id: <bs6qb6-l4a.ln1@osiris.mauzo.dyndns.org>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2009-04-18, Ben Morrow <ben@morrow.me.uk> wrote:
> > for my $x (1..2) {
> > push @cvs, sub { $x };
> > }
> >
> > and
> >
> > for my $x (1..2) {
> > eval "sub foo { \$x }";
> > push @cvs = \&foo;
> > }
> >
> > is that in the first case the anon sub is only compiled at compile time,
> > and both copies get the same optree, whereas in the second they are
> > (separately) compiled at runtime and each gets a different optree (that
> > happen to do the same thing). I would say that the first gives multiple
> > instances of a single closure, whereas the second gives multiple subrefs
> > that happen to do similar things to different variables. When I put it
> > like that it's hard not to say the distinction is purely academic :).
>
> Now try this with 1..1e7 ... Or with -w...
Yes, I was ignoring the warnings for the sake of the discussion. I
should probably have made that clear.
The question of memory usage is important in some cases, but not really
relevant to the semantics. For one thing, a CvCLONED CV uses some memory
itself, so running out of memory for cloned anon subs is just a matter
of tweaking the numbers a little higher...
Ben
------------------------------
Date: Sun, 19 Apr 2009 02:54:34 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrngul501.bec.nospam-abuse@chorin.math.berkeley.edu>
On 2009-04-19, Ben Morrow <ben@morrow.me.uk> wrote:
> The question of memory usage is important in some cases, but not really
> relevant to the semantics.
To the contrary. If you ignore the memory usage and speed, there is
absolutely no point in having closures (for languages with eval()).
But you already noticed this...
> For one thing, a CvCLONED CV uses some memory itself, so running out
> of memory for cloned anon subs is just a matter of tweaking the
> numbers a little higher...
If this were relevant, we would all run with 64K of memory, and would
satisfy the rest from swap. 1/2 ;-) [I assume that implement-swapping
code fits in 64K; I would not be surprised if with contemporary
Winlixes this is not true ;-]
Yours,
Ilya
------------------------------
Date: Sat, 18 Apr 2009 17:18:42 -0700 (PDT)
From: kun niu <haoniukun@gmail.com>
Subject: Re: What's wrong with the following regular expression?
Message-Id: <8dcc907c-c54d-4898-88bb-8fd12f4aba97@d38g2000prn.googlegroups.com>
On 4=D4=C219=C8=D5, =C9=CF=CE=E72=CA=B135=B7=D6, J=A8=B9rgen Exner <jurge..=
.@hotmail.com> wrote:
> kun niu <haoniu...@gmail.com> wrote:
> >And do you have any other recommendation for html parsing except
> >regex?
> >Would html::parser be faster?
>
> No, but it would do it correctly.
>
> This has been discussed many, many times over. And there is only this
> 'sln' guy, how still believes a non-regular language (HTML) could be
> parsed by regular expressions. Of course he still owes the proof that
> Chomsky was wrong.
>
> jue
Sorry for my poor knowledge in this field.
And thank you for point me the way.:)
------------------------------
Date: Sat, 18 Apr 2009 17:25:38 -0700 (PDT)
From: kun niu <haoniukun@gmail.com>
Subject: Re: What's wrong with the following regular expression?
Message-Id: <7a0a281b-686c-465f-9073-19800f3f068d@f1g2000prb.googlegroups.com>
On 4=D4=C219=C8=D5, =C9=CF=CE=E73=CA=B134=B7=D6, Lars Eighner <use...@larse=
ighner.com> wrote:
> In our last episode,
> <671aab8b-f4df-4502-8d64-8d8b3b509...@c18g2000prh.googlegroups.com>, the
> lovely and talented kun niu broadcast on comp.lang.perl.misc:
>
> > In case that you have a perl intrepreter, you can try it.
> > It gives the right value at least for me.:)
> > And do you have any other recommendation for html parsing except
> > regex?
> > Would html::parser be faster?
>
> No, but it would be robust. You are scraping e-mail addresses. It is
> difficult to imagine a morally acceptable reason for doing this, but more=
to
> the point, you don't have control of the original documents. You don't k=
now
> that the documents were valid to begin with, you don't know what variatio=
ns
> may be in the scraped A tags, and so forth. Without thinking about it, I
> can see three ways your regex can fail with real-world data. You could
> patch those up, and then you could deal with the ways it fails that I don=
't
> see immediately. Eventually the code is not readable, not maintainable, =
and
> still not right.
>
> Yes, yes, yes. I have used regex to write a quick and dirty one-liner to
> make a small change in a stack of documents that I had created and that I
> knew no one had mucked with. It's still nuts to use regex for html in a
> production script.
>
> > Thanks again for your reply.
>
> --
> Lars Eighner <http://larseighner.com/> use...@larseighner.com
> 88 days since Rick Warren prayed over Bush's third term.
> Obama: No hope, no change, more of the same. Yes, he can, but no, he w=
on't.
Though, truly, the code is not for use in production environment,
it's still valuable for me to know my shortcomings.:-)
------------------------------
Date: Sat, 18 Apr 2009 17:31:13 -0700 (PDT)
From: kun niu <haoniukun@gmail.com>
Subject: Re: What's wrong with the following regular expression?
Message-Id: <8b7e25e5-f47b-4dac-bb03-9f6b13857dd4@y6g2000prf.googlegroups.com>
On 4=D4=C219=C8=D5, =C9=CF=CE=E74=CA=B109=B7=D6, Tad J McClellan <ta...@see=
sig.invalid> wrote:
> kun niu <haoniu...@gmail.com> wrote:
> > $content =3D "<a href=3D\"mailto:t...@google.com\"><a class=3D\"hello\"=
href=3D
>
> ^^^^^^^
>
> > \"mailto:t...@google.com?title=3Dhello\">";
>
> You should always enable warnings when developing Perl code.
>
> > @emails =3D ($content =3D~ /<a.*href=3D"mailto:(.*)>"/cgim);
>
> ^^
> ^^ these are transposed...
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
Thank you for your reply.
But I wonder how @emails =3D ($content =3D~ /<a.*href=3D"mailto:(.*)>"/
cgim); is transposed.
I turned on warnings with "perl -w" and I don't see a warning here.
------------------------------
Date: Sat, 18 Apr 2009 21:07:21 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: What's wrong with the following regular expression?
Message-Id: <slrngul1qp.b5v.tadmc@tadmc30.sbcglobal.net>
kun niu <haoniukun@gmail.com> wrote:
> On 4??19??, ????4??09??, Tad J McClellan <ta...@seesig.invalid> wrote:
>> kun niu <haoniu...@gmail.com> wrote:
>> > $content = "<a href=\"mailto:t...@google.com\"><a class=\"hello\" href=
^^
^^
The data has a quote followed by an angle bracket.
>> > \"mailto:t...@google.com?title=hello\">";
>>
>> You should always enable warnings when developing Perl code.
>>
>> > @emails = ($content =~ /<a.*href="mailto:(.*)>"/cgim);
>>
>> ^^
>> ^^ these are transposed...
The word "transposed" means "order is reversed"...
>> --
>> Tad McClellan
>> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
It is bad manners to quote .sigs.
> But I wonder how @emails = ($content =~ /<a.*href="mailto:(.*)>"/
^^
^^
The pattern has an angle bracket followed by a quote.
> I turned on warnings with "perl -w" and I don't see a warning here.
The warning (Possible unintended interpolation) was from the
assignment line, not the pattern line.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
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 V11 Issue 2352
***************************************