[25096] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7346 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 31 14:05:55 2004

Date: Sun, 31 Oct 2004 11:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 31 Oct 2004     Volume: 10 Number: 7346

Today's topics:
        FAQ 3.0: What is perl.com? Perl Mongers? pm.org? perl.o <comdog@panix.com>
        FAQ 8.23: How can I open a pipe both to and from a comm <comdog@panix.com>
    Re: Finding a module's $VERSION programmatically <tassilo.von.parseval@rwth-aachen.de>
    Re: IDEs <NOdj.athensSPAM@surfeu.fi>
        Multiple s/xx/yy/ <ulrich.herbst@gmx.de>
    Re: Multiple s/xx/yy/ <mritty@gmail.com>
    Re: Multiple s/xx/yy/ <nospam@bigpond.com>
    Re: Multiple s/xx/yy/ <tadmc@augustmail.com>
    Re: Multiple s/xx/yy/ <nobull@mail.com>
    Re: PerlFaq Question <nospam@nospam.com>
    Re: print FILE function() <Juha.Laiho@iki.fi>
        question about plucene <pogorzem@o2.pl>
        Question: need to parse web pages to extract data <abuse@microsoft.com>
    Re: Question: need to parse web pages to extract data <wyzelli@yahoo.com>
    Re: Regular Expression confusion <rwxr-xr-x@gmx.de>
    Re: Regular Expression confusion <c.taylor@no.spam>
    Re: Regular Expression confusion <rwxr-xr-x@gmx.de>
    Re: Regular Expression confusion <nobull@mail.com>
    Re: Regular Expression confusion <see@sig.invalid>
    Re: Regular Expression confusion <postmaster@castleamber.com>
    Re: Regular Expression confusion <nobull@mail.com>
        Which data structures to use? (Hash.. etc.,) (Tom)
    Re: Which data structures to use? (Hash.. etc.,) <nobull@mail.com>
    Re: Which data structures to use? (Hash.. etc.,) <bik.mido@tiscalinet.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 31 Oct 2004 11:03:00 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 3.0: What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org?
Message-Id: <cm2gp4$njd$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

3.0: What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org?

    Perl.com at http://www.perl.com/ is part of the O'Reilly Network, a
    subsidiary of O'Reilly Media.

    Perl Mongers is an advocacy organization for the Perl language which
    maintains the web site http://www.perl.org/ as a general advocacy site
    for the Perl language.

    Perl Mongers uses the pm.org domain for services related to Perl user
    groups, including the hosting of mailing lists and web sites. See the
    Perl user group web site at http://www.pm.org/ for more information
    about joining, starting, or requesting services for a Perl user group.

    Perl Mongers also maintain the perl.org domain to provide general
    support services to the Perl community, including the hosting of mailing
    lists, web sites, and other services. The web site http://www.perl.org/
    is a general advocacy site for the Perl language, and there are many
    other sub-domains for special topics, such as

        http://bugs.perl.org/
        http://history.perl.org/
        http://lists.perl.org/
        http://use.perl.org/

    http://www.cpan.org/ is the Comprehensive Perl Archive Network, a
    replicated worlwide repository of Perl software, see the *What is CPAN?*
    question earlier in this document.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Sun, 31 Oct 2004 17:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 8.23: How can I open a pipe both to and from a command?
Message-Id: <cm35s5$t1j$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

8.23: How can I open a pipe both to and from a command?

    The IPC::Open2 module (part of the standard perl distribution) is an
    easy-to-use approach that internally uses pipe(), fork(), and exec() to
    do the job. Make sure you read the deadlock warnings in its
    documentation, though (see IPC::Open2). See "Bidirectional Communication
    with Another Process" in perlipc and "Bidirectional Communication with
    Yourself" in perlipc

    You may also use the IPC::Open3 module (part of the standard perl
    distribution), but be warned that it has a different order of arguments
    from IPC::Open2 (see IPC::Open3).



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Sun, 31 Oct 2004 05:47:50 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Finding a module's $VERSION programmatically
Message-Id: <slrnco8rjm.qd.tassilo.von.parseval@localhost.localdomain>

