in reply to Re^2: Reading (the same) data in different ways & memory usage
in thread Reading (the same) data in different ways & memory usage
How does one substitution with capture compare to doing 2 substitutions without capture?
In your example:
$hr_returnvalue->{$CurrentColumnName} =~ s/^\s*(.*?)\s*$/$1/; + # Trim whitespace
The regular expression /^\s*(.*?)\s*$/ will always match, regardless if there is or is not whitespace present, so the substitution will always be done.
In my example:
s/^\s+//, s/\s+$// for $hr_returnvalue->{$CurrentColumnName}; + # Trim whitespace
The regular expressions /^\s+/ and /\s+$/ will only match if there is whitespace present and so the substitution will only be done on the occurrence of whitespace.
Running a benchmark would be good start, and you should try to use data similar to, or the actual data that your program uses.
|
|---|