Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: optimize the code
by BrowserUk (Patriarch) on Jun 24, 2010 at 12:24 UTC | |
by Anonymous Monk on Jun 25, 2010 at 05:18 UTC | |
by Anonymous Monk on Jun 29, 2010 at 07:28 UTC | |
by marto (Cardinal) on Jun 29, 2010 at 08:22 UTC | |
|
Re: optimize the code
by almut (Canon) on Jun 24, 2010 at 11:41 UTC | |
|
Re: optimize the code
by BrowserUk (Patriarch) on Jun 24, 2010 at 10:58 UTC | |
by Anonymous Monk on Jun 24, 2010 at 11:13 UTC | |
|
Re: optimize the code
by Khen1950fx (Canon) on Jun 24, 2010 at 11:41 UTC | |
|
Re: optimize the code
by BioLion (Curate) on Jun 24, 2010 at 12:02 UTC | |
|
Re: optimize the code
by wfsp (Abbot) on Jun 24, 2010 at 12:22 UTC |