in reply to Using split, splice, and join to remove time from scalar context return of localtime()

my $now = localtime; my @t = split /\s/, $now; splice @t, 3, 1; $now = join ' ', @t;

That won't work very well during the first nine days of the month:

$ perl -le' my $now = localtime 1260043200; print $now; my @t = split /\s/, $now; splice @t, 3, 1; $now = join " ", @t; print $now; ' Sat Dec 5 12:00:00 2009 Sat Dec 12:00:00 2009
  • Comment on Re: Using split, splice, and join to remove time from scalar context return of localtime()
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Using split, splice, and join to remove time from scalar context return of localtime()
by jffry (Hermit) on Dec 17, 2009 at 23:49 UTC

    Nice one! I forgot the "+" in my @t = split /\s+/, $now; That would have been an ugly bug.

      That's why I used split " " in my benchmark. I didn't stop to think if such a situation existed, but I figured it would be safer.