[25657] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7899 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 20 18:05:24 2005

Date: Sun, 20 Mar 2005 15:05:05 -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, 20 Mar 2005     Volume: 10 Number: 7899

Today's topics:
        Help simplify complex regexp needing positive lookahead david.karr@wamu.net
    Re: Help simplify complex regexp needing positive looka <spamtrap@dot-app.org>
    Re: IP address, how? <nospam@bigpond.com>
    Re: IP address, how? <wyzelli@yahoo.com>
    Re: OOP Tutorial (Anno Siegel)
    Re: Perl program help to sort of 'pad name xy' file <see.sig@rochester.rr.com>
    Re: regular expression help with apostrophe (Anno Siegel)
        Script that sends email to text box value <cdrossen@cdrmarketing.com>
        Will XML::Simple work with keys, strings, integers, and <noway@nohow.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Mar 2005 10:29:19 -0800
From: david.karr@wamu.net
Subject: Help simplify complex regexp needing positive lookahead and reluctant quantifers
Message-Id: <1111343359.670584.217900@z14g2000cwz.googlegroups.com>

My code is in Java, but my problem is a complicated regexp.
Ironically, I think I'm more likely to get a better response in here
than elsewhere.  It's too bad there's no "regular expressions"
newsgroup (that I can find).

My sample data is the following (abstracted from real data):
--------------
*XXXlkjsflkw34lkjsfd
2XXXlkjsdfojsfjoimf344
3XXXabcdef9999999
4XXX9f9f9f9f9f9f9f9f
5XXXg8g8g8g8g8g8g8g
6XXXe6e6e6e6e6e6e6e6e
 YYY=D/23333333
 -xxxxxxxxxxxx
 -yyyyyyyyyyyy
 ZZZ=gggggggggggg
 AAA=hhhhhhhhhh
 -jjjjjjjjjjj
 -kkkkkkkkkkk
/XXX 2
--------------

The important elements are "XXX", "YYY", "ZZZ", and "AAA".  Each of
"YYY", "ZZZ", and "AAA" could be in any order, and some could be
missing, or others like it could be added.  What I'd like to build is a
regexp that can group each of "YYY", "ZZZ", and "AAA" along with their
"associated data", up to either the next "[A-Z]{3}=", or the ending
"/XXX".  If I can get the "associated data" into group values, I can
use other regexps for the detail in those group values.

The regexp that I've built so far comes close to solving this, but not
quite.  This is what I have so far (translated from Java string syntax
to Perl):

--------------
"(?sm)\\*.{3}.*\n" .
"2.{3}.*\n" .
"3.{3}.*\n" .
"4.{3}.*\n" .
"5.{3}.*\n" .
"6.{3}.*\n" .
" ([A-Z]{3}=)(.*?)(?= [A-Z]{3}=|/[A-Z]{3})" .
" ([A-Z]{3}=)(.*?)(?= [A-Z]{3}=|/[A-Z]{3})" .
" ([A-Z]{3}=)(.*?)(?= [A-Z]{3}=|/[A-Z]{3})" .
"/[A-Z]{3}.*"
--------------

You can ignore for now the fact that I'm not verifying that all the
places that require "XXX" are all "XXX".  The problem area is the
"[A-Z]{3}=" groups.  This regexp works for my sample data, but I wasn't
able to simplify those three repeated lines into a single expression,
which would handle any number of those.  I tried the following, to
replace those three lines:

"( ([A-Z]{3}=)(.*?)(?= [A-Z]{3}=|/[A-Z]{3}))*"

but that didn't seem to work, and I'm not sure why.

The following is the output from my Java program, using the working
regexp, where it iterated through the found groups.  I provide this
just as another view of what I'm trying to capture:

--------------
group[YYY=]
group[D/23333333
 -xxxxxxxxxxxx
 -yyyyyyyyyyyy
]
group[ZZZ=]
group[gggggggggggg
]
group[AAA=]
group[hhhhhhhhhh
 -jjjjjjjjjjj
 -kkkkkkkkkkk
]
--------------



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

