Please tell me how can i optimize this code. The file is very large and has around 11989364 lines. So the processing is very slow.#!/usr/bin/perl use Date::Manip; $date_2_days_ago = ParseDate("3 days ago");; $date_converted = UnixDate($date_2_days_ago,"%e/%h/%Y"); open DATA,">$ARGV[1]"; open FH,"$ARGV[0]"; while(<FH>){ @tab_delimited_array = split(/\t/,$_); $tab_delimited_array[3] =~ s/^\[//; $tab_delimited_array[3] =~ s/^\-//; chomp($tab_delimited_array[3]); if(length($tab_delimited_array[3]) > 1) { $date_format= UnixDate($tab_delimited_array[3],"%Y%m%d%H:%M:%S"); $converted_date = Date_ConvTZ("$date_format",'GMT','PST'); $pst_converted_date = UnixDate($converted_date,"%e/%h/%Y:%H:%M:%S +"); $pst_converted_date =~ s/^\s//g; $extracted_YMD=UnixDate($converted_date,"%e/%h/%Y"); $_ =~ s/$arr[3]/$pst_converted_date/g; if($extracted_YMD =~ m/$date_converted/){ print DATA $_; } } } close DATA; close FH;
In reply to optimize the code by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |