I have the following code where I loop through several files (approx 300) and get the corresponding values from them. this builds a large hash where the first key is the profile name, followed by the info you want. Unfortunately this slows down significantly when I run a large number of files. It runs approx 0.05 seconds per profile if I do < 30 files but if I do a large number (300+) it takes up to 1.0 seconds per profile. Is there a way I can initialize the hash or someway speed this up when it is running a large number? Thanks
foreach my $customProf (@{scalar2array($Settings->{custom_pl
+ots}[$i][$t]{profiles})}){
if(exists $profEvntVar->{$customProf}){next;}
my ($evnt_nums_ref,$var_names_ref,$variables_ref,$last_evn
+t_name) = getvars($customProf);
$profEvntVar->{$customProf}{events} = $evnt_nums_ref; #Li
+nk profiles with their respective events
$profEvntVar->{$customProf}{times} = $evnt_times_ref; #Li
+nk profiles with their respective events
$profEvntVar->{$customProf}{vars} = $var_names_ref; #
+Link profiles with their respective variables
$profEvntVar->{$customProf}{varsref} = $variables_ref;
+ #Link profiles with their respective variables
$profEvntVar->{$customProf}{lastEvent} = $last_evnt_name;
+ #Link profiles with their respective variables
}
sub getvars{
my $profile = shift(@_);
my @ptk_info = `<system_command_here>`;
my $evnt_nums_ref;
my $events_found = 0;
my $vars;
my $prof_var_names;
my $last_evnt_name;
foreach (@ptk_info){
if(/^\s*(\d*\.\d*)0\s-\s(.*?)\s*$/){
$evnt_nums_ref->{$2} = $1;
$last_evnt_name = $2;
}
if($events_found == 1 && /^\b/){
push( @{$vars}, split(" ") );
}
elsif($events_found == 0 && /^Events$/){
$events_found = 1;
}
}
foreach (@{$vars}){
if(/(.{1,8})\S*:\S*/){
$prof_var_names->{$1} = $_;
}
else{
$prof_var_names->{$_} = $_;
}
}
my @sorted_vars = sort { lc($a) cmp lc($b) } @{$vars};
return $evnt_nums_ref,$prof_var_names,\@sorted_vars,$last_evnt_name;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|