[28536] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9900 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 27 18:10:22 2006

Date: Fri, 27 Oct 2006 15:10: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           Fri, 27 Oct 2006     Volume: 10 Number: 9900

Today's topics:
        Simple Regular expression problem <bigfred@gmail.com>
    Re: Simple Regular expression problem <thepoet_nospam@arcor.de>
    Re: Simple Regular expression problem <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: Simple Regular expression problem <tadmc@augustmail.com>
    Re: Simple Regular expression problem <bigfred@gmail.com>
    Re: Simple Regular expression problem <thepoet_nospam@arcor.de>
    Re: Simple Regular expression problem <glex_no-spam@qwest-spam-no.invalid>
    Re: Store multi-dimensions array for use in latter form <tzz@lifelogs.com>
    Re: Store multi-dimensions array for use in latter form <tadmc@augustmail.com>
    Re: Store multi-dimensions array for use in latter form (reading news)
    Re: Store multi-dimensions array for use in latter form xhoster@gmail.com
        Want to install Perl compiler <jainarunk@gmail.com>
    Re: Want to install Perl compiler <dorward@yahoo.com>
    Re: Want to install Perl compiler <mritty@gmail.com>
    Re: Want to install Perl compiler <john@castleamber.com>
    Re: Want to install Perl compiler <mritty@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 27 Oct 2006 12:42:26 -0700
From: "Krebul" <bigfred@gmail.com>
Subject: Simple Regular expression problem
Message-Id: <1161978146.875081.154180@e3g2000cwe.googlegroups.com>

Hi,

I'm trying to write a regular expression to escape the < charactar
within an XML file.  I only want to escape the character when its the
value of a node. Ex:

"<xmlnode>one < two</xmlnode>"

I want to convert that to:

"<xmlnode>one &lt; two</xmlnode>"

The logic I decided to use was to simply escape any < character,
followed by followed by another < character, without a > character in
between.

I cannot get  my regexp to work, but the closest I've come was:

$str =~ s/<.*?(?!>)</\&lt;$&</g;

Please advise what I'm doing wrong.

Thanks
-Krebul



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

Date: Fri, 27 Oct 2006 22:33:19 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Simple Regular expression problem
Message-Id: <45426cfe$0$18836$9b4e6d93@newsspool4.arcor-online.net>

Krebul wrote:
> I'm trying to write a regular expression to escape the < charactar
> within an XML file.  I only want to escape the character when its the
> value of a node. Ex:
> 
> "<xmlnode>one < two</xmlnode>"
> 
> I want to convert that to:
> 
> "<xmlnode>one &lt; two</xmlnode>"
> 
> The logic I decided to use was to simply escape any < character,
> followed by followed by another < character, without a > character in
> between.
> 
> I cannot get  my regexp to work, but the closest I've come was:
> 
> $str =~ s/<.*?(?!>)</\&lt;$&</g;
> 
> Please advise what I'm doing wrong.

For one you're misunderstanding the meaning of zero-width
assertions, for the second point your logic is flawed.
They way you describe your solution, you would escape the
opening brackets of the tags instead of in-betweens (in
fact, that's what you're doing, together with doubling up
the opening bracket in between).

Your look-ahead assertion is plainly ignored, as the
non-greedy .*? will of course not be followed by a closing
bracket when it's followed by an opening bracket.

What you want to do is to escape any opening angle bracket
that is followed by an arbitrary number of characters that
are _not_ closing angle brackets which are followed by another
opening angle bracket.

To put that description into a pattern:
s/
   <		# opening angle bracket
   (?=
     [^>]*	# anything but not a closing angle bracket
     <		# another opening angle bracket
   )
/&lt;/xg;

Note that here I have used the zero-width look-ahead (?=)
so that I don't capture anything from that subpattern, so
I don't have to care for any $1..$n or $& in the replacement.

The /x modifier lets me put in whitespace and comments in
the pattern, which makes it much more legible.

HTH
-Chris


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

Date: Fri, 27 Oct 2006 13:31:55 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Simple Regular expression problem
Message-Id: <su6a14x4ve.ln2@goaway.wombat.san-francisco.ca.us>

On 2006-10-27, Krebul <bigfred@gmail.com> wrote:
>
> I'm trying to write a regular expression to escape the < charactar
> within an XML file.  I only want to escape the character when its the
> value of a node. Ex:
>
> "<xmlnode>one < two</xmlnode>"
>
> I want to convert that to:
>
> "<xmlnode>one &lt; two</xmlnode>"

This seems to scream out to me to not use a regex, but one of
the XML parser modules.  XML::Simple is probably a good place
to start.

--keith

-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information



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

