[31110] in Perl-Users-Digest
Perl-Users Digest, Issue: 2355 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 20 14:09:49 2009
Date: Mon, 20 Apr 2009 11:09:11 -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 Mon, 20 Apr 2009 Volume: 11 Number: 2355
Today's topics:
Re: Capturing Port Data <benkasminbullock@gmail.com>
Re: Capturing Port Data <XXjbhuntxx@white-star.com>
Re: Capturing Port Data <maustin@firstdbasource.com>
Re: Capturing Port Data <ben@morrow.me.uk>
Re: dmake.exe: Error: -- 'C:\Perl\libConfig.pm' not fou tuser1@gmail.com
Re: dmake.exe: Error: -- 'C:\Perl\libConfig.pm' not fou tuser1@gmail.com
Re: dmake.exe: Error: -- 'C:\Perl\libConfig.pm' not fou tuser1@gmail.com
Re: effienct way to select random value from the hash <whynot@pozharski.name>
Re: effienct way to select random value from the hash <smallpond@juno.com>
How can I backreference a ?: group in perl regular expr <haoniukun@gmail.com>
Re: How can I backreference a ?: group in perl regular <ben@morrow.me.uk>
Re: How can I backreference a ?: group in perl regular <haoniukun@gmail.com>
new CPAN modules on Mon Apr 20 2009 (Randal Schwartz)
Re: What does `my' do?! (Tim McDaniel)
Re: What does `my' do?! <willem@snail.stack.nl>
Re: What does `my' do?! <devnull4711@web.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Apr 2009 01:26:21 GMT
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Capturing Port Data
Message-Id: <49ebcf3c$0$734$c5fe31e7@read01.usenet4all.se>
On Sun, 19 Apr 2009 21:37:44 +0000, Cosmic Cruizer wrote:
> use strict;
> use warnings;
> use Net::Telnet;
>
> my $msg = 'GET /capacity HTTP/1.1';
> my $port = 5050;
> my $timeout = 5;
>
> my $telnet = new Net::Telnet (
> Timeout => $timeout,
> Errmode => 'die',
> Port => $port,);
>
> $telnet->open('66.163.181.177');
>
> if(!$telnet){
> print "No connection\n";
> }
You need to read the documentation of Net::Telnet more carefully.
------------------------------
Date: Mon, 20 Apr 2009 02:23:06 GMT
From: Cosmic Cruizer <XXjbhuntxx@white-star.com>
Subject: Re: Capturing Port Data
Message-Id: <Xns9BF2C526E3577ccruizermydejacom@207.115.33.102>
Ben Morrow <ben@morrow.me.uk> wrote in
news:anlsb6-e1j.ln1@osiris.mauzo.dyndns.org:
>
> Quoth Cosmic Cruizer <XXjbhuntxx@white-star.com>:
>> I could not get the yahoo modules to work, nor did I have success
>> with IO::Socket. So now I'm trying to use Net::Telnet. I think the
>> problem has to do with needing two returns after $msg. I've tried
>> using both print and cmd without success.
>>
>> Anybody know why I'm not able to capture the output?
>>
>> use strict;
>> use warnings;
>> use Net::Telnet;
>>
>> my $msg = 'GET /capacity HTTP/1.1';
>
> What's wrong with LWP::Simple?
>
> Ben
>
Hi Ben,
I read the info about LWP::Simple, but I don't see how that will help. I
should have been able to do this program using IO::Socket, but couldn't get
it to work. (I've written several other programs using IO::Socket without
running into this problem.) It appears the same issue that is preventing me
from being successful using IO::Socket is probably the same issue I am
encountering with Net::Telnet.
Thanks for the suggestion.
...Cos
------------------------------
Date: Mon, 20 Apr 2009 11:50:58 -0500
From: Michael Austin <maustin@firstdbasource.com>
Subject: Re: Capturing Port Data
Message-Id: <OL1Hl.25047$Ws1.4822@nlpi064.nbdc.sbc.com>
Ben Bullock wrote:
> On Sun, 19 Apr 2009 21:37:44 +0000, Cosmic Cruizer wrote:
>
>> use strict;
>> use warnings;
>> use Net::Telnet;
>>
>> my $msg = 'GET /capacity HTTP/1.1';
>> my $port = 5050;
>> my $timeout = 5;
>>
>> my $telnet = new Net::Telnet (
>> Timeout => $timeout,
>> Errmode => 'die',
>> Port => $port,);
>>
>> $telnet->open('66.163.181.177');
>>
>> if(!$telnet){
>> print "No connection\n";
>> }
>
> You need to read the documentation of Net::Telnet more carefully.
>
>
>
Looks like you are trying to log into a router and get the IP address...
As this is in this forum you may need to ensure proper line lengths if
you copy/paste.
this is what I have used for my linksys router for ages now...
#!/usr/bin/perl -w
## $ENV{'PATH'} = (exists($ENV{PATH}) ? "$ENV{PATH}:" : "") .
## "/sbin:/usr/sbin:/bin:/usr/bin:/etc:/usr/lib:";
use Getopt::Long;
use Sys::Hostname;
use IO::Socket;
sub encode_base64 ($;$) {
my $res = '';
my $eol = $_[1];
$eol = "\n" unless defined $eol;
pos($_[0]) = 0; # ensure start at the
beginning
while ($_[0] =~ /(.{1,45})/gs) {
$res .= substr(pack('u', $1), 1);
chop($res);
}
$res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
# fix padding at the end
my $padding = (3 - length($_[0]) % 3) % 3;
$res =~ s/.{$padding}$/'=' x $padding/e if $padding;
# break encoded string into lines of no more than 76 characters each
if (length $eol) {
$res =~ s/(.{1,76})/$1$eol/g;
}
$res;
}
$0 = "findIP";
my $version = "3.5.4";
my $programd = $0;
$programd =~ s%^.*/%%;
my $program = $programd;
$program =~ s/d$//;
my $now = time;
my $hostname = hostname();
my ($peer, $server, $port);
my ($sd, $rq, $request, $reply);
my $url = "HTTP://192.168.1.1:80/Status_Router.asp";
$url =~ s%^HTTP://%%i;
$server = $url;
$server =~ s%/.*%%;
$url = "/" unless $url =~ m%/%;
$url =~ s%^[^/]*/%%;
## determine peer and port to use.
$peer = $server;
$peer =~ s%/.*%%;
$port = $peer;
$port =~ s%^.*:%%;
$port = 80 unless $port =~ /^\d+$/;
$peer =~ s%:.*$%%;
my $auth = encode_base64("doesntmatter:mypassword");
$request = "GET ";
$request .= "/$url HTTP/1.0\n";
$request .= "Authorization: Basic $auth";
$request .= "User-Agent: ${program}/${version}\n";
$request .= "Connection: open\n";
$request .= "\n";
## make sure newlines are <cr><lf> for some pedantic proxy servers
($rq = $request) =~ s/\n/\r\n/g;
# uncomment the following for debug mode.
# printf("$rq");
local $^W = 0;
$sd = IO::Socket::INET->new(PeerAddr => $peer,
PeerPort => $port,
Proto => 'tcp');
my $skip='interipaddr';
my $DNS1='script>1';
my $DNS2='script>2';
my $DNS3='script>3';
my $result = send $sd, $rq, 0;
if ($result != length($rq)) {
printf("cannot send to 192.168.1.1:80 ($!).\n");
} else {
while ($_ = <$sd>) {
# verbose("RECEIVE:", "%s", define($_, "<undefined>"));
$reply .= $_ if defined $_;
}
# uncomment the following for debug mode - additional information
# printf(" $reply\n");
if ($reply =~
/${skip}.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/is)
{
$WANip = $1;
}
if ($reply =~
/${DNS1}.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/is)
{
$DNS1 = $1;
}
if ($reply =~
/${DNS2}.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/is)
{
$DNS2 = $1;
}
if ($reply =~
/${DNS3}.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/is)
{
$DNS3 = $1;
}
printf("Current IP address is: $WANip\n");
printf("DNS 1 IP address is: $DNS1\n");
printf("DNS 2 IP address is: $DNS2\n");
printf("DNS 3 IP address is: $DNS3\n");
close($sd);
}
sampleoutput (munged to protect the guilty :)
getip.pl
Current IP address is: 555.555.555.140
DNS 1 IP address is: 556.556.556.1
DNS 2 IP address is: 557.557.557.1
DNS 3 IP address is: script>3 <-- obviously this does not exist.
------------------------------
Date: Mon, 20 Apr 2009 18:36:56 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Capturing Port Data
Message-Id: <oeoub6-d413.ln1@osiris.mauzo.dyndns.org>
Quoth Cosmic Cruizer <XXjbhuntxx@white-star.com>:
> Ben Morrow <ben@morrow.me.uk> wrote in
> news:anlsb6-e1j.ln1@osiris.mauzo.dyndns.org:
>
> > Quoth Cosmic Cruizer <XXjbhuntxx@white-star.com>:
> >> I could not get the yahoo modules to work, nor did I have success
> >> with IO::Socket. So now I'm trying to use Net::Telnet. I think the
> >> problem has to do with needing two returns after $msg. I've tried
> >> using both print and cmd without success.
> >>
> >> Anybody know why I'm not able to capture the output?
> >>
> >> use strict;
> >> use warnings;
> >> use Net::Telnet;
> >>
> >> my $msg = 'GET /capacity HTTP/1.1';
> >
> > What's wrong with LWP::Simple?
>
> I read the info about LWP::Simple, but I don't see how that will help. I
> should have been able to do this program using IO::Socket, but couldn't get
> it to work. (I've written several other programs using IO::Socket without
> running into this problem.) It appears the same issue that is preventing me
> from being successful using IO::Socket is probably the same issue I am
> encountering with Net::Telnet.
Well, AFAICS you are trying to do a GET of
http://88.xx.xx.161:5050/capacity (sorry, I can't remember the exact IP
address). What happens if you simply pass that URL to LWP::Simple::get?
Ben
------------------------------
Date: Mon, 20 Apr 2009 02:05:29 -0700 (PDT)
From: tuser1@gmail.com
Subject: Re: dmake.exe: Error: -- 'C:\Perl\libConfig.pm' not found, and can't be made
Message-Id: <3d71c94c-bdad-4263-9778-afc6229b60e6@h2g2000yqg.googlegroups.com>
On Apr 20, 2:14=A0am, sisyphus <sisyphus...@gmail.com> wrote:
> On Apr 20, 9:39=A0am, tus...@gmail.com wrote:
>
> > On Apr 20, 1:29=A0am, tus...@gmail.com wrote:
> > I suspect this value should rather be "dmake" (am I right ?)- Hide quot=
ed text -
>
> No, I don't think so.
> Sure, we want 'dmake' to be used, but that value of 'nmake' is being
> overridden anyway. (You can check this by running 'perl -V:make',
> which should report that make=3D'dmake'.)
I get
C:\>perl -V:make
make=3D'nmake';
> I guess, however, there's a chance that by some strange twist of fate,
> it's not being overridden soon enough - so, in lib/Config_heavy.pl,
> try changing:
>
> make=3D'nmake
> to
> make=3D'dmake'
>
> and see if that has any effect on the generated Makefile. (It should
> alter the value of $Config{make} to 'dmake', but I'm not expecting any
> other differences.)
I have changed lib/Config_heavy.pl into make=3D'dmake', I deleted the
old Makefile and ran 'perl Makefile.PL, but there is no other
difference.
AR_STATIC_ARGS =3D cr
DIRFILESEP =3D ^\
DFSEP =3D $(DIRFILESEP)
so I changed my lib/Config_heavy.pl back to its original state
make=3D'nmake'.
> I think, too, that the problem with 'rem' is another separate issue
> (but nothing's guaranteed :-)
>
> Could you check that we're both looking at the same version of
> EU::MM_Win32 (which defines DIRFILESEP) by running:
>
> perl -MExtUtils::MM_Win32 -e "print $ExtUtils::MM_Win32::VERSION"
>
> And check that it contains the following subroutine:
>
> ##################################
> sub init_DIRFILESEP {
> =A0 =A0 my($self) =3D shift;
>
> =A0 =A0 my $make =3D $self->make;
>
> =A0 =A0 # The ^ makes sure its not interpreted as an escape in nmake
> =A0 =A0 $self->{DIRFILESEP} =3D $make eq 'nmake' ? '^\\' :
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $make eq 'dmake' ? '\=
\\\'
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0: '\\';}
>
> ##################################
>
> I have version 6.42 of EU::MM_Win32.
I have
C:\>perl -MExtUtils::MM_Win32 -e "print $ExtUtils::MM_Win32::VERSION"
6.50
(but this should not make any difference, because I upgraded EU::MM a
couple of hours ago,
but the problem was exactly the same before the upgrade)
Here is my init_DIRFILESEP...
**********************************
sub init_DIRFILESEP {
my($self) =3D shift;
# The ^ makes sure its not interpreted as an escape in nmake
$self->{DIRFILESEP} =3D $self->is_make_type('nmake') ? '^\\' :
$self->is_make_type('dmake') ? '\\\\'
: '\\';
}
**********************************
...which looks identical to yours
I believe that we have different values in "$self->make" (see sub
is_make_type in ExtUtils\MM_Win32.pm)
sub is_make_type {
my($self, $type) =3D @_;
return !! ($self->make =3D~ /\b$type(?:\.exe)?$/);
}
Where does the value "$self->make" originate ?
------------------------------
Date: Mon, 20 Apr 2009 05:08:45 -0700 (PDT)
From: tuser1@gmail.com
Subject: Re: dmake.exe: Error: -- 'C:\Perl\libConfig.pm' not found, and can't be made
Message-Id: <88fd5730-78df-4c28-900e-8c8c8f6e9f4d@l9g2000vba.googlegroups.com>
On Apr 20, 11:05=A0am, tus...@gmail.com wrote:
> Where does the value "$self->make" originate ?
I've found the problem...
...in "lib\ActivePerl\Config.pm":
******************************************************
sub override {
[...]
if ($key eq "make" && $^O eq "MSWin32") {
for (qw(nmake dmake)) {
if (ActiveState::Path::find_prog($_)) {
$_[0] =3D $OVERRIDE{$key} =3D $_;
return 1;
}
}
return 0;
}
******************************************************
("lib\ActivePerl\Config.pm" is called by the standard "lib\Config.pm")
I have an old version of "nmake" on my system, and my guess would be
that you have not.
The code in lib\ActivePerl\Config.pm is quite clever indeed:
First it looks if there exists an executable called "nmake". On my
configuration, there is one (albeit a very old one) and the subroutine
returns with $Config{make} =3D 'nmake'
I assume that on your configuration there is no such executable
'nmake', therefore it looks if there exists an executable called
"dmake", which there is, and the subroutine returns with $Config{make}
=3D 'dmake'
Here is what I did to resolve the issue on my system:
C:\dosext>ren NMAKE.EXE NMAKE-old.exe
And here is proof that "dmake" now works ok on my system:
C:\Scalar-Util-Refcount-1.0.2>perl -V:make
make=3D'dmake';
C:\Scalar-Util-Refcount-1.0.2>perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for Scalar::Util::Refcount
C:\Scalar-Util-Refcount-1.0.2>dmake
gcc -c -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -
DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -
DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -
DPERL_MSVCRT_REA
DFIX -DHASATTRIBUTE -fno-strict-aliasing -mms-bitfields -O2 -
DVERSION=3D\"1.0.2\" -DXS_VERSION=3D\"1.0.2\" "-IC:\Perl\lib\CORE"
Refcount_wrap.c
Running Mkbootstrap for Scalar::Util::Refcount ()
C:\Perl\bin\perl.exe -MExtUtils::Command -e chmod 644 Refcount.bs
dlltool --def Refcount.def --output-exp dll.exp
g++ -o blib\arch\auto\Scalar\Util\Refcount\Refcount.dll -Wl,--base-
file -Wl,dll.base -mdll -L"C:\Perl\lib\CORE" Refcount_wrap.o -Wl,--
image-base,0x3d100000 C:\Perl\lib\CORE\perl510.lib -lke
rnel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -
lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -
lodbc32 -lodbccp32 -lmsvcrt dll.exp
dlltool --def Refcount.def --base-file dll.base --output-exp dll.exp
g++ -o blib\arch\auto\Scalar\Util\Refcount\Refcount.dll -mdll -L"C:
\Perl\lib\CORE" Refcount_wrap.o -Wl,--image-base,0x3d100000 C:\Perl
\lib\CORE\perl510.lib -lkernel32 -luser32 -lgdi32 -lwin
spool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -
luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lmsvcrt
dll.exp
C:\Perl\bin\perl.exe -MExtUtils::Command -e chmod 755 blib\arch\auto
\Scalar\Util\Refcount\Refcount.dll
C:\Perl\bin\perl.exe -MExtUtils::Command -e cp Refcount.bs blib\arch
\auto\Scalar\Util\Refcount\Refcount.bs
C:\Perl\bin\perl.exe -MExtUtils::Command -e chmod 644 blib\arch\auto
\Scalar\Util\Refcount\Refcount.bs
C:\Scalar-Util-Refcount-1.0.2>dmake test
C:\Perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(0,
'blib\lib', 'blib\arch')" t/*.t
t/10_test....ok
All tests successful.
Files=3D1, Tests=3D7, 0 wallclock secs ( 0.00 cusr + 0.00 csys =3D 0.00
CPU)
C:\Scalar-Util-Refcount-1.0.2>dmake install
Files found in blib\arch: installing files in blib\lib into
architecture dependent library tree
Installing C:\Perl\site\lib\auto\Scalar\Util\Refcount\Refcount.dll
Appending installation info to C:\Perl\lib/perllocal.pod
------------------------------
Date: Mon, 20 Apr 2009 05:44:28 -0700 (PDT)
From: tuser1@gmail.com
Subject: Re: dmake.exe: Error: -- 'C:\Perl\libConfig.pm' not found, and can't be made
Message-Id: <627822e8-8fd1-4a40-8b86-be520819754a@x6g2000vbg.googlegroups.com>
On Apr 20, 2:08=A0pm, tus...@gmail.com wrote:
> ("lib\ActivePerl\Config.pm" is called by the standard "lib\Config.pm")
I meant:
"lib\ActivePerl\Config.pm" is called by "lib\Config_heavy.pl", which,
in turn, is called by the standard "lib\Config.pm".
------------------------------
Date: Mon, 20 Apr 2009 09:45:38 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: effienct way to select random value from the hash
Message-Id: <slrnguo6gr.bil.whynot@orphan.zombinet>
On 2009-04-19, Xho Jingleheimerschmidt <xhoster@gmail.com> wrote:
> Eric Pozharski wrote:
*SKIP*
>> My point was, that when picking random item of already randomized
>> sequence, the picked item becomes more or less random? I don't know.
>
> The order in a hash is not random, it is arbitrary. (In some
> implementations of perl, in some situations, at some times, it may be
> close to randomized.)
Oh, my god! It's even worse -- the order is arbitrary (good point,
BTW). In such circumstances, the only thing could help (me?) --
B<sort>. Luckily, I'm not the OP.
--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
------------------------------
Date: Mon, 20 Apr 2009 10:02:50 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: effienct way to select random value from the hash
Message-Id: <9d31eb74-2a7a-4e5d-a35f-161166a50bf7@r36g2000vbr.googlegroups.com>
On Apr 16, 9:19 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> smallpond <smallp...@juno.com> wrote innews:e7099553-400a-431d-9d3f-b4c0b6dc8beb@r28g2000vbp.googlegroups.com:
>
> > On Apr 16, 10:35 am, viki <viki...@gmail.com> wrote:
> >> sub RandomElement { # select random element from the hash
> >> my ($hashref) = @_;
> >> my @keys = keys(%{$hashref});
> >> my $random = $hashref->{ $keys[ int(rand( @keys )) ]};
>
> >> }
>
> >> When the hash is large, the creation of @keys for every
> >> invocation is invefficient. It's waste that's O((N)) for every call
> >> to RandomElement.
>
> >> What would be the fastest version of RandomElement ?
>
> ...
>
> > sub ran3($) {
> > my ($hashref) = @_;
> > my @vals = values(%{$hashref});
> > $vals[ int(rand( @vals )) ];
> > }
>
> > 10,000 calls to this took 2.341 s
>
> Interesting because here is what I get:
>
> C:\Temp> cat t.pl
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use Benchmark qw( cmpthese );
>
> my $h;
>
> for (1 .. 10_000) {
> $h->{"key$_"} = rand;
>
> }
>
> cmpthese -5, {
> smallpond => sub { ran3($h) },
> sinan => sub { ran42($h) },
>
> };
>
> sub ran3 {
> my ($h) = @_;
> my @v = values %$h;
> $v[rand @v];
>
> }
>
> sub ran42 {
> my ( $h ) = @_;
> (values %$h)[rand values %$h ];
>
> }
>
> __END__
>
> C:\Temp> t
> Rate smallpond sinan
> smallpond 288/s -- -82%
> sinan 1569/s 446% --
>
Your code is clearly better since it avoids creating the
unneeded array. What I was trying to compare was
extracting values vs keys vs flattening the entire hash
and picking an odd element (a value). Using your
method, extracting the list of values still wins,
although maybe there is a better way to do ranf.
cmpthese -5, {
flatten => sub { ranf($h) },
values => sub { ranv($h) },
keys => sub { rank($h) },
};
sub ranf {
my ($h) = @_;
(%$h)[1 + 2 * rand (keys %$h)];
}
sub ranv {
my ($h) = @_;
(values %$h)[rand values %$h];
}
sub rank {
my ($h) = @_;
$h->{(keys %$h)[rand keys %$h]};
}
Rate flatten keys values
flatten 71.3/s -- -3% -87%
keys 73.5/s 3% -- -86%
values 542/s 659% 637% --
------------------------------
Date: Mon, 20 Apr 2009 09:33:37 -0700 (PDT)
From: kun niu <haoniukun@gmail.com>
Subject: How can I backreference a ?: group in perl regular expression?
Message-Id: <9f5fb86b-27ae-44a9-bf57-5bd4dd0fdeda@y34g2000prb.googlegroups.com>
Dear all,
My question is listed as title.
I want to use strings like \1,\2 etc to represent the group matched
last time.
But the group is not captured, as signed by ?:.
Can I implement this in perl?
If so, how?
Thanks for any hints or advice in advance.
------------------------------
Date: Mon, 20 Apr 2009 17:50:26 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How can I backreference a ?: group in perl regular expression?
Message-Id: <inlub6-is03.ln1@osiris.mauzo.dyndns.org>
Quoth kun niu <haoniukun@gmail.com>:
> Dear all,
> My question is listed as title.
> I want to use strings like \1,\2 etc to represent the group matched
> last time.
> But the group is not captured, as signed by ?:.
> Can I implement this in perl?
No. That, in fact, is the whole point of (?:) groups.
Why do you think you need to do this?
Ben
------------------------------
Date: Mon, 20 Apr 2009 11:05:48 -0700 (PDT)
From: kun niu <haoniukun@gmail.com>
Subject: Re: How can I backreference a ?: group in perl regular expression?
Message-Id: <ee8eeed4-77fd-4f97-ab70-863bf5e7c1ec@i28g2000prd.googlegroups.com>
On 4=D4=C221=C8=D5, =C9=CF=CE=E712=CA=B150=B7=D6, Ben Morrow <b...@morrow.m=
e.uk> wrote:
> Quoth kun niu <haoniu...@gmail.com>:
>
> > Dear all,
> > My question is listed as title.
> > I want to use strings like \1,\2 etc to represent the group matched
> > last time.
> > But the group is not captured, as signed by ?:.
> > Can I implement this in perl?
>
> No. That, in fact, is the whole point of (?:) groups.
>
> Why do you think you need to do this?
>
> Ben
Thank you for your attention to my question and your precious time.
In my application, I'll have reformat the telephone number in my
company.
Since they came from all over the world, we have various telephone
format.
Here's some examples:
000-000-000
(00)00-000-0000
!00!00-000-0000
0000000
0000-0000
0000 0000 000
you dont care
What my job is to check the valid telephone number and to give them
out.
In case that I meet a ')' character, I'll have to check if there's a
'(' in the front.
'!' is also valid here.
But all these characters should not be captured.
So I'll have to backreference a previous group
Expression like "((?:[!|]*)\d+\1\d+)" gives a bad result.
Any further hints or advice here?
Thanks again for your reply.
------------------------------
Date: Mon, 20 Apr 2009 04:42:29 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Apr 20 2009
Message-Id: <KIDuEt.BAC@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
ASNMTAP-3.000020
http://search.cpan.org/~asnmtap/ASNMTAP-3.000020/
----
Acme-Mom-Yours-0.02
http://search.cpan.org/~adamk/Acme-Mom-Yours-0.02/
Your mom is so fat she takes 2 months to compile
----
Acme-Perl-VM-0.0.2
http://search.cpan.org/~gfuji/Acme-Perl-VM-0.0.2/
An implementation of Perl5 Virtual Machine in Pure Perl (APVM)
----
Apache-Session-LDAP-0.02
http://search.cpan.org/~guimard/Apache-Session-LDAP-0.02/
An implementation of Apache::Session
----
App-GitHub-0.01
http://search.cpan.org/~fayland/App-GitHub-0.01/
GitHub Command Tools
----
App-GitHub-0.02
http://search.cpan.org/~fayland/App-GitHub-0.02/
GitHub Command Tools
----
App-GitHub-0.03
http://search.cpan.org/~fayland/App-GitHub-0.03/
GitHub Command Tools
----
App-GitHub-0.04
http://search.cpan.org/~fayland/App-GitHub-0.04/
GitHub Command Tools
----
App-Rad-Plugin-TT-0.2
http://search.cpan.org/~fco/App-Rad-Plugin-TT-0.2/
Template Toolkit extension for the App::Rad framework
----
Audio-Scan-0.09
http://search.cpan.org/~agrundma/Audio-Scan-0.09/
Fast C parser for MP3, Ogg Vorbis, FLAC, ASF
----
B-Hooks-EndOfScope-0.08
http://search.cpan.org/~flora/B-Hooks-EndOfScope-0.08/
Execute code after a scope finished compilation
----
B-Hooks-OP-Check-0.16
http://search.cpan.org/~flora/B-Hooks-OP-Check-0.16/
Wrap OP check callbacks
----
B-Hooks-OP-Check-0.17
http://search.cpan.org/~flora/B-Hooks-OP-Check-0.17/
Wrap OP check callbacks
----
B-Hooks-OP-Check-StashChange-0.06
http://search.cpan.org/~flora/B-Hooks-OP-Check-StashChange-0.06/
Invoke callbacks when the stash code is being compiled in changes
----
Bot-BasicBot-Pluggable-Module-Eliza-0.03
http://search.cpan.org/~mdom/Bot-BasicBot-Pluggable-Module-Eliza-0.03/
Eliza for Bot::BasicBot::Pluggable
----
Business-AU-Ledger-0.82
http://search.cpan.org/~rsavage/Business-AU-Ledger-0.82/
A simple, web-based, payments/receipts manager
----
CPAN-WWW-Top100-Generator-0.03
http://search.cpan.org/~adamk/CPAN-WWW-Top100-Generator-0.03/
Create or update the website for http://ali.as/top100
----
CPANTS-Weight-0.08
http://search.cpan.org/~adamk/CPANTS-Weight-0.08/
Graph based weights for CPAN Distributions
----
Cache-Memcached-Tags-0.01
http://search.cpan.org/~ebragin/Cache-Memcached-Tags-0.01/
Cache::Memcached based client library for memcached-tags: http://code.google.com/p/memcached-tags/
----
Cache-Memcached-Tie-0.06
http://search.cpan.org/~gugu/Cache-Memcached-Tie-0.06/
Use Cache::Memcached::Fast like hash.
----
Catalyst-Plugin-HashedCookies-1.05
http://search.cpan.org/~oliver/Catalyst-Plugin-HashedCookies-1.05/
Tamper-resistant HTTP Cookies
----
Catalyst-Plugin-Session-State-Stash-0.10
http://search.cpan.org/~elpenguin/Catalyst-Plugin-Session-State-Stash-0.10/
Maintain session IDs using the stash
----
Chess-Play-0.01
http://search.cpan.org/~gippoliti/Chess-Play-0.01/
Play chess games, calculate legal moves, use a search algorithm
----
Class-Entangle-0.03
http://search.cpan.org/~exodist/Class-Entangle-0.03/
Functions to entangle an object.
----
Class-Entangle-0.04
http://search.cpan.org/~exodist/Class-Entangle-0.04/
Functions to entangle an object.
----
Compress-unLZMA-0.03
http://search.cpan.org/~ferreira/Compress-unLZMA-0.03/
Interface to LZMA decompression library
----
Config-Model-OpenSsh-1.205
http://search.cpan.org/~ddumont/Config-Model-OpenSsh-1.205/
OpenSsh configuration files editor
----
DBD-SQLite-1.23
http://search.cpan.org/~adamk/DBD-SQLite-1.23/
Self-contained RDBMS in a DBI Driver
----
DBIx-Class-0.08100
http://search.cpan.org/~mstrout/DBIx-Class-0.08100/
Extensible and flexible object <-> relational mapper.
----
DBIx-Class-ResultSet-RecursiveUpdate-v0.004
http://search.cpan.org/~zby/DBIx-Class-ResultSet-RecursiveUpdate-v0.004/
like update_or_create - but recursive
----
DBIx-Class-ResultSet-RecursiveUpdate-v0.005
http://search.cpan.org/~zby/DBIx-Class-ResultSet-RecursiveUpdate-v0.005/
like update_or_create - but recursive
----
DOCSIS-ConfigFile-0.56
http://search.cpan.org/~jhthorsen/DOCSIS-ConfigFile-0.56/
Decodes and encodes DOCSIS config-files
----
Data-CapabilityBased-0.001000
http://search.cpan.org/~mstrout/Data-CapabilityBased-0.001000/
Ask your data not what it is, but what it can do for your program
----
Ed2k_link-20090419
http://search.cpan.org/~val/Ed2k_link-20090419/
module for creation and work with eD2K links
----
Geo-Coordinates-GMap-0.03
http://search.cpan.org/~bluefeet/Geo-Coordinates-GMap-0.03/
Routines for converting decimal lat/lon to Google Map tiles, and back again.
----
Graphics-Color-0.20
http://search.cpan.org/~gphat/Graphics-Color-0.20/
Device and library agnostic color spaces.
----
Graphics-Primitive-0.40
http://search.cpan.org/~gphat/Graphics-Primitive-0.40/
Device and library agnostic graphic primitives
----
Hessian-Client-0.1.13
http://search.cpan.org/~heytrav/Hessian-Client-0.1.13/
RPC via Hessian with a remote server.
----
Hessian-Client-0.1.14
http://search.cpan.org/~heytrav/Hessian-Client-0.1.14/
RPC via Hessian with a remote server.
----
LWP-UserAgent-Mockable-1.0
http://search.cpan.org/~mmorgan/LWP-UserAgent-Mockable-1.0/
Permits recording, and later playing back of LWP requests.
----
LWP-UserAgent-Mockable-1.00
http://search.cpan.org/~mmorgan/LWP-UserAgent-Mockable-1.00/
Permits recording, and later playing back of LWP requests.
----
Module-Install-0.85
http://search.cpan.org/~adamk/Module-Install-0.85/
Standalone, extensible Perl module installer
----
Module-Manifest-0.07
http://search.cpan.org/~adamk/Module-Manifest-0.07/
Parse and examine a Perl distribution MANIFEST file
----
Mojo-Server-FCGI-0.05
http://search.cpan.org/~sri/Mojo-Server-FCGI-0.05/
Speedy FastCGI Server
----
MooseX-Accessors-ReadWritePrivate-v1.0.1
http://search.cpan.org/~elliotjs/MooseX-Accessors-ReadWritePrivate-v1.0.1/
Name your accessors get_foo() and set_foo() or _set_foo().
----
MooseX-MethodAttributes-0.06
http://search.cpan.org/~bobtfish/MooseX-MethodAttributes-0.06/
code attribute introspection
----
Net-GitHub-0.07
http://search.cpan.org/~fayland/Net-GitHub-0.07/
Perl Interface for github.com
----
Net-GitHub-0.08
http://search.cpan.org/~fayland/Net-GitHub-0.08/
Perl Interface for github.com
----
Net-ParSCP-0.11
http://search.cpan.org/~casiano/Net-ParSCP-0.11/
Secure transfer of files between clusters via SSH
----
OAuth-Lite-1.18
http://search.cpan.org/~lyokato/OAuth-Lite-1.18/
OAuth framework
----
OAuth-Lite-1.19
http://search.cpan.org/~lyokato/OAuth-Lite-1.19/
OAuth framework
----
ORLite-Migrate-0.03
http://search.cpan.org/~adamk/ORLite-Migrate-0.03/
Extremely light weight SQLite-specific schema migration
----
OSType-0.001
http://search.cpan.org/~dagolden/OSType-0.001/
Map operating system names to generic types or families
----
POE-Filter-XML-0.38
http://search.cpan.org/~nperez/POE-Filter-XML-0.38/
A POE Filter for parsing XML
----
POE-Filter-XML-RPC-0.04
http://search.cpan.org/~nperez/POE-Filter-XML-RPC-0.04/
A POE Filter for marshalling XML-RPC
----
Padre-Plugin-Perl6-0.27
http://search.cpan.org/~szabgab/Padre-Plugin-Perl6-0.27/
Padre plugin for Perl6
----
Parse-Marpa-1.003_000
http://search.cpan.org/~jkegl/Parse-Marpa-1.003_000/
Generate Parsers from any BNF grammar
----
Rinchi-CIGIPP-0.01
http://search.cpan.org/~bmames/Rinchi-CIGIPP-0.01/
Perl extension for the Common Image Generator Interface.
----
Rose-DB-0.751
http://search.cpan.org/~jsiracusa/Rose-DB-0.751/
A DBI wrapper and abstraction layer.
----
Rose-DB-Object-0.781
http://search.cpan.org/~jsiracusa/Rose-DB-Object-0.781/
Extensible, high performance object-relational mapper (ORM).
----
Search-Xapian-1.0.12.0
http://search.cpan.org/~olly/Search-Xapian-1.0.12.0/
Perl XS frontend to the Xapian C++ search library.
----
Simo-0.1103
http://search.cpan.org/~kimoto/Simo-0.1103/
Very simple framework for Object Oriented Perl.
----
Simo-0.1104
http://search.cpan.org/~kimoto/Simo-0.1104/
Very simple framework for Object Oriented Perl.
----
Simo-Util-0.0301
http://search.cpan.org/~kimoto/Simo-Util-0.0301/
Utility Class for Simo
----
Simo-Wrapper-0.0221
http://search.cpan.org/~kimoto/Simo-Wrapper-0.0221/
This module is now not recommended.
----
Test-SubCalls-1.09
http://search.cpan.org/~adamk/Test-SubCalls-1.09/
Track the number of times subs are called
----
UTF8BOM-1.02
http://search.cpan.org/~lyokato/UTF8BOM-1.02/
handling Byte Order Mark for UTF-8 files
----
Variable-Magic-0.34
http://search.cpan.org/~vpit/Variable-Magic-0.34/
Associate user-defined magic to variables from Perl.
----
Win32-TieRegistry-0.26
http://search.cpan.org/~adamk/Win32-TieRegistry-0.26/
Manipulate the Win32 Registry
----
signatures-0.04
http://search.cpan.org/~flora/signatures-0.04/
subroutine signatures with no source filter
----
signatures-0.05
http://search.cpan.org/~flora/signatures-0.05/
subroutine signatures with no source filter
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Mon, 20 Apr 2009 15:36:40 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: What does `my' do?!
Message-Id: <gsi4q8$v6$1@reader1.panix.com>
In article <slrnguk5d7.6ug.nospam-abuse@chorin.math.berkeley.edu>,
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>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...
That looks to me more like a scope compile-time effect. "my $x"
creates a variable that doesn't come into rvalue scope until after the
end of the statement, except that it can be assigned to in the
statement itself. (It has two different scopes? Uglier and uglier.)
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Mon, 20 Apr 2009 16:55:11 +0000 (UTC)
From: Willem <willem@snail.stack.nl>
Subject: Re: What does `my' do?!
Message-Id: <slrngupa7f.djr.willem@snail.stack.nl>
Tim McDaniel wrote:
) That looks to me more like a scope compile-time effect. "my $x"
) creates a variable that doesn't come into rvalue scope until after the
) end of the statement, except that it can be assigned to in the
) statement itself. (It has two different scopes? Uglier and uglier.)
Indeed. Very annoying if you want to do something like:
my $widget = $main->SomeWidget(-command => sub {
...
$widget->insert($text);
...
});
Which doesn't work (obviously, after reading the above).
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Mon, 20 Apr 2009 19:36:11 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: What does `my' do?!
Message-Id: <753q48F15pqqlU1@mid.individual.net>
Willem wrote:
> Tim McDaniel wrote:
> ) That looks to me more like a scope compile-time effect. "my $x"
> ) creates a variable that doesn't come into rvalue scope until after the
> ) end of the statement, except that it can be assigned to in the
> ) statement itself. (It has two different scopes? Uglier and uglier.)
>
> Indeed. Very annoying if you want to do something like:
>
> my $widget = $main->SomeWidget(-command => sub {
> ...
> $widget->insert($text);
> ...
> });
>
> Which doesn't work (obviously, after reading the above).
The scope of a lexical (my) variable begins AFTER the expression in which
it is declared, NOT inside the expression.
Maybe this is annoying, but the rule is simple.
I don't see any "ugliness".
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
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 2355
***************************************