[32676] in Perl-Users-Digest
Perl-Users Digest, Issue: 3952 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 23 11:09:21 2013
Date: Thu, 23 May 2013 08:09:06 -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 Thu, 23 May 2013 Volume: 11 Number: 3952
Today's topics:
How to make XML::XPath ignore namespaces? <davidmichaelkarr@gmail.com>
Re: I'd like to try Perl... <jblack@nospam.com>
Re: I'd like to try Perl... <peterxpercival@hotmail.com>
Problem: perl negative look-ahead assertion in multi-li <cibalo@gmx.co.uk>
Re: Problem: perl negative look-ahead assertion in mult <thepoet_nospam@arcor.de>
Re: Problem: perl negative look-ahead assertion in mult <derykus@gmail.com>
Re: Problem: perl negative look-ahead assertion in mult <rweikusat@mssgmbh.com>
Re: so how much money do perl programmers make? <dailey.kohtz@gmail.com>
Would anyone teach me perl? <dailey.kohtz@gmail.com>
Re: Would anyone teach me perl? <justin.1303@purestblue.com>
Re: Would anyone teach me perl? <jblack@nospam.com>
Re: XML parsing problem <ben@morrow.me.uk>
Re: XML parsing problem <email@domain.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 21 May 2013 10:59:05 -0700 (PDT)
From: David Karr <davidmichaelkarr@gmail.com>
Subject: How to make XML::XPath ignore namespaces?
Message-Id: <93145537-447d-447b-83e7-9b8abd5c715c@googlegroups.com>
I'm trying to use XML::XPath to extract content from XML documents. The documents are specified with namespaces, but I want to use XPath expressions without namespaces. As far as I can tell, I had this working perfectly fine in two different scripts.
It seems like sometime today, the behavior of XML::XPath has changed with respect to this. I don't see what I could have changed that has made this behavior change.
I can get some manual tests to work, if I almost fully specify namespaces, using a call to "set_namespace()" in the script (hardcoding the prefix I expect to use) and specifying the prefix in the XPath expression.
Again, I'm pretty sure I had this working yesterday, without calling "set_namespace()" in the script, or specifying prefixes in the XPath expressions.
If I don't add that "set_namespace()" call and specify prefixes in the expression, I just get empty nodesets from my queries.
I tried setting "$XML::XPath::Namespaces" to zero before I create the first XPath object, but that doesn't seem to make any difference.
The following is a simple script I pipe XML into:
--------------------
#! /bin/perl
use XML::XPath;
use XML::XPath::XMLParser;
use Getopt::Long;
$| = 1;
my $opt_file;
GetOptions("f|file=s" => \$opt_file);
$XML::XPath::Namespaces = 0;
my $xpath;
if ($opt_file ne '') {
$xpath = XML::XPath->new(filename => $opt_file);
}
else {
$xpath = XML::XPath->new(ioref => \*STDIN);
}
while (my $expr = shift @ARGV) {
my $nodeset = $xpath->find($expr);
if ($nodeset) {
if ($opt_file ne '') {
print $opt_file . ":\n";
}
my $node;
for $node ($nodeset->get_nodelist) {
print $node->string_value() . "\n";
}
}
}
------------------
Here's a sample command line:
% echo "<ns3:abc xmlns:ns3=\"xxx\"><ns3:def>ghi</ns3:def></ns3:abc>" | xpathtext "//def"
I would hope to get "ghi" from this, but I'm currently getting nothing.
------------------------------
Date: Tue, 21 May 2013 13:58:50 -0500
From: John Black <jblack@nospam.com>
Subject: Re: I'd like to try Perl...
Message-Id: <MPG.2c057fe1b0af9e4b989779@news.eternal-september.org>
In article <d9ac9117-18c9-4114-ad7a-612c23ba1dd5@dk8g2000vbb.googlegroups.com>,
marc.girod@gmail.com says...
> Note also the Cygwin option...
Yeah, spend a few minutes checking out the cygwin environment. I started with Strawberry
Perl and ended up removing it and installing cygwin. You get perl and tons more if you want.
You choose what you want installed or not installed but what you end up with is an
environment and set of tools that looks like and includes most of what you get with Unix. In
fact, when I'm in a cygwin terminal, I can pretty much behave as if its a unix window and
everything seems to work as I expect.
John Black
------------------------------
Date: Wed, 22 May 2013 12:21:26 +0100
From: Peter Percival <peterxpercival@hotmail.com>
Subject: Re: I'd like to try Perl...
Message-Id: <kni9nn$rkn$2@news.albasani.net>
Marc Girod wrote:
> Note also the Cygwin option...
I have Cygwin and did not realize that Perl was included :-). I suspect
that's true of a lot of Cygwin things.
--
I think I am an Elephant,
Behind another Elephant
Behind /another/ Elephant who isn't really there....
A.A. Milne
------------------------------
Date: Wed, 22 May 2013 02:51:20 -0700 (PDT)
From: cibalo <cibalo@gmx.co.uk>
Subject: Problem: perl negative look-ahead assertion in multi-line mode
Message-Id: <51f87fe3-e68a-44f5-83c9-1cb38847de94@ve4g2000pbb.googlegroups.com>
Hello,
I have updated/modified my mysql database in my free website recently.
I have to re-code all my php files such that an extra statement has to
be inserted before the last mysql_query call. It may have more than
one mysql_query call in some of my php files.
I try to use a negative look-ahead assertion to make such a change as
follows.
I would like to insert just one "new_insert" line before the "coding
line 4". And my php file looks like this.
$ echo -e "coding line 1 test 1\ncoding line 2 mysql_query 2\ncoding
line 3 test 3\ncoding line 4 mysql_query 4\ncoding line 5 test 5"
coding line 1 test 1
coding line 2 mysql_query 2
coding line 3 test 3
coding line 4 mysql_query 4
coding line 5 test 5
Then I perl-regex with negative look-ahead assertion in multi-line
mode (/smg or /sg or /mg) like this:
$ echo -e "coding line 1 test 1\ncoding line 2 mysql_query 2\ncoding
line 3 test 3\ncoding line 4 mysql_query 4\ncoding line 5 test 5" |
perl -pe '/mysql_query(?!.*mysql_query)/smg && print "new_insert\n"'
coding line 1 test 1
new_insert
coding line 2 mysql_query 2
coding line 3 test 3
new_insert
coding line 4 mysql_query 4
coding line 5 test 5
However, my "coding line 2" gets changed too. And that is not what I'm
looking for.
Or, perl negative look-ahead assertion doesn't like me! Can you please
let me know what I'm missing?
Thank you very much in advance!!!
Best Regards,
cibalo
------------------------------
Date: Wed, 22 May 2013 14:37:21 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Problem: perl negative look-ahead assertion in multi-line mode
Message-Id: <519cbc01$0$6554$9b4e6d93@newsspool4.arcor-online.net>
Am 22.05.2013 11:51, schrieb cibalo:
> I would like to insert just one "new_insert" line before the "coding
> line 4". And my php file looks like this.
>
> $ echo -e "coding line 1 test 1\ncoding line 2 mysql_query 2\ncoding
> line 3 test 3\ncoding line 4 mysql_query 4\ncoding line 5 test 5"
> coding line 1 test 1
> coding line 2 mysql_query 2
> coding line 3 test 3
> coding line 4 mysql_query 4
> coding line 5 test 5
>
> Then I perl-regex with negative look-ahead assertion in multi-line
> mode (/smg or /sg or /mg) like this:
>
> $ echo -e "coding line 1 test 1\ncoding line 2 mysql_query 2\ncoding
> line 3 test 3\ncoding line 4 mysql_query 4\ncoding line 5 test 5" |
> perl -pe '/mysql_query(?!.*mysql_query)/smg && print "new_insert\n"'
> coding line 1 test 1
> new_insert
> coding line 2 mysql_query 2
> coding line 3 test 3
> new_insert
> coding line 4 mysql_query 4
> coding line 5 test 5
>
> However, my "coding line 2" gets changed too. And that is not what I'm
> looking for.
>
> Or, perl negative look-ahead assertion doesn't like me!
In this case its not the look-ahead that's breaking things.
You're starting with a wrong assumption by running Perl with
the "-p" option, thus doing line-by-line processing of your
input. To be able to look ahead, the whole input must already
be known to your script, so you have to slurp your whole file
in one go (see "perldoc perlrun" for details):
echo ... | perl -0777 -pe ...
Now that you have the whole input in $_, you need to do regex
replacement instead of just matching to get your insert at the
correct place:
perl -0777 -pe 's/(mysql_query(?!.*mysql_query))/new_insert\n$1/sm'
You don't need the "g" modifier, as the replacement only needs
to happen once.
HTH
Chris
F'up to clpm set
------------------------------
Date: Wed, 22 May 2013 14:47:37 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: Problem: perl negative look-ahead assertion in multi-line mode
Message-Id: <knjeed$3ed$1@speranza.aioe.org>
On 5/22/2013 2:51 AM, cibalo wrote:
> Hello,
> I have updated/modified my mysql database in my free website recently.
> I have to re-code all my php files such that an extra statement has to
> be inserted before the last mysql_query call. It may have more than
> one mysql_query call in some of my php files.
>
> I try to use a negative look-ahead assertion to make such a change as
> follows.
>
> I would like to insert just one "new_insert" line before the "coding
> line 4". And my php file looks like this.
>
> $ echo -e "coding line 1 test 1\ncoding line 2 mysql_query 2\ncoding
> line 3 test 3\ncoding line 4 mysql_query 4\ncoding line 5 test 5"
> coding line 1 test 1
> coding line 2 mysql_query 2
> coding line 3 test 3
> coding line 4 mysql_query 4
> coding line 5 test 5
>
> Then I perl-regex with negative look-ahead assertion in multi-line
> mode (/smg or /sg or /mg) like this:
>
> $ echo -e "coding line 1 test 1\ncoding line 2 mysql_query 2\ncoding
> line 3 test 3\ncoding line 4 mysql_query 4\ncoding line 5 test 5" |
> perl -pe '/mysql_query(?!.*mysql_query)/smg && print "new_insert\n"'
> coding line 1 test 1
> new_insert
> coding line 2 mysql_query 2
> coding line 3 test 3
> new_insert
> coding line 4 mysql_query 4
> coding line 5 test 5
>
> However, my "coding line 2" gets changed too. And that is not what I'm
> looking for.
>
> Or, perl negative look-ahead assertion doesn't like me! Can you please
> let me know what I'm missing?
Since you want to insert just before the last mysql_query line, you can
use .* greediness to avoid a negative look-ahead:
echo ... |
perl -0777 -pe 's/ (.*) (coding .*? query .*? \n)/$1new_insert\n$2/sx'
--
Charles DeRykus
------------------------------
Date: Thu, 23 May 2013 15:33:54 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Problem: perl negative look-ahead assertion in multi-line mode
Message-Id: <87mwrlzrxp.fsf@sapphire.mobileactivedefense.com>
cibalo <cibalo@gmx.co.uk> writes:
> I have updated/modified my mysql database in my free website recently.
> I have to re-code all my php files such that an extra statement has to
> be inserted before the last mysql_query call. It may have more than
> one mysql_query call in some of my php files.
>
> I try to use a negative look-ahead assertion to make such a change as
> follows.
>
> I would like to insert just one "new_insert" line before the "coding
> line 4". And my php file looks like this.
>
> $ echo -e "coding line 1 test 1\ncoding line 2 mysql_query 2\ncoding
> line 3 test 3\ncoding line 4 mysql_query 4\ncoding line 5 test 5"
> coding line 1 test 1
> coding line 2 mysql_query 2
> coding line 3 test 3
> coding line 4 mysql_query 4
> coding line 5 test 5
Strictly, this isn't related to the shell and not related to Perl, but
if you want to make a modification to a set of text files, have you
considered using a text editor?
NB: The 'compound command' below was executed in a directory which
contained three copies of the 'demo file' whose content was included in
the original posting.
for x in *; do
ed "$x" <<'TT'
$
?mysql_query?i
new_insert
.
wq
TT
done
This invokes ed on every file in the current directory, with 'command
input' coming from a here document (separator quoted to prevent 'shell
expansion' of the text). The ed commands are
$
Go to the last line of the input file.
?mysql_query?i
Search backwards (regexp) for the first msql_query and insert text in
front of that line.
new_insert
The text to insert.
.
'Exit insert-mode' command.
wq
Write changes and quit (non-standard, BSD-originated command).
------------------------------
Date: Thu, 23 May 2013 05:46:57 -0700 (PDT)
From: Dailey Kohtz <dailey.kohtz@gmail.com>
Subject: Re: so how much money do perl programmers make?
Message-Id: <8d2e95c6-f5b0-4cba-87bc-8ea59db6e764@googlegroups.com>
On Tuesday, May 14, 2013 4:42:23 PM UTC-7, johannes falcone wrote:
> curious?
>
>
>
> rate get to 75/h w2 easily?
>
>
>
> or no?
the avverage is 81,000
------------------------------
Date: Thu, 23 May 2013 06:04:50 -0700 (PDT)
From: Dailey Kohtz <dailey.kohtz@gmail.com>
Subject: Would anyone teach me perl?
Message-Id: <3f2bbbfa-1485-4690-a1d5-5e877ff6c463@googlegroups.com>
I've practiced enough to do a helloworld program,but I've had trouble. I have the v5 and second adition O'Rielly.
titles:
Learning Perl
Programming Perl
Perl Cookbook
----------------------------------------------------------------------------------
Can anyone put the time in to teaching me to program?
Are you willing to help me even though I'm don't know how?
I'm a pretty fast learner, so don't even worry about getting flustered.
------------------------------
Date: Thu, 23 May 2013 14:57:22 +0100
From: Justin C <justin.1303@purestblue.com>
Subject: Re: Would anyone teach me perl?
Message-Id: <2rj17a-g8b.ln1@zem.masonsmusic.co.uk>
On 2013-05-23, Dailey Kohtz <dailey.kohtz@gmail.com> wrote:
> I've practiced enough to do a helloworld program,but I've had trouble. I have the v5 and second adition O'Rielly.
> titles:
> Learning Perl
> Programming Perl
> Perl Cookbook
> ----------------------------------------------------------------------------------
> Can anyone put the time in to teaching me to program?
> Are you willing to help me even though I'm don't know how?
> I'm a pretty fast learner, so don't even worry about getting flustered.
If you've got Learning Perl you don't need a teacher, it's
an excellent book. If you *really* insist on having a teacher
then try http://www.stonehenge.com - there may be other
teachers, but Randall and Tom wrote the book (literally).
Justin.
--
Justin C, by the sea.
------------------------------
Date: Thu, 23 May 2013 10:07:35 -0500
From: John Black <jblack@nospam.com>
Subject: Re: Would anyone teach me perl?
Message-Id: <MPG.2c07ecb5e13f19ba98977b@news.eternal-september.org>
In article <2rj17a-g8b.ln1@zem.masonsmusic.co.uk>, justin.1303@purestblue.com says...
> On 2013-05-23, Dailey Kohtz <dailey.kohtz@gmail.com> wrote:
> > I've practiced enough to do a helloworld program,but I've had trouble. I have the v5 and second adition O'Rielly.
> > titles:
> > Learning Perl
> > Programming Perl
> > Perl Cookbook
> > ----------------------------------------------------------------------------------
> > Can anyone put the time in to teaching me to program?
> > Are you willing to help me even though I'm don't know how?
> > I'm a pretty fast learner, so don't even worry about getting flustered.
>
>
> If you've got Learning Perl you don't need a teacher, it's
> an excellent book.
I think this guy is just trolling...
John Black
------------------------------
Date: Tue, 21 May 2013 19:26:22 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: XML parsing problem
Message-Id: <erqs6a-t541.ln1@anubis.morrow.me.uk>
Quoth Nachtmsk <mshavel@mac.com>:
>
> I am posting an XML file to a server for authentication.
> The server I post to responds back with some XML. In that XML is a
> token that I need to parse out.
> The data that I am being sent back is part XML and part HTTP header. I
> just can't seem to get the XML isolated to parse it. I'm thinking it
> has something to do with line breaks but I'm not sure. I have tried
> using the XML::Simple as well as regular expressions but nothing is
> working. Attached is the file I am getting returned from the server I
> am posting to. This is the file I need to parse the XML out of, just a
> few fields really, <Token> being the most important and <Status> being
> the other. Thanks for any help!
>
> I have attached the XML file I get back from the server I am posting
> to. I changed a few things, but just values in the Tags, nothing else.
> Here is the code I am using. It's commented out a lot because I have
> tried various methods.
>
> I guess the big issue I seem to be having when using XML::Simple is:
> *The XML returned has Non-XML in it, so XML::Simple is choking. I tried
> using RegEx to parse out just the XML from the returned file but
> nothing is working. I'm pretty decent with RegEx so I'm just not
> getting what is happening. Thanks!
>
> use CGI;
> #use DBI;
> use LWP::UserAgent;
> use HTTP::Request::Common;
> use XML::Simple;
> #use Data::Dumper;
>
> my($query)= new CGI;
>
> $u="test";
> $p="test";
>
>
> print $query->header();
>
> my $userAgent = LWP::UserAgent->new(agent => 'perl post');
>
> $message="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
> <NotificationRequest Version=\"1.0\"> <NotificationHeader>
> <Type>2</Type> Snip....";
>
> my $response = $userAgent->request(POST
> 'http://www.posttosite.com/web_service.php',
> Content_Type => 'text/xml',
> Content => $message);
>
> print $response->error_as_HTML unless $response->is_success;
>
> $res =$response->as_string;
Don't do that: this will give you the whole HTTP response, including the
header. You want either the ->content or ->decoded_content method.
> -=-=-=-=-=-
> [Alternative: text/html]
> -=-=-=-=-=-
Please don't do that.
Ben
------------------------------
Date: Tue, 21 May 2013 15:39:44 -0400
From: Michael Shavel <email@domain.com>
Subject: Re: XML parsing problem
Message-Id: <2013052115394414903-email@domaincom>
On 2013-05-21 14:26:22 -0400, Ben Morrow said:
> Quoth Nachtmsk <mshavel@mac.com>:
>>
>> I am posting an XML file to a server for authentication.
>> The server I post to responds back with some XML. In that XML is a
>> token that I need to parse out.
>> The data that I am being sent back is part XML and part HTTP header. I
>> just can't seem to get the XML isolated to parse it. I'm thinking it
>> has something to do with line breaks but I'm not sure. I have tried
>> using the XML::Simple as well as regular expressions but nothing is
>> working. Attached is the file I am getting returned from the server I
>> am posting to. This is the file I need to parse the XML out of, just a
>> few fields really, <Token> being the most important and <Status> being
>> the other. Thanks for any help!
>>
>> I have attached the XML file I get back from the server I am posting
>> to. I changed a few things, but just values in the Tags, nothing else.
>> Here is the code I am using. It's commented out a lot because I have
>> tried various methods.
>>
>> I guess the big issue I seem to be having when using XML::Simple is:
>> *The XML returned has Non-XML in it, so XML::Simple is choking. I tried
>> using RegEx to parse out just the XML from the returned file but
>> nothing is working. I'm pretty decent with RegEx so I'm just not
>> getting what is happening. Thanks!
>>
>> use CGI;
>> #use DBI;
>> use LWP::UserAgent;
>> use HTTP::Request::Common;
>> use XML::Simple;
>> #use Data::Dumper;
>>
>> my($query)= new CGI;
>>
>> $u="test";
>> $p="test";
>>
>>
>> print $query->header();
>>
>> my $userAgent = LWP::UserAgent->new(agent => 'perl post');
>>
>> $message="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
>> <NotificationRequest Version=\"1.0\"> <NotificationHeader>
>> <Type>2</Type> Snip....";
>>
>> my $response = $userAgent->request(POST
>> 'http://www.posttosite.com/web_service.php',
>> Content_Type => 'text/xml',
>> Content => $message);
>>
>> print $response->error_as_HTML unless $response->is_success;
>>
>> $res =$response->as_string;
>
> Don't do that: this will give you the whole HTTP response, including the
> header. You want either the ->content or ->decoded_content method.
>
>> -=-=-=-=-=-
>> [Alternative: text/html]
>> -=-=-=-=-=-
>
> Please don't do that.
>
> Ben
Thank you Ben! That's exactly what I needed to know.
------------------------------
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 3952
***************************************