Date: Fri, 27 Oct 2006 15:12:25 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Simple Regular expression problem
Message-Id: <slrnek4q19.o20.tadmc@tadmc30.august.net>

Krebul <bigfred@gmail.com> wrote:

> The logic I decided to use was to simply escape any < character,
> followed by followed by another < character, without a > character in
> between.


   $str =~ s/<([^>]*<)/&lt;$1/g;


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


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

Date: 27 Oct 2006 13:58:17 -0700
From: "Krebul" <bigfred@gmail.com>
Subject: Re: Simple Regular expression problem
Message-Id: <1161982697.709981.98690@e3g2000cwe.googlegroups.com>

Thank you.  That was very helpful!


Christian Winter wrote:
> Krebul wrote:
> > I'm trying to write a regular expression to escape the < charactar
> > within an XML file.  I only want to escape the character when its the
> > value of a node. Ex:
> >
> > "<xmlnode>one < two</xmlnode>"
> >
> > I want to convert that to:
> >
> > "<xmlnode>one &lt; two</xmlnode>"
> >
> > The logic I decided to use was to simply escape any < character,
> > followed by followed by another < character, without a > character in
> > between.
> >
> > I cannot get  my regexp to work, but the closest I've come was:
> >
> > $str =~ s/<.*?(?!>)</\&lt;$&</g;
> >
> > Please advise what I'm doing wrong.
>
> For one you're misunderstanding the meaning of zero-width
> assertions, for the second point your logic is flawed.
> They way you describe your solution, you would escape the
> opening brackets of the tags instead of in-betweens (in
> fact, that's what you're doing, together with doubling up
> the opening bracket in between).
>
> Your look-ahead assertion is plainly ignored, as the
> non-greedy .*? will of course not be followed by a closing
> bracket when it's followed by an opening bracket.
>
> What you want to do is to escape any opening angle bracket
> that is followed by an arbitrary number of characters that
> are _not_ closing angle brackets which are followed by another
> opening angle bracket.
>
> To put that description into a pattern:
> s/
>    <		# opening angle bracket
>    (?=
>      [^>]*	# anything but not a closing angle bracket
>      <		# another opening angle bracket
>    )
> /&lt;/xg;
>
> Note that here I have used the zero-width look-ahead (?=)
> so that I don't capture anything from that subpattern, so
> I don't have to care for any $1..$n or $& in the replacement.
>
> The /x modifier lets me put in whitespace and comments in
> the pattern, which makes it much more legible.
> 
> HTH
> -Chris



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

Date: Fri, 27 Oct 2006 23:10:11 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Simple Regular expression problem
Message-Id: <454275a3$0$18846$9b4e6d93@newsspool4.arcor-online.net>

Keith Keller wrote:
> On 2006-10-27, Krebul <bigfred@gmail.com> wrote:
>> I'm trying to write a regular expression to escape the < charactar
>> within an XML file.  I only want to escape the character when its the
>> value of a node. Ex:
>>
>> "<xmlnode>one < two</xmlnode>"
[...]
> 
> This seems to scream out to me to not use a regex, but one of
> the XML parser modules.  XML::Simple is probably a good place
> to start.

XML::Simple is probably a bad place to start for not wellformed
XML data, and most probably the OP is just about to fix his
raw data so that it becomes parseable.

The only module I know of that may be worth a look is
XML::Liberal, which applies some fixups on its own, but I haven't
used this one at all.

-Chris


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

Date: Fri, 27 Oct 2006 16:12:27 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Simple Regular expression problem
Message-Id: <4542760f$0$498$815e3792@news.qwest.net>

Keith Keller wrote:
> On 2006-10-27, Krebul <bigfred@gmail.com> wrote:
>> I'm trying to write a regular expression to escape the < charactar
>> within an XML file.  I only want to escape the character when its the
>> value of a node. Ex:
>>
>> "<xmlnode>one < two</xmlnode>"
>>
>> I want to convert that to:
>>
>> "<xmlnode>one &lt; two</xmlnode>"
> 
> This seems to scream out to me to not use a regex, but one of
> the XML parser modules.  XML::Simple is probably a good place
> to start.

Except that since it's not valid XML, it can't be parsed.

% perl -MXML::Simple -e'XMLin( "<xmlnode>one < two</xmlnode>" )'
Invalid element name [Ln: 1, Col: 14]

If possible, fix whatever is generating the invalid XML.

Also, '>' and '&' need to be encoded too, not just '<'.


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

Date: Fri, 27 Oct 2006 21:20:33 +0100
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Store multi-dimensions array for use in latter form?
Message-Id: <g69d58do6i6.fsf@lifelogs.com>

On 27 Oct 2006, shareparadise@gmail.com wrote:

