[31548] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2807 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 7 06:09:29 2010

Date: Sun, 7 Feb 2010 03:09:11 -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, 7 Feb 2010     Volume: 11 Number: 2807

Today's topics:
        A revolt against NYC school closures <aijazali2009@gmail.com>
    Re: A zero-width positive lookbehind assertion <derykus@gmail.com>
    Re: A zero-width positive lookbehind assertion <rvtol+usenet@xs4all.nl>
    Re: A zero-width positive lookbehind assertion <derykus@gmail.com>
    Re: activestate perlex: is it real? <nospam@somewhere.com>
        Building a ready workforce <aijazali2009@gmail.com>
    Re: capturing multiple patterns per line sln@netherlands.com
        Math not working <fgnowfg@gmail.com>
    Re: Math not working <john@castleamber.com>
    Re: Math not working <dmw@coder.cl>
    Re: Math not working <ben@morrow.me.uk>
    Re: Math not working <ben@morrow.me.uk>
    Re: Math not working <nospam-abuse@ilyaz.org>
        McGraw-Hill Education Examines Career Readiness Issues, <aijazali2009@gmail.com>
    Re: OT: GNUS <dthole@gmail.com>
    Re: OT: GNUS <john@castleamber.com>
        Protesters condemn school closings <aijazali2009@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 7 Feb 2010 01:34:11 -0800 (PST)
From: arsalan <aijazali2009@gmail.com>
Subject: A revolt against NYC school closures
Message-Id: <c3111063-bf4c-4bc2-959b-0d716efe9fe2@c4g2000yqa.googlegroups.com>

A WIDE coalition of New Yorkers made their voices heard in the last
week of January against New York City Mayor Bloomberg's decision to
close 19 schools--disproportionately large schools located in
communities of color.
For more details www.technicaledu4u.blogspot.com


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

Date: Sat, 6 Feb 2010 05:09:33 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: A zero-width positive lookbehind assertion
Message-Id: <f6fcc807-b823-4591-8aea-95b80aa3d667@b12g2000pre.googlegroups.com>

On Feb 5, 6:56=A0pm, George <iamhell...@gmail.com> wrote:
> Hi
> I am trying to get directory name from say a path
> c:/app/organizer
> what I want to get is organizer , so basically =A0if I search from end
> of string and then lookbehind
> ($name)=3D($path=3D~(/(?<=3D\/)(.*?)(.*?)\z/));
>
> but it does not result in getting to oraginzer , it fetches app/
> organizer , kind of greedy
>
> I know I can do it using FILE::BASENAME , but want to understand how
> to do it using regexp and look back

Here's a possible lookbehind solution:

  ( $name ) =3D $path =3D~ m{  (?<=3D/) ([^/]*) \z }x;


or, with 5.10 you could use \K  (perldoc perlre):

  ( $name ) =3D $path =3D~ m{  / \K ([^/]*) \z }x;



But, the above are somewhat obfuscated because there's a
straightforward, simpler alternative:

( $name ) =3D $path =3D~ m{  / ([^/]*) \z }x


The only difference is that $& now includes '/'; whereas,
the latter doesn't.

--
Charles DeRykus


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

Date: Sat, 06 Feb 2010 14:56:04 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: A zero-width positive lookbehind assertion
Message-Id: <4b6d74f4$0$22944$e4fe514c@news.xs4all.nl>

C.DeRykus wrote:

> ( $name ) = $path =~ m{  / ([^/]*) \z }x

That $name will end up false if there is no slash in $path.

perl -Mstrict -le '
   for my $path (undef, "", "test", "test/123") {
     my ($name) = $path =~ m~([^/]+)\z~;
     print defined($name) ? "<$name>" : "undef";
   }
'
undef
undef
<test>
<123>

But you should just use File::Basename for this.
(beware, the module name was grossly misspelled by OP)

-- 
Ruud


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

Date: Sat, 6 Feb 2010 15:30:26 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: A zero-width positive lookbehind assertion
Message-Id: <e5ed6ce5-0b2a-44e2-915e-97fe7b737456@w27g2000pre.googlegroups.com>

