[31105] in Perl-Users-Digest
Perl-Users Digest, Issue: 2350 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 18 14:09:49 2009
Date: Sat, 18 Apr 2009 11:09:14 -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: 2350
Today's topics:
A Perl module for autoformatting C program <struggleyb.nku@gmail.com>
Re: A Perl module for autoformatting C program <tadmc@seesig.invalid>
Re: A Perl module for autoformatting C program <ben@morrow.me.uk>
Re: effienct way to select random value from the hash <whynot@pozharski.name>
generic variable name possible? <ela@yantai.org>
Re: generic variable name possible? <haoniukun@gmail.com>
how to redirect stdout to wx::textctrl? thanks <abbypan@gmail.com>
Re: how to redirect stdout to wx::textctrl? thanks <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. <tadmc@seesig.invalid>
Re: I'm looking for a Perl Book... I think. <cartercc@gmail.com>
Re: I'm looking for a Perl Book... I think. <cartercc@gmail.com>
Re: I'm looking for a Perl Book... I think. <someone@somewhere.nb.ca>
Re: Module Win32::API and DLL with Windows Visual C++ <sisyphus359@gmail.com>
Re: perls popularity <unclebob@tnglwood.demon.co.uk>
Re: What does `my' do?! <nospam-abuse@ilyaz.org>
Re: What does `my' do?! <nospam-abuse@ilyaz.org>
Re: What does `my' do?! <nospam-abuse@ilyaz.org>
Re: What does `my' do?! <nospam-abuse@ilyaz.org>
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? <usenet@larseighner.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 18 Apr 2009 07:05:52 -0700 (PDT)
From: byang <struggleyb.nku@gmail.com>
Subject: A Perl module for autoformatting C program
Message-Id: <42527c70-0413-4ba3-8e4e-28ed49af8fd3@v23g2000pro.googlegroups.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!
Regards!
Bo
------------------------------
Date: Sat, 18 Apr 2009 10:09:41 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: A Perl module for autoformatting C program
Message-Id: <slrngujr9l.3gp.tadmc@tadmc30.sbcglobal.net>
byang <struggleyb.nku@gmail.com> wrote:
> 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
Why do you care what language is used to implement the program
you are looking for?
Googling for "C beautifier" finds a boatload of already written
pretty printers for C.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sat, 18 Apr 2009 16:13:43 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: A Perl module for autoformatting C program
Message-Id: <7a7pb6-mr4.ln1@osiris.mauzo.dyndns.org>
Quoth byang <struggleyb.nku@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.
Ben
------------------------------
Date: Sat, 18 Apr 2009 14:52:12 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: effienct way to select random value from the hash
Message-Id: <slrngujfq4.pr6.whynot@orphan.zombinet>
On 2009-04-16, Jürgen Exner <jurgenex@hotmail.com> wrote:
*SKIP*
> I don't know for sure, but treating $hashref as a reference to an array
> might do the trick already.
No, it doesn't
{2565:11} [0:0]$ perl -Mstrict -wle 'my $x= { a => "b" }; print scalar @$x'
Not an ARRAY reference at -e line 1.
However,
{2565:11} [0:0]$ perl -Mstrict -wle 'my $x= { a => "b" }; print scalar(() = %$x)'
2
And one more point of concern: serializing hash into array is a subject
of Perl's own key reordering. Maybe just do it once?
--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
------------------------------
Date: Sun, 19 Apr 2009 00:17:42 +0800
From: "ela" <ela@yantai.org>
Subject: generic variable name possible?
Message-Id: <gscuf4$n3k$1@ijustice.itsc.cuhk.edu.hk>
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
my ( $iteration, $modellist ) = @ARGV;
open( my $FPM, '<', "$modellist") or die "could not open '$modellist' $!";
$lineM = <$FPM>;
@models = split(/\t/, $lineM);
foreach (@models) {
$modelscript = $_ . "_script.txt";
$modellog = $_ . ".log";
##########################
open( my $PROBLEMFP, '>', "$modelscript") or die "could not open
'$modelscript' $!";
}
------------------------------
Date: Sat, 18 Apr 2009 09:58:10 -0700 (PDT)
From: kun niu <haoniukun@gmail.com>
Subject: Re: generic variable name possible?
Message-Id: <86e56129-2910-4ad1-b011-7b35661fb38b@f1g2000prb.googlegroups.com>
On 4=D4=C219=C8=D5, =C9=CF=CE=E712=CA=B117=B7=D6, "ela" <e...@yantai.org> w=
rote:
> 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
> my ( $iteration, $modellist ) =3D @ARGV;
>
> open( my $FPM, '<', "$modellist") or die "could not open '$modellist' $!"=
;
>
> $lineM =3D <$FPM>;
> @models =3D split(/\t/, $lineM);
>
> foreach (@models) {
> $modelscript =3D $_ . "_script.txt";
> $modellog =3D $_ . ".log";
>
> ##########################
> open( my $PROBLEMFP, '>', "$modelscript") or die "could not open
> '$modelscript' $!";
>
> }
>
>
Here's part of my code:
$file =3D "test.txt";
@test =3D (1,2);
foreach(@test)
{
open($_, ">", $file) or die "could not open $file, $!\n";
}
How about put all your fp in an array and open them separately?
------------------------------
Date: Sat, 18 Apr 2009 09:49:25 -0700 (PDT)
From: lsyx <abbypan@gmail.com>
Subject: how to redirect stdout to wx::textctrl? thanks
Message-Id: <50dfc51b-bca1-460b-bf27-86f67c7b40fe@w31g2000prd.googlegroups.com>
Code:
##################
#!/usr/bin/perl
use strict;
use warnings;
use Wx;
use threads;
use threads::shared qw/shared_clone/;
package MyFrame;
use Wx qw(wxTE_MULTILINE);
use base qw/Wx::Frame/;
sub new
{
my ( $class, $frame, $title, $x, $y, $w, $h ) = @_;
my ($this) = $class->SUPER::new(
$frame, -1, $title,
Wx::Point->new( $x, $y ),
Wx::Size->new( $w, $h ) );
my $notebook = Wx::Notebook->new( $this, -1 );
my $log = Wx::TextCtrl->new(
$notebook, -1, "test\n",
[ 10, 10 ],
[ 500, 300 ],
wxTE_MULTILINE
);
$this;
} ## end sub new
#}
#{
package MyApp;
use strict;
use base qw/Wx::App/;
sub OnInit
{
my ($this) = @_;
my ($frame) =
MyFrame->new( undef, "test", 50, 50, 540,
430 );
$frame->SetSizeHints( 500, 425 );
$frame->Show(1);
$this->SetTopWindow($frame);
1;
} ## end sub OnInit
package main;
my $gui = MyApp->new();
my $worker = threads->create( \&work );
$gui->MainLoop();
sub work {
print "abcdefgh\n";
}
##############
how to put
work() 's out text : abcdefgh
into
my $log = Wx::TextCtrl 's window ?
thanks for your help.
------------------------------
Date: Sat, 18 Apr 2009 18:22:14 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: how to redirect stdout to wx::textctrl? thanks
Message-Id: <6repb6-b66.ln1@osiris.mauzo.dyndns.org>
Quoth lsyx <abbypan@gmail.com>:
[ see subject ]
I would use Tie::Simple to tie *STDOUT with a PRINT method that does
whatever is necessary to write to the TextCtrl.
Ben
------------------------------
Date: Sat, 18 Apr 2009 11:10:57 -0300
From: "Guy" <someone@somewhere.nb.ca>
Subject: Re: I'm looking for a Perl Book... I think.
Message-Id: <49e9df6d$0$5471$9a566e8b@news.aliant.net>
"Tad J McClellan" <tadmc@seesig.invalid> a écrit dans le message de news:
slrngui9kv.qpg.tadmc@tadmc30.sbcglobal.net...
> Guy <someone@somewhere.nb.ca> wrote:
>
>> The only book I have on Perl is: "Perl5 for Web programming" circa 1998.
>
>> 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;
>
>
> Where did you find this code?
>
> One line is for using the CGI module in a function-oriented manner
> while another line is for using the CGI module in an object-oriented
> manner.
>
> Sensible programs use only one or the other, not both at the same time.
>
> I suggest not using wherever it was that you picked up that code.
>
>
>> Do I need a new book on Perl,
>
>
> You needed a different Perl book even in 1998.
>
> You would probably benefit from a Perl book written in the modern era.
I just got back from our largest bookstore. There was only one book on Perl:
"Learning Perl" by O'Reilly.
It said something like "you can use CGI.pm but it's not covered in this
book".
That's what my current book says, so I didn't buy it.
Their computer lists a book on CGI.pm (I think by Lincoln Stein) but it was
published in 1998. In any case, they didn't have it on the shelf. I never
bought a 10 year old computer book before, but I'd still like to familiarize
myself with the CGI.pm library.
But then again, I think it's the Object Oriented stuff that I'd really like
to learn too. like this $q = new CGI; which I think creates instances of CGI
or something, or is this just part of CGI.pm??
Maybe I'll have to try and learn this online, but I'd much prefer there were
a good book I could read, I seem to learn more from reading books.
Thanks again for all your input.
Guy
------------------------------
Date: Sat, 18 Apr 2009 10:06:40 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: I'm looking for a Perl Book... I think.
Message-Id: <slrngujr40.3gp.tadmc@tadmc30.sbcglobal.net>
Guy <someone@somewhere.nb.ca> wrote:
>
> "Tad J McClellan" <tadmc@seesig.invalid> a écrit dans le message de news:
> slrngui9kv.qpg.tadmc@tadmc30.sbcglobal.net...
>> Guy <someone@somewhere.nb.ca> wrote:
>>
>>> The only book I have on Perl is: "Perl5 for Web programming" circa 1998.
>>
>>> 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;
>>
>>
>> Where did you find this code?
This was not a rhetorical question.
I really would like to know where you got that code from.
> I just got back from our largest bookstore. There was only one book on Perl:
There are 173 Perl books at:
http://www.nerdbooks.com/search.php?search=title%5Bperl%5D%26display%3D%5Btitle%3A+perl%5D
( but about 150 of them are not worth the effort of reading them... )
> "Learning Perl" by O'Reilly.
>
> It said something like "you can use CGI.pm but it's not covered in this
> book".
CGI.pm is not a large enough topic to be a stand-alone book.
> I'd still like to familiarize
> myself with the CGI.pm library.
Have you tried reading the documentation for CGI.pm that comes with CGI.pm?
That was not a rhetorical question either.
> But then again, I think it's the Object Oriented stuff that I'd really like
> to learn too.
You need to learn about 0.1% of object oriented Perl programming
in order to use the object-oriented manner of CGI.pm for parsing
form parameters.
use CGI;
my $q = CGI->new();
my $price = $q->param('sale_price');
That's it!
Learning OO is a good idea, but is not required if all you want to
do is parse form parameters with CGI.pm.
> Maybe I'll have to try and learn this online,
I don't recommend that approach.
There is way more crap than there is good stuff on the interweb,
and when you're new you won't be able to tell the difference...
Your very first attempt should be to see if you can learn what
you need to know from Perl's standard documentation.
If that doesn't work, then...
> but I'd much prefer there were
> a good book I could read, I seem to learn more from reading books.
... a book might be a good idea.
"Learning Perl" is the 1st in a series of 3 Perl tutorial books. It
does not cover OO programming.
"Intermediate Perl" is the 2nd, and it does cover OO.
"Mastering Perl" is the 3rd in the series.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sat, 18 Apr 2009 10:01:37 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: I'm looking for a Perl Book... I think.
Message-Id: <f3f13985-7e3d-4992-a69e-73759bc9aaf7@k8g2000yqn.googlegroups.com>
On Apr 17, 7:22=A0pm, "Guy" <some...@somewhere.nb.ca> wrote:
> Ok, I'm creating my own website on genealogy.
Guy, THE BOOK you need is Paul Dubois, MySQL and Perl for the web.
It's rather old, but not really out of date, and does more than any
book I know of to walk you through what you need to do.
Two cautions: (1) It assumes familiarity with system administration,
server administration, Perl, and SQL. If you are a beginner at any of
these, you need to remediate yourself before reading the book. (2) It
uses both CGI to output HTML and references extensively, so you need
to bone up on CGI and references. I personally don't use CGI to
generate HTML so that doesn't bother me, but I had to really get
familiar with Perl references before the book began to make sense.
CC
------------------------------
Date: Sat, 18 Apr 2009 10:13:17 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: I'm looking for a Perl Book... I think.
Message-Id: <7fe130d1-6064-4447-b600-5e61a5678940@c12g2000yqc.googlegroups.com>
On Apr 18, 10:10=A0am, "Guy" <some...@somewhere.nb.ca> wrote:
> I just got back from our largest bookstore. There was only one book on Pe=
rl:
> "Learning Perl" by O'Reilly.
Look on amazon.com and half.com. I haven't bought a book in a
bookstore for years, and am quite happy with used books. (Buying used
books isn't like buying used food. ;-)).
> That's what my current book says, so I didn't buy it.
You don't need to use much CGI, and I have a strong distaste for using
CGI to generate my HTML. Of course, this is simply a matter of
personal preference.
>
> Their computer lists a book on CGI.pm (I think by Lincoln Stein) but it w=
as
> published in 1998. =A0In any case, they didn't have it on the shelf. =A0I=
never
> bought a 10 year old computer book before, but I'd still like to familiar=
ize
> myself with the CGI.pm library.
Depends. I'm currently (re)reading a 20 year old book and getting a
lot out of it. Most of my Perl books are old books. Once you get the
basics and learn the documentation, you shouldn't need the book, just
read the documentation. Perl has particularly good documentation -
it's clear, up-to-date, and widely available. (My 20 y.o. book is a vi
manual.)
> But then again, I think it's the Object Oriented stuff that I'd really li=
ke
> to learn too. like this $q =3D new CGI; which I think creates instances o=
f CGI
> or something, or is this just part of CGI.pm??
You're much better off spending your time elsewhere if you're mainly
interested in web stuff. For example, I think that Higher Order Perl
(Dominus) is more useful than Object Oriented Perl (Conway) for just
increasing your effectiveness as a developer. I'm not critical of OOP,
it's an excellent book and well worth your study, but for me HOP was
more immediately useful. Besides, you don't really need object
oriented programming if all you're doing is building a web app.
> a good book I could read, I seem to learn more from reading books.
I'm a dead tree guy myself, so I know exactly what you mean. Another
good book for your interests is Diane Zak, CGI/Perl, Course
Technology.
CC
------------------------------
Date: Sat, 18 Apr 2009 14:52:51 -0300
From: "Guy" <someone@somewhere.nb.ca>
Subject: Re: I'm looking for a Perl Book... I think.
Message-Id: <49ea136f$0$5502$9a566e8b@news.aliant.net>
>>>> 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;
>>>
>>>
>>> Where did you find this code?
>
>
> This was not a rhetorical question.
>
> I really would like to know where you got that code from.
Sorry, it was just a few lines of code that I had pasted together there
myself, I didn't find it whole like that.
> Have you tried reading the documentation for CGI.pm that comes with
> CGI.pm?
>
> That was not a rhetorical question either.
I bought some web space and asked that I could use Perl. I was just given a
username and a password and a domain name. I didn't install the webserver.
> "Learning Perl" is the 1st in a series of 3 Perl tutorial books. It
> does not cover OO programming.
>
> "Intermediate Perl" is the 2nd, and it does cover OO.
>
> "Mastering Perl" is the 3rd in the series.
>
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
I appreciate all your help, thanks to all,
Guy
------------------------------
Date: Sat, 18 Apr 2009 05:53:59 -0700 (PDT)
From: sisyphus <sisyphus359@gmail.com>
Subject: Re: Module Win32::API and DLL with Windows Visual C++
Message-Id: <8cf48cd3-1da5-4ccc-87de-4120ef384358@k19g2000prh.googlegroups.com>
On Apr 18, 2:48=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth jc <jc_user...@aanet.com.au>:
> > I am not sure if Win32::API is the appropriate tool for accessing user
> > DLLs. ??
>
> Well, there are several alternatives. The most long-winded and most
> likely to work successfully is to write a proper XS module that wraps
> the DLL. If you find XS too complicated, you could use Inline::C to do
> the grunt-work for you, though IME it brings its own list of
> complications I prefer to do without.
For mine, Win32::API is *not* the ideal way to access user DLLs
unless:
1) you don't have a C compiler
or
2) your C compiler cannot link to DLLs directly (ie needs to link to
an import lib) and you don't have an import library for that DLL.
With Strawberry Perl, neither 1) nor 2) will be the case (as
Strawberry Perl comes with the MinGW port of the gcc compiler - which
is a C compiler that can link directly to a DLL if need be).
With ActiveState Perl neither 1) nor 2) will be the case if you first
'ppm install MinGW'.
Ben's advice is, as always, sound. But don't let his recommendations
deter you from using Inline::C which is a powerful and flexible tool
that allows you to take the XS solution without having to learn how to
write an XS file. (You may need to become familiar with the perl API,
however - 'perldoc perlapi'.)
And feel free to use Inline::C with windows system DLLs too:
use Inline C =3D> DATA =3D>
MYEXTLIB =3D> 'C:/windows/system32/user32.dll';
$text =3D "@ARGV" || 'Inline.pm works with MSWin32. Scary...';
WinBox('Inline Text Box', $text);
__END__
__C__
int WinBox(char* Caption, char* Text) {
return MessageBoxA(0, Text, Caption, 0);
}
That's based on an example in the Inline::C-Cookbook documentation -
it links directly to user32.dll. To use that script with a Microsoft
Compiler you'd have to replace:
MYEXTLIB =3D> 'C:/windows/system32/user32.dll';
with
LIBS =3D> '-luser32';
With MinGW, both of those 2 variations work (assuming user32.dll is in
C:/windows/system32, of course).
Once your Inline::C solution has been written you can always convert
to XS (and avoid the dependency upon Inline) using
<plug>InlineX::C2XS</plug>, again without having to go to the trouble
of writing the XS file yourself.
Cheers,
Rob
------------------------------
Date: Sat, 18 Apr 2009 09:15:00 +0100
From: Robert Billing <unclebob@tnglwood.demon.co.uk>
Subject: Re: perls popularity
Message-Id: <9_fGl.21490$NW7.8074@newsfe25.ams2>
Nathan Keel wrote:
> sln@netherlands.com wrote:
>> I'm pretty sure unix or any other admins brains can hardly make thier
>> legs work let alone do Perl.
>>
>> This as your intro to this topic gives you a big 5-thumbs down!
>>
>> -sln
>
> I can't make sense of your reply. Anyway, I said any *good* admin. Any
> good admin will be smart and they can figure plenty of things out. If
> they aren't smart, they won't be a good admin or a good coder.
> Apparently your idea of what an admin is or does is different than the
> rest of the world.
I couldn't make any sense of his reply to my posting about UTF8 either.
I suspect the tinfoil in his bowler hat has become damp.
--
I am Robert Billing, Christian, author, inventor, traveller, cook and
animal lover. "It burned me from within. It quickened; I was with book
as a woman is with child."
Quality e-books for portable readers: http://www.alex-library.com
------------------------------
Date: Sat, 18 Apr 2009 17:06:49 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrnguk25a.6ug.nospam-abuse@chorin.math.berkeley.edu>
On 2009-04-17, Ben Morrow <ben@morrow.me.uk> wrote:
>> > perl -wle "eval shift; delayed()" "my $x; $x=12; sub delayed {print $x}"
>> > 12
>> > *After* `eval' is executed, the scope of $ARGV[0] is exited. But as
>> > you see (and this is *very expected*), $x is not cleared on scope
>> > exit.
>> Yor code example represents a closure wherein the value of a lexical
Wrong - already discussed.
>> variable declared outside of its scope gets captured. As usual, $x is
>> cleared at the end of the scope of $ARGV[0]
As my example shows, it's value is 12. So it is not "cleared".
Hope this helps,
Ilya
------------------------------
Date: Sat, 18 Apr 2009 17:28:44 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrnguk3ed.6ug.nospam-abuse@chorin.math.berkeley.edu>
On 2009-04-16, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>> pp_hot.c... it appears that 'my' actually clears the variable on scope
>> *exit*, not when the 'my' is encountered at runtime, and this has been
>> there since at least 5.000. I suppose it makes sense: since we must
>> clear the variable on scope exit (to get timely destruction), there's no
>> point clearing it on scope entry as well.
> Why it is not completely correct:
>
> perl -wle "eval shift; delayed()" "my $x; $x=12; sub delayed {print $x}"
> 12
>
> *After* `eval' is executed, the scope of $ARGV[0] is exited. But as
> you see (and this is *very expected*), $x is not cleared on scope
> exit.
I remembered the "meta-explanation of what happens" I made for myself
when I was fixing/developing this stuff...
The variable is "renewed" at the end of scope, not "cleared".
A new, completely fresh copy of the variable is made, which has no
relationship to "the old copy". (As if Perl accesses a variable
through a reference, and now stores at this location a reference to
another variable.)
After this (and until end-of-scope is reached again), this new copy is
accessed through $x in this scope.
BUT: embedded subroutines maintain their own "references to
variables"; since they "do not own" $x, no "renewing" is made in
their end-of-scope. So they always access the reference to the
"first" $x:
perl -wle "for (0..1) { my $x; $x=12 unless $_; sub p{print $x}; p; p; print $x }"
12
12
12
12
12
Use of uninitialized value in print at -e line 1.
(Of course, closures behave in yet slightly different ways... Sigh,
I did not want to document it yet, and STILL do not know how to
express it short-clear-not-ambiguously-and-correct...)
Ilya
P.S. Of course, when one creates a reference to a completely new
variable, there is no guaranties that anything changes! *IF*
somebody else was keeping a reference to the old variable, then
one MUST get something distinct. However, if it was only you
who referenced the variable, you can get back the same "slot".
This is similar to doing free()+malloc(): you can get back the
same buffer; the difference is that Perl guaranties that *new*
values are undef. (As if malloc() in C would always reset
memory buffers to 0...)
------------------------------
Date: Sat, 18 Apr 2009 17:55:40 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrnguk5d7.6ug.nospam-abuse@chorin.math.berkeley.edu>
On 2009-04-17, Tim McDaniel <tmcd@panix.com> wrote:
>>> >The run-time effect of "my" is that it marks the variable to be
>>> >cleared at the end of the current scope. That's all.
>>> To clarify, "that's all" in this example. The other run-time effect
>>> of "my" is that, if there be an initial value supplied (for example,
>>> on the right-hand side of "="), this assignment would be done at run
>>> time. (Ilya was expecting that, if there be no right-hand side, it
>>> would be set to undef, which is apparently not so.)
>>What? No. Perl is not C, and doesn't have a concept of
>>'initialization' distinct from ordinary assignment. Any assignment to
>>a newly created lexical is executed when control flow reaches that
>>point at runtime, just as with any other expression.
> We appear to be in vehement agreement: anything that looks like
> "initialization" in a "my" is not special, but is merely a standard
> run-time assignment like any other. (My use of "initial value" may
> have been inapt, especially in this example, where it's assigned in
> the BEGIN block.)
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
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. And 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...
Yours,
Ilya
------------------------------
Date: Sat, 18 Apr 2009 17:59:44 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrnguk5ks.6ug.nospam-abuse@chorin.math.berkeley.edu>
On 2009-04-17, sln@netherlands.com <sln@netherlands.com> wrote:
> Besides this unusual initialization/assignment thing, the docs specify
> BEGIN is wrapped in an eval when it is run, which I thought odd.
That's just for symmetry with END...
Hope this helps,
Ilya
------------------------------
Date: Sat, 18 Apr 2009 09:01:57 -0700 (PDT)
From: kun niu <haoniukun@gmail.com>
Subject: What's wrong with the following regular expression?
Message-Id: <0ebb61cb-61d0-4295-8c20-05b05c4f5972@n7g2000prc.googlegroups.com>
Dear all,
I'm trying to help to extrace email from company's website.
Here's part of my test script.
$content = "<a href=\"mailto:test@google.com\"><a class=\"hello\" href=
\"mailto:test@google.com?title=hello\">";
@emails = ($content =~ /<a.*href="mailto:(.*)>"/cgim);
foreach my $email (@emails)
{
print "email:" . $email . "\n";
}
But to my surprise, no result is printed.
I'm working on Debian squeeze.
My perl version is 5.10.0.
Would anyone here please help me out?
Thanks for any hints or advice in advance.
------------------------------
Date: Sat, 18 Apr 2009 09:11:21 -0700 (PDT)
From: kun niu <haoniukun@gmail.com>
Subject: Re: What's wrong with the following regular expression?
Message-Id: <45beda24-7f78-4891-8119-e879c505d50d@z23g2000prd.googlegroups.com>
On 4=D4=C219=C8=D5, =C9=CF=CE=E712=CA=B101=B7=D6, kun niu <haoniu...@gmail.=
com> wrote:
> Dear all,
>
> I'm trying to help to extrace email from company's website.
> Here's part of my test script.
>
> $content =3D "<a href=3D\"mailto:t...@google.com\"><a class=3D\"hello\" h=
ref=3D
> \"mailto:t...@google.com?title=3Dhello\">";
> @emails =3D ($content =3D~ /<a.*href=3D"mailto:(.*)>"/cgim);
> foreach my $email (@emails)
> {
> print "email:" . $email . "\n";}
>
> But to my surprise, no result is printed.
> I'm working on Debian squeeze.
> My perl version is 5.10.0.
> Would anyone here please help me out?
> Thanks for any hints or advice in advance.
I'm sorry thatthe script should be the following one:
$content =3D "<a href=3D\"mailto:test\@google.com\"><a class=3D\"hello\"
href=3D\"mailto:test\@google.com?title=3Dhello\">";
@emails =3D ($content =3D~ /<a.*href=3D"mailto:(.*)>"/cgim);
foreach my $email (@emails)
{
print "email:" . $email . "\n";
}
------------------------------
Date: Sat, 18 Apr 2009 17:10:30 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: What's wrong with the following regular expression?
Message-Id: <slrnguk284.2bon.usenet@debranded.larseighner.com>
In our last episode,
<45beda24-7f78-4891-8119-e879c505d50d@z23g2000prd.googlegroups.com>, the
lovely and talented kun niu broadcast on comp.lang.perl.misc:
> On 4??19??, ????12??01??, kun niu <haoniu...@gmail.com> wrote:
>> Dear all,
>>
>> I'm trying to help to extrace email from company's website.
>> Here's part of my test script.
>>
>> $content = "<a href=\"mailto:t...@google.com\"><a class=\"hello\" href=
>> \"mailto:t...@google.com?title=hello\">";
>> @emails = ($content =~ /<a.*href="mailto:(.*)>"/cgim);
>> foreach my $email (@emails)
>> {
>> print "email:" . $email . "\n";}
>>
>> But to my surprise, no result is printed.
>> I'm working on Debian squeeze.
>> My perl version is 5.10.0.
>> Would anyone here please help me out?
>> Thanks for any hints or advice in advance.
> I'm sorry thatthe script should be the following one:
> $content = "<a href=\"mailto:test\@google.com\"><a class=\"hello\"
> href=\"mailto:test\@google.com?title=hello\">";
> @emails = ($content =~ /<a.*href="mailto:(.*)>"/cgim);
> foreach my $email (@emails)
> {
> print "email:" . $email . "\n";
> }
First, parsing html with regular expressions is an extremely bad idea.
Second, regular expresions are greedy, so this provides at most one match.
Third, you have set up () to capture something. What did you do with it?
Answer: you did nothing with it.
Fourth, ($content =~ /<a.*href="mailto:(.*)>"/cgim) --- why do think this
could ever return anything besides TRUE or FALSE.
--
Lars Eighner <http://larseighner.com/> usenet@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 won't.
------------------------------
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 2350
***************************************