Date: Sun, 20 Mar 2005 15:59:54 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Help simplify complex regexp needing positive lookahead and reluctant quantifers
Message-Id: <0r6dnaalOdjQeaDfRVn-sw@adelphia.com>

david.karr@wamu.net wrote:

> My code is in Java, but my problem is a complicated regexp.
> Ironically, I think I'm more likely to get a better response in here
> than elsewhere.  It's too bad there's no "regular expressions"
> newsgroup (that I can find).

No, but there is definitely a Java group.

I'm not just being snide - implementations of regular expressions vary. An
answer you get here may not apply to Java, and answers you get here or in a
Java group may not apply to sed, and so forth. You'd be far better off
asking your question in a group that's focused on the particular
implementation that you're using.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Sun, 20 Mar 2005 12:32:59 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: IP address, how?
Message-Id: <3a45mrF6686fuU1@individual.net>

warpman wrote:

> I'm new to perl and need some help. I currently have a guestbook that
> when a user posts a message I get the following information.
> 
> You have a new entry in your guestbook:
> message text area...
> city, st country - date and time
> 
> My question is how do I get the IP address from the person posting the
> message sent to me? Why the IP? Well, because lately I've been getting
> a lot of spam on the guestbook. Any help or information would be
> appreciated.

If you use Apache its passed as an environment variable.

gtoomey


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

Date: Sun, 20 Mar 2005 07:19:47 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: IP address, how?
Message-Id: <nu9%d.4548$C7.154@news-server.bigpond.net.au>

"Gregory Toomey" <nospam@bigpond.com> wrote in message 
news:3a45mrF6686fuU1@individual.net...
: warpman wrote:
:
: > I'm new to perl and need some help. I currently have a guestbook that
: > when a user posts a message I get the following information.
: >
: > You have a new entry in your guestbook:
: > message text area...
: > city, st country - date and time
: >
: > My question is how do I get the IP address from the person posting the
: > message sent to me? Why the IP? Well, because lately I've been getting
: > a lot of spam on the guestbook. Any help or information would be
: > appreciated.
:
: If you use Apache its passed as an environment variable.

It's passed as an environment variable whether you use Apache or not...

P 




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

Date: 20 Mar 2005 13:39:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: OOP Tutorial
Message-Id: <d1jue8$ffj$1@mamenchi.zrz.TU-Berlin.DE>

David Combs <dkcombs@panix.com> wrote in comp.lang.perl.misc:

> FYI: Abigail is a HE.

Woof!

Anno


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

Date: Sun, 20 Mar 2005 02:43:39 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: Perl program help to sort of 'pad name xy' file
Message-Id: <vr5%d.100853$H05.37104@twister.nyroc.rr.com>

vlsidesign wrote:

> Thanks Joel for your response.
> 
> Your assumption was correct, I would start from top-left corner. The
> pads are not staggered so it sounds like it would work beautifully.
> Your suggestion sounds very cool, and clever.
> 
> I did a google search and some reading so here goes, sorry if it is
> crude and not quite accurate... So if O is the origin (0,0) of my x y
> coordinate plane. I can take Pythagorems theorem for the radius r.   So
> r = to the square root of (x^2 + y^2). Also if v = theta (angle) then
> y = r sin v, x = r  cos v, y/x=tan v, so v = tan-1(y/x).
> 
> Is that correct? I then could sort v (which is the angle) in PERL from
> there??
> 

Yep, you've got it.  You might note that Perl has builtin the 
atan2(y,x) function which computes the four-quadrant arctan(y/x) 
correctly, in radians.

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


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

Date: 20 Mar 2005 15:07:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regular expression help with apostrophe
Message-Id: <d1k3j2$j1d$1@mamenchi.zrz.TU-Berlin.DE>

