in reply to Performance issue

Performance issue? .0002 seconds per sub call? is your input file multi-GB? (assumes $str is coming from a file or DB, which might suggest "performance issue" lies elsewhere).

After adding strict and warnings and dealing with missing variable declarations, on a not-particularly-speedy w32 machine (results similar on Ubuntu):

Extract begins with the input line mycompany----engineer=====itdept--- +--33 1234965298.64138 1234965298.64149 1234965298.64153 1234965298.64158

Update Further thoughts:

#!/usr/bin/perl use strict; use warnings; # use Data::Dumper; use Time::HiRes qw(time); my $Name = "MyName"; my ($Age, %Details); my @source = ('acompany----engineer=====itdept-----33', 'bcompany----butcher=====killingfloor-----34', 'acompany----baker=====oven-----35', 'acompany----candlestickmaker=====tallow-----36', 'acompany----monk=====monastery-----37', ); my $Pattern = "([a-z]+)\-+([a-z]+)\=+([a-z]+)\-+([0-9]+)"; my $start_time = time; for my $str(@source) { Extract($str, $Name, $Pattern); } my $end_time = time; print "back in main elapsed time for a 5-element \@source was: ", $end +_time - $start_time, "\n"; sub Extract { my @subarr = @_; my ($Line,$Name,$Pattern) = @subarr; my (@Arr,$CallId); # print "Extract begins with the input line $Line\n"; # print time,"\n"; @Arr = ($Line =~ m/$Pattern/g); # print time,"\n"; $Age = $Arr[$#Arr]; # print time,"\n"; $Details{$Age}{$Name} = \@Arr if defined($Age); #print time,"\n"; }

Timings: first, with print at line 38 enabled:

C:\ww>perl 744750.pl Extract begins with the input line acompany----engineer=====itdept---- +-33 Extract begins with the input line bcompany----butcher=====killingfloo +r-----34 Extract begins with the input line acompany----baker=====oven-----35 Extract begins with the input line acompany----candlestickmaker=====ta +llow-----36 Extract begins with the input line acompany----monk=====monastery----- +37 back in main elapsed time for a 5-element @source was: 0.0008189678192 +13867

whereas, with line 38 commented out (ie, as shown):

C:\ww>perl 744750.pl back in main elapsed time for a 5-element @source was: 0.0001859664916 +99219

The difference, 0.000633001327514648 (roughly 3x the total elapsed time_when_omitting_the_prints in sub Extract) is attributable to the mis-use of print for profiling. See moritz's above & ELISHEVA's below.