Also sprach Paul Lalli:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:cm0b6m$89m$1@mamenchi.zrz.TU-Berlin.DE...
>> Brian Greenfield  <$news\200101$@zombie.org.uk> wrote in
> comp.lang.perl.misc:
>> > I'm trying to find the version number of the CPAN modules I've
>> > installed so I can keep my modules up to date.
>>
>> You get this functionality from CPANPLUS (not sure if the predecessor
>> CPAN already had it).  It compares versions of installed modules with
>> current versions on CPAN.
>>
>
> CPAN.pm does indeed offer this functionality, with the 'r' command from the
> CPAN shell.  It will give a list of your currently installed modules that
> are less up-to-date than the versions currently available on the CPAN.
> (Note that - I believe unlike CPANPLUS - there is no functionality to
> automatically download and install the newer versions based on this list).

There is, although no obvious way: You create a bundle with
'autobundle', make sure the newly created file is in @INC and then do a
'install Bundle::Snapshot_<DATE>.pm'

That works best if you have the latest perl installed, otherwise it will
try to grab and compile a new perl.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sun, 31 Oct 2004 11:49:24 +0200
From: "Jussi Mononen" <NOdj.athensSPAM@surfeu.fi>
Subject: Re: IDEs
Message-Id: <cm2ce5$t7s$1@nyytiset.pp.htv.fi>

>> Ultraedit has a pretty lousy indentation engine IMO
>
> True, it's not very sophisticated, but that feature is unimportant to
> me. I really don't *want* my editor to do that. I do occasionally use
> PerlTidy to clean up someone else's code, though. :)

When I write code, I do it "visually" meaning that I want to see as much 
code at one glance as possible and I want the code to "look good", ie. that 
the indentation is "correct". Maybe this is why I have to use 21" monitor 
with at least 1600x1400 resoution ;-)

>> did I mention that Emacs is free ;-)
>
> Free is good, but I don't mind paying for quality software. At $35, UE
> is a bargain. (Great support, too.)

I ended up using Emacs in my job, because it was available and supported 
well my "visual coding" :-) We do have Ultaredit licenses for our laptops 
for remote work, since using emacs through a VPN is quite painfull at times.

But, what gets the job done is the best tool for you :-)

/jUSSi 




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

Date: 31 Oct 2004 14:17:41 +0100
From: Ulrich Herbst <ulrich.herbst@gmx.de>
Subject: Multiple s/xx/yy/
Message-Id: <87fz3vrpqi.fsf@pculi.herbst.fam>

Hi,

I have to substitute multiple patterns in a template with different
values.

Something like that:

----------------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

my $template='a##1b##2c##3';

my $var1='x';
my $var2='y';
my $var3='z';

(my $newvar = $template) =~ s/##1/$var1/g;
$newvar =~ s/##2/$var2/g;
$newvar =~ s/##3/$var3/g;

print $newvar ."\n";
# $newvar = 'axbycz'
----------------------------------------------------------------------

Can I put these three lines with "s/.../.../" in one line ?

Uli