On Feb 6, 5:56=A0am, "Dr.Ruud" <rvtol+use...@xs4all.nl> wrote:
> C.DeRykus wrote:
> > ( $name ) =3D $path =3D~ m{ =A0/ ([^/]*) \z }x
>
> That $name will end up false if there is no slash in $path.
>
> perl -Mstrict -le '
> =A0 =A0for my $path (undef, "", "test", "test/123") {
> =A0 =A0 =A0my ($name) =3D $path =3D~ m~([^/]+)\z~;
> =A0 =A0 =A0print defined($name) ? "<$name>" : "undef";
> =A0 =A0}
> '
> undef
> undef
> <test>
> <123>
>
> But you should just use File::Basename for this.
> (beware, the module name was grossly misspelled by OP)

I could be wrong but the OP sounded more interested in
how regex lookbehind could be used in a specific case
than generating a drop-in replacement for File::Basename.
But, I  agree it's worth noting the limitations and correct
spelling.


--
Charles DeRykus


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

Date: Sat, 6 Feb 2010 22:37:20 -0500
From: "Thrill5" <nospam@somewhere.com>
Subject: Re: activestate perlex: is it real?
Message-Id: <hklchi$mje$1@news.eternal-september.org>


"Fergus McMenemie" <fergus@twig-me-uk.not.here> wrote in message 
news:1jderrk.1ld7v4a1ebpt34N%fergus@twig-me-uk.not.here...
> Ron Bergin <rkb@i.frys.com> wrote:
>
>> > discontinued.
>> >
>> > Is this true? What is its status?
>> >
>> I have not used perlex, but if the official mailing list is any
>> indication, it would appear to be dead.  The last posting to the
>> mailing list was mid 2007.
>>
>> http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/perlex
>
> Thanks for that. But there is definetly some FUD at work. After all
> I came across this today:-
>
> http://docs.activestate.com/activeperl/5.10/PerlEx/Welcome.html
>
> which has a copyright in the footer of 2009! Now 5.10 only arrived
> in late 2007.
>
>>
>> > I am running perl v5.6.1 on vista sp 2
>>
>> IMO, that's a bigger problem.
>>
>> You should upgrade to at the very least 5.8 or preferably 5.10.
>
> If only it were my choice!

Most of ActiveStates products suffer from extremely poor documentation, (or 
a total lack thereof)  It's no wonder that most of them end up being 
discontinued or no longer supported.  The existing PerlEx documenation only 
refrences only IIS 5.0, which was release with Windows 2000 about 10 years 
ago.   I know it works with IIS 6.0 and 7.0, only because I tested it, but 
you would never know that from the docs. 




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

Date: Sun, 7 Feb 2010 01:33:07 -0800 (PST)
From: arsalan <aijazali2009@gmail.com>
Subject: Building a ready workforce
Message-Id: <228ead83-18b0-4c72-880c-e0d128ebdeec@k41g2000yqm.googlegroups.com>

More Employers Statewide Seeking Job Applicants With Career Readiness
Certification

Local employers gathered Thursday at Lenoir Community College to learn
more about the state=92s WorkKeys and Career Readiness Certification
programs.
For more details www.technicaledu4u.blogspot.com


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

Date: Sat, 06 Feb 2010 11:43:46 -0800
From: sln@netherlands.com
Subject: Re: capturing multiple patterns per line
Message-Id: <i9hrm55tndkt0i5ibt6vuhq9e2jt78s8h5@4ax.com>

On Fri, 5 Feb 2010 08:17:05 -0800 (PST), ccc31807 <cartercc@gmail.com> wrote:

>This is a newbie question, I admit, but I don't know the answer.
>
>Suppose I am parsing a file line by line, and I want to push to an
>array all substrings on that line that match a pattern. For example,
>consider the listing below. @urls SHOULD contain this: @urls = (http://
>google.com, http://yahoo.com, http://amazon.com, http://ebay.com)
>Instead, it contains only the last value. Using the g modifier doesn't
>help.
>
>I know why @urls contains only the last value, but I don't know how to
>get all the values.
>
>Thanks, CC.
>
>-------listing---------------
>use strict;
>use warnings;
>
>my @urls;
>while (<DATA>)
>{
>   if (/<a.*href="([^"]+)/) { push @urls, $1; }
>}
>
>print @urls;
>exit(0);
>
>__DATA__
><html>\n
><body>\n
><h1>My Favorite Sites</h1>\n
><p>\n
>My favorite sites are <a href="http://google.com">Google</a>, <a
>href="http://yahoo.com">Yahoo</a>, <a href="http://amazon.com">Amazon</
>a>, and <a href="http://ebay.com">Ebay</a>.\n
></p>\n
></body>\n
></html>\n

