in reply to Perl Script performance issue

A comment on your lines that use split, split(/$hash_ref->{DELIMITER}/. If the delimiter is pipe, |, then your split is split /|/, .... That will not work as you want because the split pattern, '|', in this case says to split on 'nothing OR nothing'. (Equivalent to split //, ...

To correct this, you should use the \Q escape sequence. That tells perl to treat the pipe as a regular character and not mean OR in the regular expression.

I saved a file of what are called the 'dirty dozen' of metacharacters. The pipe is one of the dirty dozen. They are:

\ | ( ) [ { ^ $ * + ? .

They all need escaping if they are to be treated as a 'regular' character in a regular expression (not as a metacharacter). So, your split should look like
split(/\Q$hash_ref->{DELIMITER}\E/

(There also is the quotemeta built in function).

Replies are listed 'Best First'.
Re^2: Perl Script performance issue
by AnomalousMonk (Archbishop) on Dec 15, 2015 at 15:30 UTC

    See also Quote and Quote-like Operators (about two-thirds of the way through the section) for more info on  \Q and friends. (Update: There are also a few examples of use in perlretut Part 2, in the section "More on characters, strings, and character classes".)


    Give a man a fish:  <%-{-{-{-<

      Thanks for pointing that out. Since we are passing delimiter from config file, we are passing it as \|. That takes care of suppression automatically.