-- 
                             '''
                             (0 0)
                +------oOO----(_)--------------+
                |                              |
                |         Ulrich Herbst        |
                |                              |
                +-------------------oOO--------+
                            |__|__|
                             || ||
                            ooO Ooo


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

Date: Sun, 31 Oct 2004 08:31:01 -0500
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Multiple s/xx/yy/
Message-Id: <cm2pg2$o5l$1@misc-cct.server.rpi.edu>

Ulrich Herbst wrote:
> Hi,
> 
> I have to substitute multiple patterns in a template with different
> values.
> 
> Something like that:
> 
> ----------------------------------------------------------------------
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> my $template='a##1b##2c##3';
> 
> my $var1='x';
> my $var2='y';
> my $var3='z';
> 
> (my $newvar = $template) =~ s/##1/$var1/g;
> $newvar =~ s/##2/$var2/g;
> $newvar =~ s/##3/$var3/g;
> 
> print $newvar ."\n";
> # $newvar = 'axbycz'
> ----------------------------------------------------------------------
> 
> Can I put these three lines with "s/.../.../" in one line ?

You might be better off using a hash instead of three separate variables:
my %replace = (1=>'x', 2=>'y', 3=>'z');

(my $newvar = $template) =~ s/##(\d)/$replace{$1}/g;

Paul Lalli



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

Date: Mon, 01 Nov 2004 01:32:01 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Multiple s/xx/yy/
Message-Id: <2ukeriF2cslbbU2@uni-berlin.de>

Ulrich Herbst wrote:

> Hi,
> 
> I have to substitute multiple patterns in a template with different
> values.
> 
> Something like that:
> 
> ----------------------------------------------------------------------
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> my $template='a##1b##2c##3';
> 
> my $var1='x';
> my $var2='y';
> my $var3='z';
> 
> (my $newvar = $template) =~ s/##1/$var1/g;
> $newvar =~ s/##2/$var2/g;
> $newvar =~ s/##3/$var3/g;
> 
> print $newvar ."\n";
> # $newvar = 'axbycz'
> ----------------------------------------------------------------------
> 
> Can I put these three lines with "s/.../.../" in one line ?
> 
> Uli
> 

You need 'apply':
http://gregorytoomey.com/index.php?option=content&task=view&id=15&Itemid=28


gtoomey


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

Date: Sun, 31 Oct 2004 09:50:44 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Multiple s/xx/yy/
Message-Id: <slrncoa2ek.lf5.tadmc@magna.augustmail.com>

Ulrich Herbst <ulrich.herbst@gmx.de> wrote:


> I have to substitute multiple patterns in a template with different
> values.


> my $var1='x';
> my $var2='y';
> my $var3='z';


   my @vars = qw/ x y z /;


> (my $newvar = $template) =~ s/##1/$var1/g;
> $newvar =~ s/##2/$var2/g;
> $newvar =~ s/##3/$var3/g;


   (my $newvar = $template) =~ s/##(\d+)/$vars[$1-1]/g;


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sun, 31 Oct 2004 16:56:52 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Multiple s/xx/yy/
Message-Id: <cm35gl$epa$1@slavica.ukpost.com>



Gregory Toomey wrote:

> Ulrich Herbst wrote:
>>(my $newvar = $template) =~ s/##1/$var1/g;
>>$newvar =~ s/##2/$var2/g;
>>$newvar =~ s/##3/$var3/g;
>>
>>Can I put these three lines with "s/.../.../" in one line ?
 >
> You need 'apply':
> http://gregorytoomey.com/index.php?option=content&task=view&id=15&Itemid=28

Speaking as the originator of the apply function I would say it doesn't 
really help the OP.  I think Tad and Paul grasped the OP's problem better.



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

Date: Sun, 31 Oct 2004 01:43:05 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: PerlFaq Question
Message-Id: <1099205037.439957@nntp.acecape.com>

"brian d foy" <comdog@panix.com> wrote in message
news:301020042258204300%comdog@panix.com...


thanks for your quick replies....




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

Date: Sun, 31 Oct 2004 18:47:26 +0000 (UTC)
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: print FILE function()
Message-Id: <cm3bvu$jut$1@ichaos.ichaos-int>

"A. Sinan Unur" <usa1@llenroc.ude.invalid> said:
>Eric Bohlman <ebohlman@omsdev.com> wrote in
>news:Xns9590C6790E25ebohlmanomsdevcom@130.133.1.4: 
>> Experimentation makes it *look* like expressions enclosed in a for(), 
>> while(), or do() loop are "lost" as far as return values are
>> concerned.  Expressions enclosed in a bare block after the loop are
>> "kept," as well as expressions in statements governed by modifiers. 
>> Expressions evaluated before a loop are "lost."  A loop loses the last
>> expression even if it doesn't execute (while(0)).
>> 
>> Am I missing some place where this behavior is documented?
>
>I don't know if it is documented anywhere, but the reason it seemed 
>intuitively obvious to me (and therefore, the reason I posted my original 
>response) was that the last statement that is executed in the sub is the 
>condition of the loop. When that condition evaluates to false, the loop 
>terminates. In list context, in which the subroutine itself was being 
>evaluated, that would naturally yield an empty list.

Further, it looks like loop blocks create void context - see:

No errors; prints out "f='7'":

#! /usr/bin/perl
use strict;
use warnings;

sub f {
	7;
}

print "f='",f(),"'\n";


"Useless use of a constant in void context at ./f.pl line 7",
prints out "f=''":

#! /usr/bin/perl
use strict;
use warnings;

sub f {
	for (my $i=0; $i<3; $i++) {
		7;
	}
}

print "f='",f(),"'\n";


Interesting.
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Sun, 31 Oct 2004 18:47:54 +0100
From: pogi <pogorzem@o2.pl>
Subject: question about plucene
Message-Id: <cm38ha$fpe$1@atlantis.news.tpi.pl>

Can you help me with plucene?
I've create index, and make simple search use Plucene::Simple. It worked ok,
I think, but I don't know how to print author and title fields when I find
id's.


this is my code:

create index:
------------
use Plucene::Simple;

$index_path="index";

my $plucy = Plucene::Simple->open($index_path);

$plucy->add(
        id1 => {
                author => "authorfirst",
                title  => "titlefirst",
        },
        id2 => {
                author => "authorsecond",
                title => "titlesecond"
        },
        id3 => {
                 author => "authorfirst",
                 title => "titlethird"
        },


);


serching index:
-----------

use Plucene::Simple;

$index_path='index';
$search_string="authorfirst";
$search_string2="titlethird";

my $plucy = Plucene::Simple->open($index_path);

my @result = $plucy->search($search_string);

print @result;

my @result = $plucy->search("author:$search_string AND title: 
$search_string2");

print @result;



Thanks,
Maciej


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

Date: Sun, 31 Oct 2004 09:12:29 GMT
From: "Troll" <abuse@microsoft.com>
Subject: Question: need to parse web pages to extract data
Message-Id: <102hd.5249$K7.1478@news-server.bigpond.net.au>

Hi,

The site is:
www.homepriceguide.com.au

A sample page with data can be seen at:
http://www.homepriceguide.com.au/snapshot/price/index.cfm?action=view&suburbORpostcode=6153&source=apm

The only thing that changes is the postcode so the next page in line will
be:
http://www.homepriceguide.com.au/snapshot/price/index.cfm?action=view&suburbORpostcode=6154&source=apm

etc etc

What I'm trying to do is to extract price info and save it to a file where
each record has the postcode as its ID. Last year I wrote a script that went
through the site and gathered the data for me and dumped the results in a
file. Unfortunately it's gone walking somewhere. Can someone pls remind me
which module is best to be used here (I'm mainly concerned with the parsing
side right now)? I have not coded for <> 12mths so I'm a bit rusty now but
hopefully it will all come back.

Let me know if the above is not clear.

Thanks in advance.
Voitec




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

Date: Sun, 31 Oct 2004 11:04:32 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: Question: need to parse web pages to extract data
Message-Id: <4F3hd.5378$K7.4896@news-server.bigpond.net.au>

"Troll" <abuse@microsoft.com> wrote in message 
news:102hd.5249$K7.1478@news-server.bigpond.net.au...
> Hi,
>
> The site is:
> www.homepriceguide.com.au
>
> A sample page with data can be seen at:
> http://www.homepriceguide.com.au/snapshot/price/index.cfm?action=view&suburbORpostcode=6153&source=apm
>
> The only thing that changes is the postcode so the next page in line will
> be:
> http://www.homepriceguide.com.au/snapshot/price/index.cfm?action=view&suburbORpostcode=6154&source=apm
>
> etc etc
>
> What I'm trying to do is to extract price info and save it to a file where
> each record has the postcode as its ID. Last year I wrote a script that 
> went
> through the site and gathered the data for me and dumped the results in a
> file. Unfortunately it's gone walking somewhere. Can someone pls remind me
> which module is best to be used here (I'm mainly concerned with the 
> parsing
> side right now)? I have not coded for <> 12mths so I'm a bit rusty now but
> hopefully it will all come back.

Start with the LWP set of modules....

-- 
Wyzelli
{{${^_sub}=sub{scalar reverse shift}}{$_={${^_reverse}=>
{${^_scalar}=>{${^_shift}=>{${^_sub}=>{${^_print}=>{}}}}}}
}{s{.*}{rekcaH lreP rehtona tsuJ}}{print("@{[&${^_sub}($_)]}")}}




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

Date: 31 Oct 2004 04:48:37 GMT
From: Lukas Mai <rwxr-xr-x@gmx.de>
Subject: Re: Regular Expression confusion
Message-Id: <cm1qr5$6nc$1@wsc10.lrz-muenchen.de>

Bob Walton schrob:
> Christie Taylor wrote:

> > I'm new to regular expressions and am trying to create a fairly simple
> > one to validate input.  The goal is to accept an optional word followed
> > by zero or one spaces, then a required number of 1 to 8 digits.
> > 
> > I tried m/^word\s{0,1}\d{1,7}/i  to get started (ignoring my  optional
> > part) but this is not working, it's matching on way too much. What am I
> > missing?

[...]

>     m/^(?:word)?\s?\d{1,8}(?:\D|$)/i

Note that you can replace (?:\D|$) by a negative look-ahead assertion:

  m/^(?:word)?\s?\d{1,8}(?!\d)/i

This looks more intuitive to me (... 1 to 8 digits, not followed by
another digit).

[...]

HTH, Lukas
-- 
print+74.117.115.116,,qq.\c!..not::.her,Perl=>q$hacker,$,!($,=$")


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

Date: Sun, 31 Oct 2004 01:05:50 -0400
From: Christie Taylor <c.taylor@no.spam>
Subject: Re: Regular Expression confusion
Message-Id: <418472AE.F3E33AD0@no.spam>

Lukas Mai wrote:

> Bob Walton schrob:
> > Christie Taylor wrote:
>
> > > I'm new to regular expressions and am trying to create a fairly simple
> > > one to validate input.  The goal is to accept an optional word followed
> > > by zero or one spaces, then a required number of 1 to 8 digits.
> > >
> > > I tried m/^word\s{0,1}\d{1,7}/i  to get started (ignoring my  optional
> > > part) but this is not working, it's matching on way too much. What am I
> > > missing?
>
> [...]
>
> >     m/^(?:word)?\s?\d{1,8}(?:\D|$)/i
>
> Note that you can replace (?:\D|$) by a negative look-ahead assertion:
>
>   m/^(?:word)?\s?\d{1,8}(?!\d)/i
>
> This looks more intuitive to me (... 1 to 8 digits, not followed by
> another digit).

Ok, I'm having trouble.  When I do this and type as my test string:

word444      it works
444          it works
word 444     it doesn't work; no match

if ($teststring =~ m/^(?:word)?\s?\d{1,8}(?!\d)/i) {
   print "matches\n";
}

What am I doing wrong?  thanks.




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

Date: 31 Oct 2004 06:09:49 GMT
From: Lukas Mai <rwxr-xr-x@gmx.de>
Subject: Re: Regular Expression confusion
Message-Id: <cm1vjd$94m$2@wsc10.lrz-muenchen.de>

Christie Taylor schrob:
[...]
> Ok, I'm having trouble.  When I do this and type as my test string:

> word444      it works
> 444          it works
> word 444     it doesn't work; no match

> if ($teststring =~ m/^(?:word)?\s?\d{1,8}(?!\d)/i) {
>    print "matches\n";
> }

~/programming/perl $ cat try.pl
#!/usr/local/bin/perl
use warnings;
use strict;

my @strings = ('word444', '444', 'word 444');
for my $teststring (@strings) {
    if ($teststring =~ m/^(?:word)?\s?\d{1,8}(?!\d)/i) {
        print "[$teststring] matches\n";
    } else {
        print "[$teststring] doesn't match\n";
    }
}
__END__
~/programming/perl $ perl try.pl
[word444] matches
[444] matches
[word 444] matches
~/programming/perl $


> What am I doing wrong?  thanks.

No idea; it works here.

HTH, Lukas
-- 
format =
Just another Perl hacker,
 .
write


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

Date: Sun, 31 Oct 2004 10:47:06 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Regular Expression confusion
Message-Id: <cm2frb$3r7$1@slavica.ukpost.com>


Bob Walton wrote:

> Also, you are using capturing parentheses.  Did you really intend that, 
> since you're not making use of the captured values (or if you are, 
> you're doing it wrong, since the capture isn't inside the if block)?  If 
> you don't intend a capture, use (?:regexp) instead, which is identical 
> to (regexp) except it doesn't capture.  That makes your intent clearer.

To those of us who learnt Perl regex before there were non-capturing 
parentheses that is not necessarily the case.

In my mind capturing is a natual side-effect of the grouping 
paraentheses.  If I see the programmer explicily suppress this 
side-effect then I start (at least subconciously) looking for a positive 
reason why.  Bare in mind that even a regex with no captures will reset 
the "most recent match" buffer that is accessed via the $1 etc variables.

Hense replacing () with (?:) will make the intent clearer to some 
readers and less clear to others and overall is a clarity-neutral change.

Given the rule "always write less code unless this will make your code 
less clear" I would say don't use (?:).



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

Date: Sun, 31 Oct 2004 09:49:19 -0500
From: Bob Walton <see@sig.invalid>
Subject: Re: Regular Expression confusion
Message-Id: <4184f938$1_3@127.0.0.1>

Christie Taylor wrote:

> Lukas Mai wrote:
> 
> 
>>Bob Walton schrob:
>>
>>>Christie Taylor wrote:
 ...
> Ok, I'm having trouble.  When I do this and type as my test string:
> 
> word444      it works
> 444          it works
> word 444     it doesn't work; no match
> 
> if ($teststring =~ m/^(?:word)?\s?\d{1,8}(?!\d)/i) {
>    print "matches\n";
> }
> 
> What am I doing wrong?  thanks.

Don't know, works fine for me:

D:\junk>type junk494.pl
use strict;
use warnings;
while(<DATA>){
    chomp;
    print ">$_<",
       m/^(?:word)?\s?\d{1,8}(?!\d)/i ?
          ' matched':
          ' did not match',
       "\n";
}
__END__
word123
xxx234
WoRd 345
WORD 2398723498723492387
word 234xxx
word  567

word 12345678blahblahblah
1234xxx
  1234xxx
  9
9
word444
444
word 444

D:\junk>perl junk494.pl
 >word123< matched
 >xxx234< did not match
 >WoRd 345< matched
 >WORD 2398723498723492387< did not match
 >word 234xxx< matched
 >word  567< did not match
 >< did not match
 >word 12345678blahblahblah< matched
 >1234xxx< matched
 > 1234xxx< matched
 > 9< matched
 >9< matched
 >word444< matched
 >444< matched
 >word 444< matched

D:\junk>

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: 31 Oct 2004 18:07:31 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Regular Expression confusion
Message-Id: <Xns95937B586D0C9castleamber@130.133.1.4>

Brian McCauley wrote:

[ snip ]
> Hense replacing () with (?:) will make the intent clearer to some 
> readers and less clear to others and overall is a clarity-neutral
> change. 

The ones that don't know (?: ... ) should learn it. Capturing it and not 
using is way more confusing.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


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

Date: Sun, 31 Oct 2004 19:03:59 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Regular Expression confusion
Message-Id: <cm3cv0$f8l$1@slavica.ukpost.com>



John Bokma wrote:

> Brian McCauley wrote:
> 
> [ snip ]
> 
>>Hense replacing () with (?:) will make the intent clearer to some 
>>readers and less clear to others and overall is a clarity-neutral
>>change. 
> 
> 
> The ones that don't know (?: ... ) should learn it.

I did not speak of people who did not know about (?:...).  I spoke of 
people who use or have use regex in some context other than current 
versions of Perl.  The normal way to do grouping in most dialects of RE 
is simply ().

As I said before I learnt Perl before it had (?:...).  I also learnt RE 
before I learnt Perl and continue to use RE in other environments too.

> Capturing it and not using is way more confusing.

You bland assertion that this is the case will not make it true.

I will admit (and indeed have already done so in this thread) that 
_some_ people will be confused by the failure to suppress the redundant 
capturing side effect of grouping.

Personally when I see /I said "(foo|bar)"/ I am not at all confused by 
the fact that it's not being used as a capture.



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

Date: 31 Oct 2004 01:54:40 -0700
From: sudhirx@gmail.com (Tom)
Subject: Which data structures to use? (Hash.. etc.,)
Message-Id: <f50c52fa.0410310054.4a4c892b@posting.google.com>

Just started learning perl and i find it very interesting. 
Well, I have to generate reports reading from a text file. 

Following is the data-structure i have planned from which i can
extract relevant data for report.

Any suggestions on what data structures can be used here?
I understand hash tables.. however need some pointers to implement
effectively..

				           __________
Test Case 1.   --------- Iter 0 --------->|  	     |(Array)
                     |			  |----------|
                     |-- Iter 1           |          |
                     |                    |----------|
                     |-- Iter 2           |          |
                     |                    |----------|
                     |-- ..               |          |
                     |                    |----------|
		     |-- ..
		     |			   __________
                     |-- Iter n --------->|	     |(Array)
                     |		          |          |
                     |                    |----------|
                     |			  |          |
                     |                    |----------|
		     |		          |          |
                     |                    |----------|
	..
	..
	..
	..
	..
					   __________
Test Case n.   --------- Iter 0 --------->|  	     |(Array)
                     |			  |----------|
                     |-- Iter 1           |          |
                     |                    |----------|
                     |-- Iter 2           |          |
                     |                    |----------|
                     |-- ..               |          |
                     |                    |----------|
		     |-- ..
		     |			   __________
                     |-- Iter n --------->|	     |(Array)
                     |		          |          |
                     |                    |----------|
                     |			  |          |
                     |                    |----------|
		     |		          |          |
                     |                    |----------|


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

Date: Sun, 31 Oct 2004 11:49:26 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Which data structures to use? (Hash.. etc.,)
Message-Id: <cm2jg6$cle$1@slavica.ukpost.com>



Tom wrote:

> Just started learning perl and i find it very interesting. 
> Well, I have to generate reports reading from a text file. 
> 
> Following is the data-structure i have planned from which i can
> extract relevant data for report.
> 
> Any suggestions on what data structures can be used here?
> I understand hash tables.. however need some pointers to implement
> effectively..

When we say "hash" in Perl we really mean "assocative array" - the fact 
that Perl's builtin associative array type is implemented using hash 
tables is largely irrelevant and it's only a historical accident that 
the name emphasises this.

In Perl all more complex data structures are built out of arrays and 
hashes (there's that word again) using pointers (or as we call then im 
Perl references).

[ snip pictorial representation of the abstract concept array of array 
of arrays ]

In Perl you'd implement that as an array of array of arrays.  Well, 
strictly an array of references to array of of references to arrays but 
usually we take the "references to" as read.
   				
Of course this presupposes that you'd correctly assesed in the first 
place that your real-world problem is most naturally represented as an 
array of array of arrays, and since you don't tell us anything about it 
it's hard to judge.

The middle array in your model is described "iterations 0..n" and so I 
can reasonably guess that array is the correct way to model that.

The outermost array you have described as "test case 1..n".  If the test 
cases are really just numbered not named then again an array is the 
natural way to model that (although you should number from zero).  If 
the test cases are really named not numbered then a hash would be more 
natural.

The innermost array in your model presumably holds data about a given 
iteration of a given test.  It is unlikely that the outcome of a single 
iteration is a list of scalars and so it is unlikely that an array is 
the natural way to store them.  It is more likely that the outcome is a 
vector.   The distinction I'm drawing here is that the second element in 
each vector always has a given meaning (e.g. average weight of rabit) 
that is distinct from the 3rd element (e.g. total number of rabits). 
Such vectors are, in Perl, naturally represented using hashes.  Note you 
are not really using hash here as a hash table but as a record with 
named fields.  Don't worry this is normal in Perl.



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

Date: Sun, 31 Oct 2004 13:16:12 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Which data structures to use? (Hash.. etc.,)
Message-Id: <5ll9o0dg604vvp0ehiba0l3mt324bjd9mk@4ax.com>

On 31 Oct 2004 01:54:40 -0700, sudhirx@gmail.com (Tom) wrote:

>Following is the data-structure i have planned from which i can
>extract relevant data for report.
>
>Any suggestions on what data structures can be used here?
>I understand hash tables.. however need some pointers to implement
>effectively..
[snip data structures description]

Despite your very detailed description, it's not entirely clear to me
what you need. However I think you may be interested in e.g.:

  perldoc perlref
  perldoc perlreftut
  perldoc perldsc
  perldoc perllol


HTH,
Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7346
***************************************


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