RFC: utils.pm

J

Joe Smith

Ben said:
$value =~ s/^\s*(.*?)\s*$/$1/;
or some such.

I've always heard that two anchored single-wildcard searchs are
faster than a single regex with three wildcards.

$value =~ s/^\s+//; $value =~ s/\s+$//;

-Joe
 
T

Tore Aursand

my $now1 = now_day() ;

midnight happens NOW!!!

my $now2 = now_hour() ;

my $timestamp = "$now1:$now2" ;

that is not the value you expect. a bug. not a likely bug but
effectively similar to a race condition.

Yeah, but wouldn't this actually be the same as doing:

my $date1 = strftime( 'whatever', localtime() );
# midnight occurs
my $date2 = strftime( 'whatever', localtime() );

The solution, of course, is to let the 'now()' function do the formatting
for you (ie. you only need to call it once):

my $format = '%DD%:%hh%';
my $timestamp = now( $format );
yes, you did. you didn't understand the possibility of time changing
between now*() calls.

Actually, I did. But as a programmer I'm aware of the possibilities of
race conditions, so I avoid them.
 
G

Gunnar Hjalmarsson

Tore said:
my $date1 = strftime( 'whatever', localtime() );
# midnight occurs
my $date2 = strftime( 'whatever', localtime() );

Better done like:

my $time = time;
my $date1 = strftime( 'whatever', localtime($time) );
# midnight occurs
my $date2 = strftime( 'whatever', localtime($time) );

That takes care of the 'midnight problem' and is also more efficient,
since time() is only called once. Think Uri meant that also your
date/time functions should better take a time string as an argument.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top