> > > This project I'm doing is an assignment which will be tested on the
> > > school server, and I know that server doesnt have session module
> > > installed. I dont know if the grader would be kind enough to install it
> > > for me, and I dont want to risk here.

> This homework is not about passing the array between forms, Ted. It's a
> XML processor, and Im not asking anyone to write that for me. Im stuck
> at passing the array between form, and I ask for help with that, tell
> me what's wrong with it then?

Note your original text above.  The problem you are trying to solve is
a part of the homework.  You are supposed to do it on your own, aren't
you?  If not, you should specifically say that it's unrelated or that
you are allowed to seek outside help.

> If you dont see if you can help then it's fine, you dont need to add
> any uh-helpful comment like that!

My response was very helpful, actually.  You should take one of two
lessons out of it:

1) don't say it's for a homework problem next time and post under a
   different name.

2) do the work on your own, THEN talk to your teacher/TF/course aide
   if you can't figure it out, THEN ask on Usenet if they say it's OK
   and can't help you further.

I hope you choose the latter.  But my goal was just to tell you that
you won't get much help if it's for a homework, not to pass judgment.

As for passing complex data between sessions, store a simple key
(e.g. an integer) in the cookie, and that's your key into a database.
The choice of key and database are up to you, since you didn't tell
us what resources are available on the server.

Generally if the choice is between writing your own code and relying
on a module, try to get the module installed before you write your
own.  Trust me, you don't want to reinvent the wheel.

Ted


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

Date: Fri, 27 Oct 2006 15:17:05 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Store multi-dimensions array for use in latter form?
Message-Id: <slrnek4qa1.o20.tadmc@tadmc30.august.net>

shareparadise@gmail.com <shareparadise@gmail.com> wrote:

> This homework is not about passing the array between forms, Ted. It's a
> XML processor, and Im not asking anyone to write that for me. Im stuck
> at passing the array between form, and I ask for help with that, tell
> me what's wrong with it then?


Nothing. But we could not tell that from your original post.

It is a fairly common thing hereabouts for folks to ask us to
do their programming for them.


> If you dont see if you can help then it's fine, you dont need to add
> any uh-helpful comment like that!


There _is_ something wrong with displaying that bad attitude though.

So long!


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


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

Date: Fri, 27 Oct 2006 21:21:43 GMT
From: "Mumia W. (reading news)" <paduille.4060.mumia.w@earthlink.net>
Subject: Re: Store multi-dimensions array for use in latter form?
Message-Id: <HLu0h.13792$Lv3.3121@newsread1.news.pas.earthlink.net>

On 10/26/2006 10:22 PM, shareparadise@gmail.com wrote:
> This project I'm doing is an assignment which will be tested on the
> school server, and I know that server doesnt have session module
> installed. I dont know if the grader would be kind enough to install it
> for me, and I dont want to risk here.
> 
> 
> This is how I tried to do it with cookie:
> 
> my $query = new CGI;
> 
> my $cookie = $query->cookie( -name     => 'table',
>                                      -value    => @table, # tried
> $table and \@table as well

That won't work because you will only get the size of @table into the value.

>                                      -expires  => '+1M',
>                                      -path     => '/'
>                                     );
> print
> $query->header(-cookie=>$cookie),$query->start_html(-title=>"Testing2");
> # .....
> 
> # Then tried to retrieve it using this:
> my @table = $query->cookie(-name=>'table');
> 
> Actually I tried with 1 dim array and it worked well, I dont know what
> goes wrong here? This is my first hand experience with Perl so Im still
> kinda confused.
> 
> Thanks.
> 

If table is small enough, you can place the entire table into the 
cookie; however, cookies only accept scalar values, and tables don't go 
into scalars naturally; you need to convert them.

Use Data::Dumper to convert the table onto a scalar string, URL-encode 
that string and place it into the cookie.

To extract the table data from the cookie, URL-decode the cookie string 
and "eval" the decoded string.

If the data is truly simple, you can write your own subs for converting 
the table into a string and back again.

-- 
paduille.4060.mumia.w@earthlink.net


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

Date: 27 Oct 2006 21:50:25 GMT
From: xhoster@gmail.com
Subject: Re: Store multi-dimensions array for use in latter form?
Message-Id: <20061027175128.001$cT@newsreader.com>

"Mumia W. (reading news)" <paduille.4060.mumia.w@earthlink.net> wrote:
>
> To extract the table data from the cookie, URL-decode the cookie string
> and "eval" the decoded string.

