[25821] in Perl-Users-Digest
Perl-Users Digest, Issue: 8058 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 7 11:05:40 2005
Date: Sat, 7 May 2005 08:05:08 -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 Sat, 7 May 2005 Volume: 10 Number: 8058
Today's topics:
Extracting strings delimited by other strings <usenet739_yahoo_com_au>
Re: Extracting strings delimited by other strings <1usa@llenroc.ude.invalid>
Re: Extracting strings delimited by other strings <tadmc@augustmail.com>
Re: Filling the Perl Stack <nospam-abuse@ilyaz.org>
Re: Help, a problem with yesterdays date. Thanks for t <jblno@spamhotmail.com>
Help, a problem with yesterdays date. <jblno@spamhotmail.com>
Re: Help, a problem with yesterdays date. <jurgenex@hotmail.com>
Re: Help, a problem with yesterdays date. <1usa@llenroc.ude.invalid>
Re: Help, a problem with yesterdays date. <tadmc@augustmail.com>
Re: Help, a problem with yesterdays date. <pilkowsk@informatik.uni-marburg.de>
Match some lines <newsAT@screenlightDOT.com>
Re: Match some lines <jurgenex@hotmail.com>
Re: Match some lines <newsAT@screenlightDOT.com>
Re: Offline Perl obfusquator ? <tintin@invalid.invalid>
Re: pattern matching dynamic strings w/ regex ending in <ernest@virtualitas.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 7 May 2005 10:54:30 +1000
From: "Scott Bass" <usenet739_yahoo_com_au>
Subject: Extracting strings delimited by other strings
Message-Id: <427c11c6$0$32016$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Hi,
I need to write some code that will allowed embedded, specially formatted
comments to document test cases within a program (SAS code). The code will
process the programs, pulling out the test case information. AFAIK this is
similar to how Javadoc works, embedding documentation alongside code.
The syntax will look like:
/*
<testcase>
TESTID: TEST1
OBJECTIVE: The objective of the test
PROCEDURE: The procedure that the test uses
Continuation line from the above
RESULTS: The expected results of the test
Continuation line
Another "continuation" line
</testcase>
*/
The syntax can also be embedded in titles statements:
/* <testcase> */
title3 "TESTID: TEST1";
title4 "OBJECTIVE: The objective of the test";
title5 "PROCEDURE: The procedure that the test uses";
title6 " Continuation line from the above";
title6 "RESULTS: The expected results of the test";
title7 " Continuation line";
title8 ' Another "continuation" line';
/* </testcase> */
After processing the program, the desired output is a tab-delimited string
containing filename, testid, objective, procedure, and results. For those
lines that were continued, I would like an embedded CR/LF. Leading spaces
should be
removed, as well as any title statements, "outer" quotation marks
(preserving inner quotation marks), and trailing semi-colons.
Are there any modules that I could use as a starting point for this? If you
have any code does something similar, could you either post it or email it
to me? It will be easier to modify an existing example than to start from
scratch.
Kind Regards,
Scott
------------------------------
Date: Sat, 07 May 2005 02:04:23 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Extracting strings delimited by other strings
Message-Id: <Xns964EE06CAEE13asu1cornelledu@127.0.0.1>
"Scott Bass" <usenet739_yahoo_com_au> wrote in
news:427c11c6$0$32016$5a62ac22@per-qv1-newsreader-01.iinet.net.au:
> I need to write some code
...
> After processing the program, the desired output is a tab-delimited
> string containing filename, testid, objective, procedure, and results.
> For those lines that were continued, I would like an embedded CR/LF.
Surely, you do not expect people here to write a program to your specs.
> Are there any modules that I could use as a starting point for this?
Did you find anything on CPAN? Did you try Google?
The surest way to get quality help here is to post what you have
attempted so far, and specific questions regarding specific issues you
are have encountered.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Fri, 6 May 2005 21:26:06 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Extracting strings delimited by other strings
Message-Id: <slrnd7o9pu.i4j.tadmc@magna.augustmail.com>
Scott Bass <> wrote:
> /*
><testcase>
> TESTID: TEST1
> OBJECTIVE: The objective of the test
> PROCEDURE: The procedure that the test uses
> Continuation line from the above
> RESULTS: The expected results of the test
> Continuation line
> Another "continuation" line
></testcase>
> */
>
> The syntax can also be embedded in titles statements:
>
> /* <testcase> */
> title3 "TESTID: TEST1";
> title4 "OBJECTIVE: The objective of the test";
> title5 "PROCEDURE: The procedure that the test uses";
> title6 " Continuation line from the above";
> title6 "RESULTS: The expected results of the test";
> title7 " Continuation line";
> title8 ' Another "continuation" line';
> /* </testcase> */
>
> After processing the program, the desired output is a tab-delimited string
I'm going to use commas because they are easier to see.
> containing filename, testid, objective, procedure, and results. For those
> lines that were continued, I would like an embedded CR/LF. Leading spaces
> should be
> removed, as well as any title statements, "outer" quotation marks
> (preserving inner quotation marks), and trailing semi-colons.
>
> Are there any modules that I could use as a starting point for this?
I dunno.
Hardly seems worth modularization when it only takes about
20 lines of regular ol' Perl.
Assuming the whole file is slurped into $_ :
------------------------------
while ( m#<testcase>(.*?)</testcase>#gs ) {
my $record = normalize($1);
my(undef,@parts) = split /(?:TESTID|OBJECTIVE|PROCEDURE|RESULTS):\s+/,
$record;
chomp @parts;
print join( ',', @parts), "\n";
}
sub normalize {
my($r) = @_;
$r =~ s#^\s*\*/##; # snip bits of comment delimiters
$r =~ s#/\*\s*##;
$r =~ s#^title\d+ ##gm; # remove title statement cruft
$r =~ s#^(['"])(.*?)\1;#$2#gm;
$r =~ s#\n\s\s+#\n#; # join continuation lines
$r =~ s#^\s*##; # trim spaces
$r =~ s#\s*$##;
return $r;
}
------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 6 May 2005 22:08:20 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Filling the Perl Stack
Message-Id: <d5gpsk$1cfp$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Tassilo v. Parseval
<tassilo.von.parseval@rwth-aachen.de>], who wrote in article <slrnd7ju5o.3mg.tassilo.von.parseval@localhost.localdomain>:
> Maybe you can put it into some publicly available spot on the internet
> so that everyone here can see it?
At some moment I wanted to just rewrite perlxs so that it is readable,
and use this opportunity to document all the stuff I needed to do in
my XS code... But it was quite some time ago...
Ilya
------------------------------
Date: Sat, 07 May 2005 14:00:46 GMT
From: jbl <jblno@spamhotmail.com>
Subject: Re: Help, a problem with yesterdays date. Thanks for the suggestions, this is a big help
Message-Id: <pfip719vd546n60f2057d69a52chjmbge6@4ax.com>
On Sat, 07 May 2005 13:49:06 GMT, "A. Sinan Unur"
<1usa@llenroc.ude.invalid> wrote:
>jbl <jblno@spamhotmail.com> wrote in
>news:pefp71t1ds3scvkhikklkvvnnmh97t15pj@4ax.com:
>
>> I am sure that by now I am overlooking something simple, but it has
>> got me.
>
>You do not have warnings enabled. Otherwise, you would have seen:
>
>Scalar value @timestruct[5] better written as $timestruct[5] etc.
>
>This probably does not have anything to do with your problem however.
>
>> All I really want is yesterdays day of month (01-31) and it's month
>> (01-12) in two digit format. I don't care about the year.
>
>...
>
>> The printf statement prints yesterdays date. This is OK
>> The print $current_day and $current_month are printing todays date.
>> Not OK.
>>
>>
>> @timestruct = localtime(time-86400);
>>
>> printf('%02d%02d%02d',@timestruct[5]+1900,@timestruct[4]+1,
>> @timestruct[3]);
>
>@timestruct[3] is an array-slice. You just want the fourth element of
>the list.
>
>> $current_day = formatDayofMonth(@timestruct[3]);
>
>Ditto.
>
>I can't figure out why you want to use this sub when you can just use
>
>my $current_day = sprintf '%2.2d', $t[3];
>
>Also, if $current_day is supposed to be yesterdays day-of-month, then
>don't you think the variable could have been named better?
>
>> ########## Subs ##########
>> sub formatMonth {
>> my $val = $_[0];
>> if( $val > 11 ) {
>> return 0;
>> }
>> return (qw(01 02 03 04 05 06 07 08 09 10 11 12))[$val];
>> }
>
>Months are returned zero-indexed this "works". But again, why not
>sprintf?
>
>
>> sub formatDayofMonth {
>> my $val = $_[0];
>> if( $val > 31 ) {
>> return 0;
>> }
>
>Now, doesn't localtime have some guarantees over the range of values it
>will return? If you are going to check for an upper bound violation, why
>not also check if $val is less than zero?
>
>> return (qw(01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
>> 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31))[$val];
>> }
>
>Day-of-month is indexed from 1, so this returns '02' for 1, '03' for 2
>etc.
>
> return (qw(01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
> 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31))[$val-1];
>
>Again,
>
>sprintf '%2.2d', $val;
>
>Sinan
------------------------------
Date: Sat, 07 May 2005 13:21:08 GMT
From: jbl <jblno@spamhotmail.com>
Subject: Help, a problem with yesterdays date.
Message-Id: <pefp71t1ds3scvkhikklkvvnnmh97t15pj@4ax.com>
I am sure that by now I am overlooking something simple, but it has
got me.
All I really want is yesterdays day of month (01-31) and it's month
(01-12) in two digit format. I don't care about the year.
As far as the subs, I thought about looking for the length of the
above and padding with a zero to the left if a single digit, but this
works OK.
The printf statement prints yesterdays date. This is OK
The print $current_day and $current_month are printing todays date.
Not OK.
@timestruct = localtime(time-86400);
printf('%02d%02d%02d',@timestruct[5]+1900,@timestruct[4]+1,@timestruct[3]);
$current_day = formatDayofMonth(@timestruct[3]);
print "\n\ncurrent day = $current_day\n";
$current_month = formatMonth(@timestruct[4]);
print "current month = $current_month\n";
########## Subs ##########
sub formatMonth {
my $val = $_[0];
if( $val > 11 ) {
return 0;
}
return (qw(01 02 03 04 05 06 07 08 09 10 11 12))[$val];
}
sub formatDayofMonth {
my $val = $_[0];
if( $val > 31 ) {
return 0;
}
return (qw(01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31))[$val];
}
Output:
20050506 what I want, yesterday
current day = 07 not what I want, this is Today
current month = 05
Thanks
jbl
------------------------------
Date: Sat, 07 May 2005 13:32:03 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Help, a problem with yesterdays date.
Message-Id: <nr3fe.10538$dw1.757@trnddc02>
jbl wrote:
> All I really want is yesterdays day of month (01-31) and it's month
> (01-12) in two digit format. I don't care about the year.
>
> As far as the subs,
[home-cooked solution snipped]
I am fairly certain that with Date::Calc this whole problem will collapse
into a two-line triviality.
jue
------------------------------
Date: Sat, 07 May 2005 13:49:06 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Help, a problem with yesterdays date.
Message-Id: <Xns964F63C2E5AA1asu1cornelledu@127.0.0.1>
jbl <jblno@spamhotmail.com> wrote in
news:pefp71t1ds3scvkhikklkvvnnmh97t15pj@4ax.com:
> I am sure that by now I am overlooking something simple, but it has
> got me.
You do not have warnings enabled. Otherwise, you would have seen:
Scalar value @timestruct[5] better written as $timestruct[5] etc.
This probably does not have anything to do with your problem however.
> All I really want is yesterdays day of month (01-31) and it's month
> (01-12) in two digit format. I don't care about the year.
...
> The printf statement prints yesterdays date. This is OK
> The print $current_day and $current_month are printing todays date.
> Not OK.
>
>
> @timestruct = localtime(time-86400);
>
> printf('%02d%02d%02d',@timestruct[5]+1900,@timestruct[4]+1,
> @timestruct[3]);
@timestruct[3] is an array-slice. You just want the fourth element of
the list.
> $current_day = formatDayofMonth(@timestruct[3]);
Ditto.
I can't figure out why you want to use this sub when you can just use
my $current_day = sprintf '%2.2d', $t[3];
Also, if $current_day is supposed to be yesterdays day-of-month, then
don't you think the variable could have been named better?
> ########## Subs ##########
> sub formatMonth {
> my $val = $_[0];
> if( $val > 11 ) {
> return 0;
> }
> return (qw(01 02 03 04 05 06 07 08 09 10 11 12))[$val];
> }
Months are returned zero-indexed this "works". But again, why not
sprintf?
> sub formatDayofMonth {
> my $val = $_[0];
> if( $val > 31 ) {
> return 0;
> }
Now, doesn't localtime have some guarantees over the range of values it
will return? If you are going to check for an upper bound violation, why
not also check if $val is less than zero?
> return (qw(01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
> 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31))[$val];
> }
Day-of-month is indexed from 1, so this returns '02' for 1, '03' for 2
etc.
return (qw(01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31))[$val-1];
Again,
sprintf '%2.2d', $val;
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sat, 7 May 2005 09:00:50 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help, a problem with yesterdays date.
Message-Id: <slrnd7pigi.jmb.tadmc@magna.augustmail.com>
jbl <jblno@spamhotmail.com> wrote:
> All I really want is yesterdays day of month (01-31) and it's month
> (01-12) in two digit format.
my($day, $month) = (localtime time - 86400)[3,4];
$day = sprintf '%02d', $day;
$month = sprintf '%02d', $month+1;
> $current_day = formatDayofMonth(@timestruct[3]);
You should always enable warnings when developing Perl code!
(most especially if you are going to ask hundreds of volunteers
to help with it.
)
> sub formatMonth {
> return (qw(01 02 03 04 05 06 07 08 09 10 11 12))[$val];
> sub formatDayofMonth {
> return (qw(01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
> 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31))[$val];
One of those is zero-based and one of them is one-based, yet
you are indexing them identically...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 7 May 2005 16:53:57 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Help, a problem with yesterdays date.
Message-Id: <3e431qF13nq6U1@individual.net>
* jbl schrieb:
>
> All I really want is yesterdays day of month (01-31) and it's month
> (01-12) in two digit format. I don't care about the year.
>
> @timestruct = localtime(time-86400);
Be aware, this doesn't work always. You've heard about daylight saving
time (DST)? Just for playing around:
use Time::Local;
my $t = timelocal( 0, 30, 0, 29, 2, 2005 );
print scalar localtime( $t ), "\n";
print scalar localtime( $t -= 86400 ), "\n";
print scalar localtime( $t -= 86400 ), "\n";
print scalar localtime( $t -= 86400 ), "\n";
__END__
Tue Mar 29 00:30:00 2005
Mon Mar 28 00:30:00 2005
Sat Mar 26 23:30:00 2005
Fri Mar 25 23:30:00 2005
Everyone would miss Sunday, the 27th ... ;-(
>
> printf('%02d%02d%02d',@timestruct[5]+1900,@timestruct[4]+1,@timestruct[3]);
>
> $current_day = formatDayofMonth(@timestruct[3]);
> print "\n\ncurrent day = $current_day\n";
>
> $current_month = formatMonth(@timestruct[4]);
> print "current month = $current_month\n";
Well, you're familiar with Perl's builtin function printf() -- but not
with sprintf(). Have a look at it -- it's suitable to replace your own
subs formatMonth() and formatDayofMonth(). I suggest something like:
my( $day, $month, $year ) = ( localtime )[3..5];
my $today = sprintf '%04d%02d%02d', $year+1900, $month+1, $day;
my $yesterday = sprintf '%04d%02d%02d', $year+1900, $month+1, $day-1;
print "$today\n$yesterday";
__END__
20050507
20050506
If you really want to do more computations with dates, I recommend to
use Date::Calc from CPAN. It pays attention of all these stumbling
blocks for you.
regards,
fabian
------------------------------
Date: Sat, 07 May 2005 07:04:07 GMT
From: one man army <newsAT@screenlightDOT.com>
Subject: Match some lines
Message-Id: <newsAT-6A862D.00101807052005@newssvr14-ext.news.prodigy.com>
Hi All You Perl Folk-
I am new to regular expressions. I am reading a manual. I have a
problem I am not figuring out. Perhaps you have some insights.
Since regular expressions are 'greedy', I am having a problem removing
data blocks out of a long, machine generated text file.
I got as far as making the file look like:
XXXXXX
(about 70 lines of text, not always exactly 70)
</FORM>
(about 411 lines of text, not always exactly 411)
XXXXXX
that continues about 230 times.
SO I want to write something that saves the 70 lines, and gets rid of
the 411. But since RegExp are greedy, my simple attempt matches
basically the whole file.
What do you do with that?
email as well as post, if you please
(news AT s c r e e n l i g h t DOT c o m)
thanks in advance!
-Brian
------------------------------
Date: Sat, 07 May 2005 07:24:41 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Match some lines
Message-Id: <Z2_ee.1091$nX1.937@trnddc09>
one man army wrote:
> Since regular expressions are 'greedy', I am having a problem
Then just make the match non-greedy.
From "perldoc perlre":
By default, a quantified subpattern is "greedy", that is, it will match
as many times as possible (given a particular starting location) while
still allowing the rest of the pattern to match. If you want it to match
the minimum number of times possible, follow the quantifier with a "?".
Note that the meanings don't change, just the "greediness".
jue
------------------------------
Date: Sat, 07 May 2005 07:59:47 GMT
From: one man army <newsAT@screenlightDOT.com>
Subject: Re: Match some lines
Message-Id: <newsAT-8EBB43.01055907052005@newssvr14-ext.news.prodigy.com>
In article <Z2_ee.1091$nX1.937@trnddc09>,
"Jürgen Exner" <jurgenex@hotmail.com> wrote:
...
Hey, Thanks! that works....
------------------------------
Date: Sat, 7 May 2005 11:58:44 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Offline Perl obfusquator ?
Message-Id: <RwTee.4400$Od6.614487@news.xtra.co.nz>
"David K. Wall" <darkon.tdo@gmail.com> wrote in message
news:Xns964E76C163E2Edkwwashere@216.168.3.30...
>>
>> http://search.cpan.org/~dconway/Acme-Bleach-1.12/
>
> If I recall correctly, Acme::Morse does about the same thing, except
> that instead of converting the code to spaces it converts it to Morse
> code. I'm not sure which is more evil.
Well there's always Acme::Morse::Audible and my favourite would be
Acme::EyeDrops
------------------------------
Date: Sat, 07 May 2005 14:24:21 +0200
From: Ernest Lergon <ernest@virtualitas.net>
Subject: Re: pattern matching dynamic strings w/ regex ending in $ problem
Message-Id: <d5ic2m$bib$00$1@news.t-online.com>
Perl 5.8.0 had some problems with regex. You should upgrade your Perl.
See: http://guest:guest@rt.perl.org/rt3/index.html?q=19767
Ernest
------------------------------
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 8058
***************************************