[28932] in Perl-Users-Digest
Perl-Users Digest, Issue: 176 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 27 00:39:39 2007
Date: Mon, 26 Feb 2007 21:39:31 -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 Mon, 26 Feb 2007 Volume: 11 Number: 176
Today's topics:
Transitioning Web Site gboutel@paradise.net.nz
Re: Transitioning Web Site <wahab-mail@gmx.de>
Re: Transitioning Web Site gboutel@paradise.net.nz
Re: Transitioning Web Site <sbryce@scottbryce.com>
Re: Transitioning Web Site gboutel@paradise.net.nz
trapping a manual close signal paul.shepherd@virgin.net
Re: trapping a manual close signal <1usa@llenroc.ude.invalid>
Re: trapping a manual close signal <bik.mido@tiscalinet.it>
Re: Unable to install Math::BigInt::GMP on Solaris 10 sumitbee@gmail.com
Unexpected RegEx results QoS@domain.invalid.com
Re: Unexpected RegEx results <jgibson@mail.arc.nasa.gov>
Re: Unexpected RegEx results QoS@domain.invalid.com
Re: Unexpected RegEx results <someone@example.com>
Re: Unexpected RegEx results <wahab-mail@gmx.de>
Re: Unexpected RegEx results QoS@domain.invalid.com
Re: Unexpected RegEx results <wahab-mail@gmx.de>
Re: Using Substr and Regular expressions. <kent.westmoreland@gmail.com>
Re: which is more powerfull ? <chaotrope@jps.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 25 Feb 2007 13:46:32 -0800
From: gboutel@paradise.net.nz
Subject: Transitioning Web Site
Message-Id: <1172439992.086079.67500@q2g2000cwa.googlegroups.com>
Dear Perl Gurus,
I have a slight situation involving transitioning a web site from one
host to another. The site has a number of Perlscript based
applications. It's a government website and 4 out of 5 applications
have been successfully transferred, which indicates that perlscript is
being understood on the new server - but getting this final
application up and running is, to use the vernacular, doing my head
in.
It could very well be an IIS situation (there is a transfer from IIS5
to IIS6 involved, also Win2000 to Win2003), in which case this would
not be the appropriate group to consult, but there are deadlines and
other ugly considerations so I'm wanting to cover my bases. Also, the
functions involved are rather embarrassingly basic, so I would be
surprised if it was a server issue - I've been bitten before by
reserved words I wasn't aware of so that's a possibility.
The problem is, in a nutshell, a perpetual syntax error. Normally you
might think this would be a misplaced semi-colon or something, but
this has proved not to be the case.
Here is a C&P of the exact error:
----------------
PerlScript Error error '80004005'
syntax error
/parentalleave/calculate/_private/common.inc, line 78
-------------------
Here, for the record, is line 78 of common.inc (surrounded by nearby
lines)
-------------------
"startworkdaterequired" => "Please enter the start work date",
"hoursworkederequired" => "Please enter the number of hours per
week worked",
(78 - parenthesis added for demo purposes)---> "badDOB" => "The
birth date or due date is invalid.",
"badstartworkdate" => "The start work date is invalid",
"badhoursworked" => "Please enter numbers only in the hours
worked field",
-------------------------
It's part of a basic hash declaration for error messages - there is no
wizardry occurring. Even if I comment out line 78 - I get the same
error on the same line - as if the file is being absorbed but not
understood at all and the parser is just giving up at that point It's
exactly the same files that previously worked on our prior hosts,
which can be observed at
http://www.ers.dol.govt.nz/parentalleave/calculate/index.html
For reference purposes, here are the initial declarations:
-----------------------
<%
#common.inc
#Global variables and routines for the ERS Parental Leave
Entitlement Caclulators
use lib 'd:\inetpub\ers-production\bin\';
use strict;
use TWL::WebTools;
use Date::Calc qw(Date_to_Days Today Add_Delta_Days Month_to_Text
Today_and_Now Add_Delta_YMD);
--------------------------
Date::calc is the only additional module from the base Activestate
installation aside from some server based globals being declared in
TWL, and they are working fine in other applications. The inclusion
of Carp does not change the error message in the slightest :-( Every
other .pm seems to be working as intended.
Originally, I was thinking that IIS was not comprehending .inc files,
but the same error persists even if files are renamed as .ASP or if
all the code is included on the one page.
I have been through the FAQ and ferreting through usenet history but
so far....nothing. I guess I'm looking for suggestions for other
walls to try banging my head against. It's been a couple of years
since I did any real Perl coding, so I'm guessing my Perl-fu is,
unfortunately, stoppable. Any suggestions would be more than
appreciated and if there is any more information which might assist
diagnosis, I am more than happy to provide.
Cheers,
-Giles
------------------------------
Date: Sun, 25 Feb 2007 23:46:06 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Transitioning Web Site
Message-Id: <ert3ti$gvv$1@mlucom4.urz.uni-halle.de>
gboutel@paradise.net.nz wrote:
> Here, for the record, is line 78 of common.inc (surrounded by nearby
> lines)
> -------------------
> "startworkdaterequired" => "Please enter the start work date",
> "hoursworkederequired" => "Please enter the number of hours per
> week worked",
> (78 - parenthesis added for demo purposes)---> "badDOB" => "The
> birth date or due date is invalid.",
> "badstartworkdate" => "The start work date is invalid",
> "badhoursworked" => "Please enter numbers only in the hours
> worked field",
> -------------------------
>
> It's part of a basic hash declaration for error messages - there is no
> wizardry occurring. Even if I comment out line 78 - I get the same
> error on the same line - as if the file is being absorbed but not
> understood at all and the parser is just giving up at that point It's
> exactly the same files that previously worked on our prior hosts,
> which can be observed at
What happens if you remove #78 altogether ans
duplicate #77 on #78
from:
"hoursworkederequired" => "Please enter the number of hours per week worked",
"badDOB" => "The birth date or due date is invalid.",
to
"hoursworkederequired" => "Please enter the number of hours per week worked",
"hoursworkederequired" => "Please enter the number of hours per week worked",
And, are you sure, #78 is the line YOU EXPECT it would be?
Put in some obvious error *before* and look what line
number is reported by the PerlScript interpreter.
Regards
M.
------------------------------
Date: 25 Feb 2007 15:10:39 -0800
From: gboutel@paradise.net.nz
Subject: Re: Transitioning Web Site
Message-Id: <1172445039.055883.108960@m58g2000cwm.googlegroups.com>
On Feb 26, 11:46 am, Mirco Wahab <wahab-m...@gmx.de> wrote:
>
> What happens if you remove #78 altogether ans
> duplicate #77 on #78
>
> from:
>
> "hoursworkederequired" => "Please enter the number of hours per week worked",
> "badDOB" => "The birth date or due date is invalid.",
>
> to
>
> "hoursworkederequired" => "Please enter the number of hours per week worked",
> "hoursworkederequired" => "Please enter the number of hours per week worked",
>
> And, are you sure, #78 is the line YOU EXPECT it would be?
> Put in some obvious error *before* and look what line
> number is reported by the PerlScript interpreter.
>
> Regards
>
> M.
If I put in a obvious error such as:
a;sfajf;asjf;alj;
in the first line I get the same Syntax error for the same line
(though plus one because of the extra line).
Replacing lines with other, previous lines doesn't seem to change
anything - same error, same place. If I comment out the specific Hash
declaration , it just produces the same syntax error later on. If I
comment out or remove just that line, I get the same syntax error on
the same line number.
This is making me think along the lines of an interpretation
difficulty/limitation - as in it's throwing in the towel because it's
got a a certain point and won't accept any more garbage, rather than
there being something specifically wrong with the code, which clearly
works on the prior server. Which just seems odd, as there are other
applications of greater length and complexity on the same site working
as intended.
I have been careful while transferring the files to make sure they are
untouched by errant text editors and their tricksy hidden characters -
so I am fairly sure what is working on the initial site is the same as
the code on the new site - hence my foncusion. I realise the platform
is not exactly the same, but don't know what kind of factors might be
creating such a situation. It's definitely finding the included page,
but just doesn't appear to be processing/interpreting it before it
gives up (and, again, the same thing (syntax error) happens if all
the code is placed in the page itself).
Thanks for your assistance :-) It's much appreciated.
Cheers,
-Giles
------------------------------
Date: Sun, 25 Feb 2007 17:59:19 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Transitioning Web Site
Message-Id: <opednRuHlMh6rX_YnZ2dnUVZ_sapnZ2d@comcast.com>
gboutel@paradise.net.nz wrote:
> Even if I comment out line 78 - I get the same
> error on the same line - as if the file is being absorbed but not
> understood at all and the parser is just giving up at that point
Look for mis-matched or missing quotes in an earlier line. Something like:
$some_var = "a string';
It's just a guess, but I've seen this sort of thing before.
Try removing line 78, and see if the error message changes. That should
give you an idea where to look.
------------------------------
Date: 26 Feb 2007 15:43:02 -0800
From: gboutel@paradise.net.nz
Subject: Re: Transitioning Web Site
Message-Id: <1172533382.303115.196420@t69g2000cwt.googlegroups.com>
On Feb 26, 1:59 pm, Scott Bryce <sbr...@scottbryce.com> wrote:
> gbou...@paradise.net.nz wrote:
> > Even if I comment out line 78 - I get the same
> > error on the same line - as if the file is being absorbed but not
> > understood at all and the parser is just giving up at that point
>
> Look for mis-matched or missing quotes in an earlier line. Something like:
>
> $some_var = "a string';
>
> It's just a guess, but I've seen this sort of thing before.
>
> Try removing line 78, and see if the error message changes. That should
> give you an idea where to look.
This proved to be prescient - only it wasn't quite as obvious as
that. The line was $some_var = "a string wit' an apostrophe, ending
with a double quote"; which was being misinterpreted owing to a prior
error. By escaping the single quote, we found another in a commented
out line! Escaping that also we iterated through as the chain of
error messages got much more helpful and finally progress was being
made. I'm still not sure why it only affected the new site and not
the other code - different Activestate versions perhaps? Character
set on servers?
Anyhow - thanks for the replies :-)
-Giles
------------------------------
Date: 25 Feb 2007 09:27:21 -0800
From: paul.shepherd@virgin.net
Subject: trapping a manual close signal
Message-Id: <1172424441.503614.96670@q2g2000cwa.googlegroups.com>
Hi
i have a simple file transfer script that moves files between
different directories continuously on a loop. It runs as a dos
console on the server. Trouble is I want to somehow trap the manual
shut down of it when one of my support guys hits the X or goes to
close. I want to trap this and log it. That way i know it was shut
down and didn't crash.
Any ideas how?
ta
------------------------------
Date: Sun, 25 Feb 2007 18:01:47 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: trapping a manual close signal
Message-Id: <Xns98E28491B3B3Basu1cornelledu@127.0.0.1>
paul.shepherd@virgin.net wrote in news:1172424441.503614.96670
@q2g2000cwa.googlegroups.com:
> i have a simple file transfer script that moves files between
> different directories continuously on a loop. It runs as a dos
> console on the server. Trouble is I want to somehow trap the manual
> shut down of it when one of my support guys hits the X or goes to
> close. I want to trap this and log it. That way i know it was shut
> down and didn't crash.
My guess is you'll need to dive into the Windows API for that and find a
way to catch the WM_CLOSE notification:
http://msdn2.microsoft.com/en-us/library/ms632617.aspx
I don't know how that works for console apps.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sun, 25 Feb 2007 20:28:21 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: trapping a manual close signal
Message-Id: <uno3u2lqvcviuqq6iphdn1ar5bdvh9kfe2@4ax.com>
On 25 Feb 2007 09:27:21 -0800, paul.shepherd@virgin.net wrote:
>i have a simple file transfer script that moves files between
>different directories continuously on a loop. It runs as a dos
>console on the server. Trouble is I want to somehow trap the manual
>shut down of it when one of my support guys hits the X or goes to
>close. I want to trap this and log it. That way i know it was shut
>down and didn't crash.
In Tk it would be a matter of a call to the protocol() method:
$mw->protocol('WM_DELETE_WINDOW' => sub {
print "Do stuff here before the exit\n";
exit;
});
Perhaps you may want to convert you console based app to a *minimal*
GUI one.
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: 24 Feb 2007 09:04:06 -0800
From: sumitbee@gmail.com
Subject: Re: Unable to install Math::BigInt::GMP on Solaris 10
Message-Id: <1172336646.037378.298700@h3g2000cwc.googlegroups.com>
On Feb 22, 10:19 pm, "Sisyphus" <sisyph...@nomail.afraid.com> wrote:
> <sumit...@gmail.com> wrote in message
>
> news:1172178117.033755.326430@s48g2000cws.googlegroups.com...
> .
> .
>
>
>
> > JP, thanks for the update. I installed gmp-4.1.2, changed the
> > LD_LIBRARY_PATH_64 and made sure the libgmp files were in /usr/local/
> > lib/sparcv9, but same problem.....
>
> Try hacking at the XS file. Where it says:
>
> #include "gmp.h"
>
> Change that to:
>
> #include "/usr/local/include/sparcv9/gmp.h" // if that's where gmp.h is
> located
>
> That should at least allow gmp.h to get found. Then it's just a matter of
> making libgmp.a (or the gmp .so) findable.
>
> Probably the simplest way to build it is to do it manually. Download the
> M:::BI::GMP-1.19 source from CPAN, extract to some location, cd to that
> location and run:
>
> perl Makefile.PL INC="-I/usr/local/include/sparcv9"
> LIBS="-L/usr/local/lib/sparcv9 -lgmp"
> make test
> make install
>
> If you don't have a 'libgmp.a' then you should be able to link directly to
> the libgmp-3.so (or whatever it's called) but you would need to change the
> above command to properly reflect the name of the gmp .so file. Something
> like:
>
> perl Makefile.PL INC="-I/usr/local/include/sparcv9"
> LIBS="-L/usr/local/lib/sparcv9 -lgmp-3"
>
> All of this is, of course, untested.
>
> Is there something there that works for you ? (You should at least be able
> to eradicate the error about gmp.h being not found - assuming it really is
> in /usr/local/include/sparcv9.)
>
> Cheers,
> Rob
Rob, thanks. I'll try it out on Monday and let you know.
Cheers,
Sumit
------------------------------
Date: Mon, 26 Feb 2007 19:29:32 GMT
From: QoS@domain.invalid.com
Subject: Unexpected RegEx results
Message-Id: <wyGEh.14260$sv6.3728@trndny08>
Hello, having some trouble solving this regular expression puzzle.
It is possible to solve the issue using some if statements, but im
curious why this is occurring.
The data involved looks similar to the following:
ALWAYSPRESENT:0008:0:OPTIONAL
OPTIONAL
OPTIONAL
Where the data will always start with a name.
This is followed by a colon some numbers a colon some numbers and a colon,
which will all be discarded.
Then there may or may not be some additional data after that.
Next there might be a newline followed by some optional data.
Finally there might be a newline followed by some optional data.
Ok here is my issue, the RegEx im using to do this will place data found
in the 3rd memory variable in the variable $4 when there is no match
to fill $4. So $4 will contain data but $3 will not, when i expected rather
that $3 would contain data and $4 would not.
Example troublesome data:
ALWAYSPRESENT:0008:0:PRESENT
PRESENT
NOTPRESENT
This is the offending RegEx.
$msg =~ /(.*?):.*:(.*)\n*(^.*)\n*(^.*)/m;
Thanks for any assistance.
------------------------------
Date: Mon, 26 Feb 2007 12:49:04 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Unexpected RegEx results
Message-Id: <260220071249048703%jgibson@mail.arc.nasa.gov>
In article <wyGEh.14260$sv6.3728@trndny08>, <QoS@domain.invalid.com>
wrote:
> Hello, having some trouble solving this regular expression puzzle.
> It is possible to solve the issue using some if statements, but im
> curious why this is occurring.
>
> The data involved looks similar to the following:
>
> ALWAYSPRESENT:0008:0:OPTIONAL
> OPTIONAL
> OPTIONAL
>
> Where the data will always start with a name.
> This is followed by a colon some numbers a colon some numbers and a colon,
> which will all be discarded.
> Then there may or may not be some additional data after that.
>
> Next there might be a newline followed by some optional data.
> Finally there might be a newline followed by some optional data.
>
> Ok here is my issue, the RegEx im using to do this will place data found
> in the 3rd memory variable in the variable $4 when there is no match
> to fill $4. So $4 will contain data but $3 will not, when i expected rather
> that $3 would contain data and $4 would not.
>
> Example troublesome data:
>
> ALWAYSPRESENT:0008:0:PRESENT
> PRESENT
> NOTPRESENT
>
> This is the offending RegEx.
>
> $msg =~ /(.*?):.*:(.*)\n*(^.*)\n*(^.*)/m;
I can't follow your logic entirely, but I suspect that you simply have
too many unqualified '*' characters in your regex (I count 6) and it is
causing confusion. For example, '\n*' need not match any characters at
all. Perhaps you want '\n?' or '\n+' there instead.
In any case, please post a complete, runnable program and somebody,
perhaps even me, will be able to help you.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Mon, 26 Feb 2007 21:05:55 GMT
From: QoS@domain.invalid.com
Subject: Re: Unexpected RegEx results
Message-Id: <TYHEh.14267$sv6.12405@trndny08>
Jim Gibson <jgibson@mail.arc.nasa.gov> wrote in message-id:
<260220071249048703%jgibson@mail.arc.nasa.gov>
>
>In article <wyGEh.14260$sv6.3728@trndny08>, <QoS@domain.invalid.com>
>wrote:
>
>> Hello, having some trouble solving this regular expression puzzle.
>> It is possible to solve the issue using some if statements, but im
>> curious why this is occurring.
>>
>> The data involved looks similar to the following:
>>
>> ALWAYSPRESENT:0008:0:OPTIONAL
>> OPTIONAL
>> OPTIONAL
>>
>> Where the data will always start with a name.
>> This is followed by a colon some numbers a colon some numbers and a colon,
>> which will all be discarded.
>> Then there may or may not be some additional data after that.
>>
>> Next there might be a newline followed by some optional data.
>> Finally there might be a newline followed by some optional data.
>>
>> Ok here is my issue, the RegEx im using to do this will place data found
>> in the 3rd memory variable in the variable $4 when there is no match
>> to fill $4. So $4 will contain data but $3 will not, when i expected rather
>> that $3 would contain data and $4 would not.
>>
>> Example troublesome data:
>>
>> ALWAYSPRESENT:0008:0:PRESENT
>> PRESENT
>> NOTPRESENT
>>
>> This is the offending RegEx.
>>
>> $msg =~ /(.*?):.*:(.*)\n*(^.*)\n*(^.*)/m;
>
>I can't follow your logic entirely, but I suspect that you simply have
>too many unqualified '*' characters in your regex (I count 6) and it is
>causing confusion. For example, '\n*' need not match any characters at
>all. Perhaps you want '\n?' or '\n+' there instead.
>
>In any case, please post a complete, runnable program and somebody,
>perhaps even me, will be able to help you.
>
>--
>Jim Gibson
>
> Posted Via Usenet.com Premium Usenet Newsgroup Services
>----------------------------------------------------------
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
>----------------------------------------------------------
> http://www.usenet.com
Ok, here is an example that demonstrates the quirks.
Notice in the second printout that what was in $3 in the first
printout is now in $4 and $3 contains ''.
And thanks very much for giving this a go!
#!usr/bin/Perl
use strict;
use warnings;
my $data;
$data = 'Some Text:0000:0:More Text'."\n".
'Text text'."\n".
'Text text text.'."\n";
&reformat($data);
$data = 'Some Text:0000:0:More Text'."\n".
'Text text'."\n";
&reformat($data);
exit;
sub reformat
{
my $msg = $_[0] || die "Invalid option in reformat\n";
my $out;
$msg =~ /(.*?):.*:(.*)\n*(^.*)\n*(^.*)/m;
$out = "$1,".
"1,".
"00000000000,".
"0000000,".
"000,".
"$2,".
"$3,".
"$4\n";
print $out;
print '=======================================================',"\n";
return(1);
}
------------------------------
Date: Mon, 26 Feb 2007 21:12:36 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Unexpected RegEx results
Message-Id: <83IEh.18$IE4.10@edtnps82>
QoS@domain.invalid.com wrote:
> Hello, having some trouble solving this regular expression puzzle.
> It is possible to solve the issue using some if statements, but im
> curious why this is occurring.
>
> The data involved looks similar to the following:
>
> ALWAYSPRESENT:0008:0:OPTIONAL
> OPTIONAL
> OPTIONAL
>
> Where the data will always start with a name.
> This is followed by a colon some numbers a colon some numbers and a colon,
> which will all be discarded.
> Then there may or may not be some additional data after that.
>
> Next there might be a newline followed by some optional data.
> Finally there might be a newline followed by some optional data.
>
> Ok here is my issue, the RegEx im using to do this will place data found
> in the 3rd memory variable in the variable $4 when there is no match
> to fill $4. So $4 will contain data but $3 will not, when i expected rather
> that $3 would contain data and $4 would not.
>
> Example troublesome data:
>
> ALWAYSPRESENT:0008:0:PRESENT
> PRESENT
> NOTPRESENT
>
> This is the offending RegEx.
>
> $msg =~ /(.*?):.*:(.*)\n*(^.*)\n*(^.*)/m;
$ perl -le'
my @x = ( <<ONE, <<TWO );
ALWAYSPRESENT:0008:0:OPTIONAL
OPTIONAL
OPTIONAL
ONE
ALWAYSPRESENT:0008:0:PRESENT
PRESENT
TWO
for ( @x ) {
print "1=$1 2=$2 3=$3 4=$4" if /(.*?):.*:(.*)\n*(^.*)\n*(^.*)/m;
}
'
1=ALWAYSPRESENT 2=OPTIONAL 3=OPTIONAL 4=OPTIONAL
1=ALWAYSPRESENT 2=PRESENT 3= 4=PRESENT
You are using the /m option and the ^ anchor which tells perl that there
*must* be at least three lines even if there are only two lines.
$ perl -le'
my @x = ( <<ONE, <<TWO );
ALWAYSPRESENT:0008:0:OPTIONAL
OPTIONAL
OPTIONAL
ONE
ALWAYSPRESENT:0008:0:PRESENT
PRESENT
TWO
for ( @x ) {
print "1=$1 2=$2 3=$3 4=$4" if /(.*?):.*:(.*)\n*(.*)\n*(.*)/;
}
'
1=ALWAYSPRESENT 2=OPTIONAL 3=OPTIONAL 4=OPTIONAL
1=ALWAYSPRESENT 2=PRESENT 3=PRESENT 4=
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Mon, 26 Feb 2007 22:16:03 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Unexpected RegEx results
Message-Id: <ervj0o$9tt$1@mlucom4.urz.uni-halle.de>
QoS@domain.invalid.com wrote:
> my $data;
> $data = 'Some Text:0000:0:More Text'."\n".
> 'Text text'."\n".
> 'Text text text.'."\n";
Thats better. Real data ;-)
My first shot:
...
my $data='
Some Text:0000:0:More Text
Text text
Text text text
';
my $rg = qr/
^([^:]+) : \d+ : \d+ : ([^\n]+)?\n
(?: ^([^:\n]+?) \n)?
(?: ^([^:\n]+?) (?:\n|$) )?/mx;
if( $data =~ /$rg/ ) {
print join "\n", map defined $_?$_:'undef', ($1, $2, $3, $4);
}
Regards
M.
------------------------------
Date: Mon, 26 Feb 2007 21:33:50 GMT
From: QoS@domain.invalid.com
Subject: Re: Unexpected RegEx results
Message-Id: <2nIEh.7699$Xe1.5349@trndny01>
QoS@domain.invalid.com wrote in message-id:
<wyGEh.14260$sv6.3728@trndny08>
>
[Snip]
Thank you everybody for helping solve this little mystery.
Your solutions and workarounds are quite clever!
I was unaware of that 'm' option side-effect.
------------------------------
Date: Mon, 26 Feb 2007 23:13:50 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Unexpected RegEx results
Message-Id: <ervvai$e7c$1@mlucom4.urz.uni-halle.de>
QoS@domain.invalid.com wrote:
> QoS@domain.invalid.com wrote in message-id:
> <wyGEh.14260$sv6.3728@trndny08>
> [Snip]
>
> Thank you everybody for helping solve this little mystery.
>
> Your solutions and workarounds are quite clever!
> I was unaware of that 'm' option side-effect.
I was under the impression your data
would not only consist of /one/ record
but rather a good sequence of them, so
the regex would need to climb down
(find) the records and spit out the
correct matches,
# Example: four record thing with "offending" structure ==>
my $morestuff='
ALWAYSPRESENT:0008:0:PRESENT
PRESENT
MAYBEPRESENT
Some Text 1:0000:0:More Text 1
Some Text 2:0000:0:More Text 2
Text22 text22 text22
Some Text 3:0000:0:More Text 3
Text3 text3
Text33 text33 text33
';
# and so on ...
# Now, the regex should identify them
# and step along ==>
my $rg = qr/ \s*
^([^:]+) : \d+ : \d+ : ([^\n]+)?\n
(?: ^([^:\n]+?) \n)?
(?: ^([^:\n]+?) (?:\n|$) )?/mx;
# This was the "shortest" thing I could find so
# far (within your constraints), the record-
# walking would be within a while ==>
while( $morestuff =~ /$rg/g ) {
printf "%s %s\n\t%s\n\t%s\n",
$1||'undef', $2||'undef',
$3||'undef', $4||'undef';
}
# ... which would give the correct matches.
Maybe I misunderstood your problem somehow,
but I found the task quite nice and interesting
(maybe somebody would write down a really simple
regular expression for that - (not me, sleeping
time now in this country ;-).
Regards
Mirco
------------------------------
Date: 26 Feb 2007 14:54:24 -0800
From: "kent.westmoreland@gmail.com" <kent.westmoreland@gmail.com>
Subject: Re: Using Substr and Regular expressions.
Message-Id: <1172530464.479441.183890@v33g2000cwv.googlegroups.com>
On Feb 23, 6:24 pm, "Dan Mercer" <damer...@comcast.net> wrote:
> <kent.westmorel...@gmail.com> wrote in messagenews:1172263881.680949.20480@k78g2000cwa.googlegroups.com...
>
> : On Feb 23, 10:21 am, "Dan Mercer" <damer...@comcast.net> wrote:
> :
> : > My guess is that if you have to ask this question, you're not ready
> : > to program in perl yet. A number of solutions are available:
> : >
> : > use strict;
> : > use warnings;
> : > my $num;
> : > my $name;
> : > ($num,$name) = (split /_/,$ARGV[0])[1,2];
> : >
> : > is just one of many possibilities.
> : >
> : > Dan Mercer
> : >
> :
> : Dan,
> :
> : Your blunt response "My guess is that if you have to ask this
> : question, you're not ready to program in perl yet." is not far from
> : the truth.
> :
> : I only recently started to "learn" perl ( 2 days ago). I am modifying
> : a script that was given to me to preform a specific task. I wanted to
> : make the script easier to use but I was not having much luck with the
> : tutorials I found on the web. I figured posting here was a great
> : place to find information that I required.
> :
> : I have tried both Manish and your suggestions ( both of which work
> : fine) with a few modifications.
> :
> : Some of my main holdbacks on perl where syntactical ( I actually had
> : something similar to your version using the split function but only
> : one variable).
> :
> : Anyway, thanks to everyone for all of your examples and help! Now I
> : have a lot of things to research.
> : Kent
>
> Try SAMS "Teach Yourself Perl in 24 hours" (Clinton Pierce). Worked
> for me.
>
> Dan Mercer
>
> :
> :
> :
> :
Hi Dan,
Thanks for the recommendation! I will check that book out!
Thanks for everyones help!
Kent
------------------------------
Date: Sun, 25 Feb 2007 00:56:53 GMT
From: "kim kubik" <chaotrope@jps.net>
Subject: Re: which is more powerfull ?
Message-Id: <p95Eh.5406$_73.4903@newsread2.news.pas.earthlink.net>
<ehabaziz2001@gmail.com> wrote
> I need to process some files to create new one with OMR marks . which
> is more powerfull in processing files ? awk/sed or perl or others ?
if all you need is a one-to-one remapping don't bother with
learning a scripting language -- just use a text editor like
emacs or vi -- and anyone can tell you which one of those
is the more powerfull (sic) . . .
:-)
------------------------------
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 V11 Issue 176
**************************************