If you want to parse with a little bit more conformity,
something like this (albeit deficient) might work better
when you come across possible gotcha's.

-sln

use strict;
use warnings;

my @urls;
{
    local $/;
    @urls = <DATA> =~ 
        /<a\s+[^>]*?(?<=\s)href\s*=\s*["'](.+?)["'][^>]*?\s*\/?>/sg;

    # Or, if you want to be more precise and don't mind the quotes:
    #/<a\s+[^>]*?(?<=\s)href\s*=\s*(".+?"|'.+?')[^>]*?\s*\/?>/sg
}

print $_,"\n" for @urls;
exit(0);

__DATA__
<html>\n
<body>\n
<h1>My Favorite Sites</h1>\n
<p>\n
My favorite sites are <a asdfhref=http://google.com" href='http://gg.com' >Google</a>, <a
href="http://yahoo.com">Yahoo</a>, <a href="http://amazon.com">Amazon</
a>, and <a href="http://ebay.com">Ebay</a>.\n
</p>\n
</body>\n
</html>\n
---------
http://gg.com
http://yahoo.com
http://amazon.com
http://ebay.com



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

Date: Sat, 6 Feb 2010 12:13:50 -0800 (PST)
From: Faith Greenwood <fgnowfg@gmail.com>
Subject: Math not working
Message-Id: <4d5494d9-18a3-46aa-81bd-21602a2ba0e1@h12g2000vbd.googlegroups.com>

I'm very confused. I'm pulling some numbers from an xml file and then
trying to do some math.

####XML File
<library>
<books>5</books>
<pages>12</pages>
</library>

####Code
#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
use XML::XPath;

my $parser=XML::LibXML->new();
my $doc=$parser->parse_file("C:/scripts/production/xml.xml");

my $books=$doc->find("//books/text()");
my $pages=$doc->find("//pages/text()");

print "$books\n";
print "$pages\n";

my $total_pages=$books * $pages;
########################
when I run the above code, I get the output:

5
12
Operation "*": no method found,
       left argument in overloaded package XML::LibXML::Nodelist,
       right argument in overloaded package XML::LibXML::Nodelist at
script.pl line 16



Why can't I do math operations here?

thx!





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

Date: Sat, 06 Feb 2010 15:40:33 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: Math not working
Message-Id: <87zl3m9h66.fsf@castleamber.com>

Faith Greenwood <fgnowfg@gmail.com> writes:

> my $total_pages=$books * $pages;
> ########################
> when I run the above code, I get the output:
>
> 5
> 12
> Operation "*": no method found,
>        left argument in overloaded package XML::LibXML::Nodelist,
>        right argument in overloaded package XML::LibXML::Nodelist at
> script.pl line 16

You are trying to multiply two Nodelists...

> Why can't I do math operations here?

that's why. You probably have to 1) check that each nodelist has one
item and 2) extract the text out of each node 3) multiply the text
(which Perl will automagically convert to numbers)

-- 
John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development


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

Date: Sat, 06 Feb 2010 18:42:42 -0300
From: Daniel Molina Wegener <dmw@coder.cl>
Subject: Re: Math not working
Message-Id: <Sqqdnbf23uv6f_DWnZ2dnUVZ_tKdnZ2d@giganews.com>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA512

On Sáb 06 Feb 2010 17:13,
Faith Greenwood wrote:

> I'm very confused. I'm pulling some numbers from an xml file and then
> trying to do some math.

  OK, no problem...

> 
> ####XML File
> <library>
> <books>5</books>
> <pages>12</pages>
> </library>
> 
> ####Code
> #!/usr/bin/perl
> use strict;
> use warnings;
> use XML::LibXML;
> use XML::XPath;
> 
> my $parser=XML::LibXML->new();
> my $doc=$parser->parse_file("C:/scripts/production/xml.xml");
> 
> my $books=$doc->find("//books/text()");
> my $pages=$doc->find("//pages/text()");
> 
> print "$books\n";
> print "$pages\n";
> 
> my $total_pages=$books * $pages;
> ########################
> when I run the above code, I get the output:
> 
> 5
> 12
> Operation "*": no method found,
>        left argument in overloaded package XML::LibXML::Nodelist,
>        right argument in overloaded package XML::LibXML::Nodelist at
> script.pl line 16

  Well, the error is clear. The /find()/ method returns a Nodelist
