[27283] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9036 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 9 11:05:48 2006

Date: Thu, 9 Mar 2006 08:05:06 -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           Thu, 9 Mar 2006     Volume: 10 Number: 9036

Today's topics:
    Re: Regex: Backreferences do not work inside quantifier <ced@blv-sam-01.ca.boeing.com>
    Re: regexp: segmentation fault <jurgenex@hotmail.com>
    Re: Year of day in localtime and timelocal don't match? (J Moreno)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 9 Mar 2006 15:43:37 GMT
From: Charles DeRykus <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Regex: Backreferences do not work inside quantifiers?
Message-Id: <IvvACo.51t@news.boeing.com>

Wolfgang Thomas wrote:
> I have a line of the following format:
> string length followed by colon followed by the actual
> string.
> To extract the string with the correct length I use the
> following regular expression:
> 
> my $s = "3:abcd";
> $s =~ /([\d]+):(.{\1})/;
> print "$1\n";
> print "$2\n";
> 
> 
> However this does not match. Neither $1 nor $2 become
> defined. If I replace \1 with 3 it works as expected,
> I get 3 in $1 and "abc" in $2.
> 
> I have studied the "Perl Programming" book and
> the active perl regex documentation, but could not
> find a restriction that backreferences must not be
> used inside quantifiers.
> 
> What am I doing wrong?

An extended regex possibility:

my $pos;
if ( $s =~ /(\d+):(?{ $pos=pos })/ ) {
   print "count=$1 substring=",substr($s, $pos, $1);
}

-- 
Charles DeRykus


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

Date: Thu, 09 Mar 2006 15:11:07 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: regexp: segmentation fault
Message-Id: <fAXPf.15821$Cc3.4150@trnddc08>

S.Marion wrote:
> Any thoughts??

About what?

jue 




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

Date: Thu, 9 Mar 2006 09:36:56 -0500
From: planB@newsreaders.com (J Moreno)
Subject: Re: Year of day in localtime and timelocal don't match?
Message-Id: <1hbxd0f.1dcob1bvtxblqN%planB@newsreaders.com>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:

> Read Gunnar's reply again.  The day_of_year count starts at 0, the
> day_of_month count starts at 1.  That goes for the return values of
> localtime() as well as for the input parameters of timelocal() and
> timelocal_nocheck().  You are using a day_of_year type count as
> a day_of_month type argument.  Of course the result is off by one.

No, I don't think so.

###
use warnings;
use strict;

use Time::Local 'timelocal_nocheck';

$\ = "\n";

my $day_of_year;
my $l_year;

$l_year = (localtime)[5];
$day_of_year = (localtime)[7];

print "Day of year fom localtime is: $day_of_year";
print scalar localtime;
print scalar localtime timelocal_nocheck  0,0,0,$day_of_year, 0, $l_year;
print '';
 
print scalar localtime timelocal_nocheck  0,0,0,0, 0, 2006;
print scalar localtime timelocal_nocheck  0,0,0,15, 0, 2006;
print scalar localtime timelocal_nocheck  0,0,0,45, 0, 2006;
print scalar localtime timelocal_nocheck  0,0,0,90, 0, 2006;
print scalar localtime timelocal_nocheck  0,0,0,180, 0, 2006;
print scalar localtime timelocal_nocheck  0,0,0,360, 0, 2006;
###

Outputs...

Day of year fom localtime is: 67
Thu Mar  9 09:14:13 2006
Wed Mar  8 00:00:00 2006

Sat Dec 31 00:00:00 2005
Sun Jan 15 00:00:00 2006
Tue Feb 14 00:00:00 2006
Fri Mar 31 00:00:00 2006
Thu Jun 29 00:00:00 2006
Tue Dec 26 00:00:00 2006

So, timelocal_nocheck is clearly treating it as a day of year value,
not a day of the month value which is being liberally interpreted, and
(localtime)[7] is just as clearly (and clearly documented as) returning
the day of the year.

It's just that the two days of the year don't match up.

And as I said in the previous post, the example in Time::Local shows
that the day of the year value is 1 based (for 365 in 99 it outputs
Dec 31) for timelocal_nocheck.

Also note that it handles negative values and that the zeroth day of
the year 2006 is Dec 31, 2005.

So, to sum it up...localtime returns a zero based day of year count,
timelocal_nocheck uses a 1 based day of year count, and all of this is
there in the docs, but IMO for timelocal_nocheck it's not as clearly
stated as it could be.

-- 
JM
"Everything is futile." -- Marvin of Borg


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

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


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