You shouldn't eval a string that is coming from a cookie.  Who knows what
someone stuck in that string when you weren't looking.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 27 Oct 2006 11:41:51 -0700
From: "Vinay Nagrik" <jainarunk@gmail.com>
Subject: Want to install Perl compiler
Message-Id: <1161974511.460812.274410@b28g2000cwb.googlegroups.com>

Hello Group,

Where can I get the Perl compiler?  Is it free?  My requirement is to
install it Windows XP machine.

Someone suggested me that I should opt for Cygwin instead?  Could
someone give me a feedback
on this issue.

I do not want to go on the impulse to very first suggestion I get (like
install cygwin).  I detailed
feedback will be very much appreciated.  It will save me a lot of
troubles.  

Thanks.

nagrik



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

Date: Fri, 27 Oct 2006 19:57:01 +0100
From: David Dorward <dorward@yahoo.com>
Subject: Re: Want to install Perl compiler
Message-Id: <ehtkqe$sti$2$8300dec7@news.demon.co.uk>

Vinay Nagrik wrote:

> Where can I get the Perl compiler?

http://www.perl.org/get.html

> Is it free?  

Yes

> Someone suggested me that I should opt for Cygwin instead?  Could
> someone give me a feedback on this issue.

Cygwin is one way to get a perl for Windows, the other common one is
ActiveState's ActivePerl. I've not compared them. Cygwin does have the
advantage of having other UNIX tools for Windows (such as bash and an X
server), but there is nothing stopping you using those tools in conjunction
with ActivePerl.

-- 
David Dorward       <http://blog.dorward.me.uk/>   <http://dorward.me.uk/>
                     Home is where the ~/.bashrc is


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

Date: 27 Oct 2006 12:18:04 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Want to install Perl compiler
Message-Id: <1161974755.706619.192120@m7g2000cwm.googlegroups.com>

Vinay Nagrik wrote:
> Where can I get the Perl compiler?  Is it free?  My requirement is to
> install it Windows XP machine.
>
> Someone suggested me that I should opt for Cygwin instead?  Could
> someone give me a feedback
> on this issue.
>
> I do not want to go on the impulse to very first suggestion I get (like
> install cygwin).  I detailed
> feedback will be very much appreciated.  It will save me a lot of
> troubles.

Cygwin is a set of programs that give you Unix-like access to your
Windows machine.  If you just want Perl and don't care about any of the
other Unix-ish commands Cygwin could provide for you, you probably just
want ActiveState's release of perl.  Follow the links from
http://www.activestate.com/Products/ActivePerl/?mp=1 to download and
install it.  Yes, it is free.

Once you've installed it, you can read all the built-in documentation
by going to Start->Programs->ActiveState ActivePerl->Documentation.
Or, you can open up a command window and type `perldoc perlintro`.

Hope this helps,
Paul Lalli



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

Date: 27 Oct 2006 19:44:10 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Want to install Perl compiler
Message-Id: <Xns986995E61E23Bcastleamber@130.133.1.4>

"Vinay Nagrik" <jainarunk@gmail.com> wrote:

> Hello Group,
> 
> Where can I get the Perl compiler?  Is it free?  My requirement is to
> install it Windows XP machine.

AFAIK there is no real Perl compiler as in perl script in -> exe out. 
There are packers like perl2exe, and PAR, but they pack perl.exe and the 
script in one file AFAIK.

If you're looking for a compiler in order to protect your code, give it up 
:-)


If by Perl compiler you mean the thingy that compiles the program and then 
executes it, check out http://activestate.com/

If you have no experience with cygwin, and are a beginner, it might be not 
the best idea to use cygwin IMO.

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: 27 Oct 2006 13:03:59 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Want to install Perl compiler
Message-Id: <1161975306.008312.171310@k70g2000cwa.googlegroups.com>

Vinay Nagrik wrote:
> Where can I get the Perl compiler?  Is it free?  My requirement is to
> install it Windows XP machine.
>
> Someone suggested me that I should opt for Cygwin instead?  Could
> someone give me a feedback
> on this issue.
>
> I do not want to go on the impulse to very first suggestion I get (like
> install cygwin).  I detailed
> feedback will be very much appreciated.  It will save me a lot of
> troubles.

Cygwin is a set of programs that give you Unix-like access to your
Windows machine.  If you just want Perl and don't care about any of the
other Unix-ish commands Cygwin could provide for you, you probably just
want ActiveState's release of perl.  Follow the links from
http://www.activestate.com/Products/ActivePerl/?mp=1 to download and
install it.  Yes, it is free.

Once you've installed it, you can read all the built-in documentation
by going to Start->Programs->ActiveState ActivePerl->Documentation.
Or, you can open up a command window and type `perldoc perlintro`.

Hope this helps,
Paul Lalli



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

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 9900
***************************************


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