Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Perl Script performance issue

by Cristoforo (Curate)
on Dec 15, 2015 at 15:12 UTC ( [id://1150386]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1150386]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-20 05:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found