object, so you are trying to miltiply $books and $pages which are
both XML::LibXML::Nodelist objects.

  Try using something like:

$books = int($books->string_value());
$pages = int($pages->string_value());
my $total_pages = $books * $pages;

> 
> 
> 
> Why can't I do math operations here?
> 
> thx!


Best regards,
- -- 
Daniel Molina Wegener <dmw [at] coder [dot] cl>
Software Architect, System Programmer & Web Developer
Phone: +1 (510) 629-4267 | Blog: http://coder.cl/
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iQIcBAEBCgAGBQJLbeJSAAoJEHxqfq6Y4O5NsjYP/2oFCmorBcavKkk2yVOHz3Qe
bOWlqiBlpw0oNsNniPFQ3n/tTFeCb/6yNHz/HiEnNsFJT0CL1l7HWjAL7tO/Lz9M
IWoUIOeEfqqDP0s0e34HTfyY1gu8/6jSUCoMsiT319PVVq/Kffp1fP/agY351Hsl
OWQkSYtDG+Q4wVIbLJ1Mxsmv/+H7YkWtRGXNmwjBllIhFYRJZmtzTKx4l3ErQ/Fe
Abw2yjm9M1G9Cl0muwdNuv/QwVequ2tH+MnGKFl03ulXc0Qk/drJDCnoTk2Pseze
6bkSB94rAAMO990rVYaQglsC30x4FHzK2EaH4W5F/2Q/U/4MXWfEgXBZV2YZcLZJ
N2Rnoa6uZVzlEtcwrGFaPnB1/HRpDSL8FaOTvUHYDrdr8auWmPGc9z6twvL9HbVM
g4USyU999wlSJkMyGrjnzjlJb5DCLuueEia+3Cb4XyarVN7b2OHrjq4yFOXW0iTU
/1rpzeAgP68QDs+jJ7JxCD8xXqZBcPTFiCWTxS5yN7DP76QXJNXu6K0SXiL8iY4y
m1ts05A5+FgZgteFk0HmODhwsetRJ/5+U0BAorv1JlYptUB7W0Q0zVyik7lICPa4
2Cm2Yv2lsLrBLtPanzj+8W1xWSB+khLSb1AxIY7znvNoZGObpFTiMoC+RFNPriqX
t3KjPZpRxkug3JkicZxw
=tQzG
-----END PGP SIGNATURE-----



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

Date: Sat, 6 Feb 2010 21:42:32 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Math not working
Message-Id: <8b4147-fov.ln1@osiris.mauzo.dyndns.org>


Quoth Faith Greenwood <fgnowfg@gmail.com>:
> I'm very confused. I'm pulling some numbers from an xml file and then
> trying to do some math.
> 
> ####XML File
> <library>
> <books>5</books>
> <pages>12</pages>
> </library>
> 
> ####Code
> #!/usr/bin/perl
> use strict;
> use warnings;
> use XML::LibXML;
> use XML::XPath;
> 
> my $parser=XML::LibXML->new();
> my $doc=$parser->parse_file("C:/scripts/production/xml.xml");
> 
> my $books=$doc->find("//books/text()");
> my $pages=$doc->find("//pages/text()");
> 
> print "$books\n";
> print "$pages\n";
> 
> my $total_pages=$books * $pages;
> ########################
> when I run the above code, I get the output:
> 
> 5
> 12
> Operation "*": no method found,
>        left argument in overloaded package XML::LibXML::Nodelist,
>        right argument in overloaded package XML::LibXML::Nodelist at
> script.pl line 16

If you add

    warn overload::StrVal($books);

before the multiplication, you will see that the 'numbers' are actually
objects with overloaded stringification. Since there is no "*" overload,
and no "0+" overload, and 'fallback => 1' was not specified[1], perl has
no way to perform the multiplication. You can work around this by
explicitly stringifying first:

    $books = "$books";  # stringify overloaded object
    $pages = "$pages";  # ""

    my $total_pages = $books * $pages;

The comment is important so that the next person to look at the code
doesn't mutter 'perldoc -q quote' and remove the lines :).

