Steve Grazzini wrote:
> rmck wrote:
>> But I run this system call and it took allnight to run :(
> 
> You were asking perl to rewrite the whole file for every line
> you wanted to change.
> 
>      #!/usr/bin/perl
>      use strict;
>      use warnings;        # or just use Foo::Monkey :-)
> 
>      use POSIX qw(strftime);
>      die "Usage: $0 FILES\n" unless @ARGV;
> 
>      $^I = '.bak';        # turn on in-place editing with backups
>      while (<>) {         # process one line at a time
>          s{ ^(\d+) }
>           { strftime("%Y-%m-%d %T", localtime($1)) }exg;
> 
>          print;
>      }

In addition to Steve's method here, you might consider memoizing the
conversion function if there are numerous duplicated times.

   use Memoize;
   memoize('convert');
   sub convert { strftime('%Y-%m-%d %T', localtime(shift)) }

   ...

         s{ ^(\d+) }{ convert($1) }ex;

If you have mostly different times, this won't help, but if many of the
times are duplicated it probably will speed things up.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to