Ted Zlatanov  <tzz@lifelogs.com> wrote in comp.lang.perl.misc:
> On Wed, 16 Mar 2005, mritty@gmail.com wrote:
> 
> > "Ted Zlatanov" <tzz@lifelogs.com> wrote in message
> > news:4n7jk7o9b3.fsf@lifelogs.com...
> >> This example does not have anything to do with the $1...$9 variables.
> >> There are only 9 of them,
> > 
> > Who on earth told you that?
> 
> In my defense, there ARE only 9 of the $1 ... $9 variables :)

You mean the backreferences \1 ... \9.

Anno


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

Date: Sun, 20 Mar 2005 14:59:24 -0800
From: "C. David Rossen" <cdrossen@cdrmarketing.com>
Subject: Script that sends email to text box value
Message-Id: <QOSdnX5U5-DZnaPfRVn-rw@comcast.com>

Hello:

I am looking for a script that will send an email to whatever address is
entered into the text box. I usually use formmail.pl, but with that, the
recipient is a hidden field and is specified in the html code. I want to use
that, but I want the email to also be sent to the address that is entered in
the email text box. Any help would be greatly appreciated.  Thanks.

David




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

Date: Sun, 20 Mar 2005 03:41:13 GMT
From: Wes Barris <noway@nohow.com>
Subject: Will XML::Simple work with keys, strings, integers, and dates?
Message-Id: <th6%d.4321$C7.2935@news-server.bigpond.net.au>

Hi,

I am trying to use XML::Simple to parse an xml file.  However, the xml file
that I am trying to parse is not in the same format as any of the XML::Simple
examples that I have seen.  In all of the examples I have seen, the xml tags
are specific to their contents.  In my xml file, the tag names are generic.
Here is a short sample of the xml that I am trying to parse:

	<dict>
		<key>35</key>
		<dict>
			<key>Track ID</key><integer>35</integer>
			<key>Name</key><string>Earache My Eye (Full Version)</string>
			<key>Artist</key><string>Alice Bowie</string>
			<key>Genre</key><string>Specialty Rock</string>
			<key>Kind</key><string>MPEG audio file</string>
			<key>Size</key><integer>6459519</integer>
			<key>Total Time</key><integer>322951</integer>
			<key>Date Modified</key><date>2005-02-16T12:03:00Z</date>
			<key>Date Added</key><date>2005-02-16T11:59:14Z</date>
			<key>Bit Rate</key><integer>160</integer>
			<key>Sample Rate</key><integer>44100</integer>
			<key>Track Type</key><string>File</string>
		 
<key>Location</key><string>file://localhost/M:/1970s/Alice%20Bowie%20-%20Earache%20My%20Eye.mp3/</string>
			<key>File Folder Count</key><integer>2</integer>
			<key>Library Folder Count</key><integer>1</integer>
		</dict>
		<key>36</key>
		<dict>
			<key>Track ID</key><integer>36</integer>
			<key>Name</key><string>Earache My Eye</string>
			<key>Artist</key><string>Cheech &#38; Chong</string>
			<key>Genre</key><string>Specialty Rock</string>
			<key>Kind</key><string>MPEG audio file</string>
			<key>Size</key><integer>1875968</integer>
			<key>Total Time</key><integer>156204</integer>
			<key>Date Modified</key><date>2005-02-16T12:03:21Z</date>
			<key>Date Added</key><date>2005-02-16T11:59:15Z</date>
			<key>Bit Rate</key><integer>96</integer>
			<key>Sample Rate</key><integer>32000</integer>
			<key>Track Type</key><string>File</string>
		 
<key>Location</key><string>file://localhost/M:/1970s/Cheech%20&#38;%20Chong%20-%20Earache%20My%20Eye.mp3/</string>
			<key>File Folder Count</key><integer>2</integer>
			<key>Library Folder Count</key><integer>1</integer>
		</dict>

I would like to be able to extract things like the "Name", "Artist", and
"Location" but I don't understand how to associate one of the elements of
the key array with one of the elements of the resulting string array.


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

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


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