Ben

[1] I consider the fact that fallback => 1 isn't the default to be a bug
    in the perl overloading system, but it's much too late to change 
    that now. Apart from anything else, any new overloads (like the -X
    overload that will be in 5.12) must behave as though fallback=>1
    were specified, for compatibility.



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

Date: Sat, 6 Feb 2010 22:42:24 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Math not working
Message-Id: <gr7147-c501.ln1@osiris.mauzo.dyndns.org>


Quoth dmw@coder.cl:
> -----BEGIN xxx SIGNED MESSAGE-----

Please don't do that here. 

>   Well, the error is clear. The /find()/ method returns a Nodelist
> object, so you are trying to miltiply $books and $pages which are
> both XML::LibXML::Nodelist objects.
> 
>   Try using something like:
> 
> $books = int($books->string_value());

The 'int()' is unnecessary, and unclear (since it implies
$books->string_value might be a float we wish to truncate to an
integer),

Ben



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

Date: Sun, 7 Feb 2010 01:30:27 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Math not working
Message-Id: <slrnhms5tj.hd7.nospam-abuse@powdermilk.math.berkeley.edu>

On 2010-02-06, Ben Morrow <ben@morrow.me.uk> wrote:
> [1] I consider the fact that fallback => 1 isn't the default to be a bug
>     in the perl overloading system, but it's much too late to change 
>     that now. Apart from anything else, any new overloads (like the -X
>     overload that will be in 5.12) must behave as though fallback=>1
>     were specified, for compatibility.

If you think so, just make overload::simple which has a different
default for `fallback'.

  In my first experiments, I saw that the behaviour with {fallback =>
  1} was too error-prone - it was very hard for the developer to see
  whether the codepath was through convert-to-Perlish-data methods, or
  through the "specialized operations" methods.

  So I made the default 0.

Hope this helps,
Ilya


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

Date: Sun, 7 Feb 2010 01:31:56 -0800 (PST)
From: arsalan <aijazali2009@gmail.com>
Subject: McGraw-Hill Education Examines Career Readiness Issues, Hosts 21st  Century Workforce Virtual Conference
Message-Id: <b4017362-5d63-430d-895e-bf75b3296ebc@o28g2000yqh.googlegroups.com>

Industry Thought Leaders To Address Importance Of 21st Century Skills
At The Center Of America's Global Competitiveness
For more details www.technicaledu4u.blogspot.com


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

Date: Sat, 06 Feb 2010 07:17:35 -0600
From: David Thole <dthole@gmail.com>
Subject: Re: OT: GNUS
Message-Id: <m21vgyld00.fsf@dhcpw80ff9506.dynamic.uiowa.edu>

John Bokma <john@castleamber.com> writes:

> In order to have a real signature:
> ...
> (A real signature has a special marker consisting of -- followed by
> exactly one space)

Thanks for the signature suggestion, this'll save some typing and looks
better than the manual typing of this I have been doing.

-- 
David
http://www.thedarktrumpet.com/


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

Date: Sat, 06 Feb 2010 11:08:14 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: OT: GNUS
Message-Id: <87fx5ewav5.fsf@castleamber.com>

David Thole <dthole@gmail.com> writes:

> John Bokma <john@castleamber.com> writes:
>
>> In order to have a real signature:
>> ...
>> (A real signature has a special marker consisting of -- followed by
>> exactly one space)
>
> Thanks for the signature suggestion, this'll save some typing and looks
> better than the manual typing of this I have been doing.

You're welcome ;-) On top of that, a signature preceded with this
special marker gives usenet clients (including Gnus ) the option to
automatically remove the signature when replying.

-- 
John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development


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

Date: Sun, 7 Feb 2010 01:31:07 -0800 (PST)
From: arsalan <aijazali2009@gmail.com>
Subject: Protesters condemn school closings
Message-Id: <0c677ddc-7896-48c5-a50a-fa8fab1283b7@v25g2000yqk.googlegroups.com>

On a chilly Thursday afternoon, hundreds of parents, teachers and
students voiced their dissent over the Department of Education=92s plans
to phase out 19 public schools, including three high schools in
Queens, as they marched outside Mayor Mike Bloomberg=92s Upper East Side
townhouse.
For more details www.technicaledu4u.blogspot.com


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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 2807
***************************************


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