Hello kris004,

Performance varies between Perl releases. It appears from testing regular expression may run slower in Perl v5.20 and higher. Therefore, provided a subsequent demonstration to factor out the regular expression engine.

Update 1: Runs fast using any Perl release by merging the two regular expressions into one. Suggestion by LanX. Of course ;-), minimize the use of multiple regular expression statements when possible.

Update 2: Added -w switch to Perl.

#!/bin/sh curl https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts +|\ perl -wnl -e ' if ( /^0\.0\.0\.0 (.*)$/ ) { print "local-zone: \"" . $1 . "\" redirect\nlocal-data: \"" . $1 . + " A 0.0.0.0\""; } ' > ads.conf

Perl up to 5.18.x

#!/bin/sh curl https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts +|\ perl -wnl -e ' if ( /^0\.0\.0\.0/ ) { chomp; s/^0\.0\.0\.0 //; print "local-zone: \"" . $_ . "\" redirect\nlocal-data: \"" . $_ . + " A 0.0.0.0\""; } ' > ads.conf

Perl 5.20.x and higher

#!/bin/sh curl https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts +|\ perl -wnal -e ' if ( $F[0] eq "0.0.0.0" ) { print "local-zone: \"" . $F[1] . "\" redirect\nlocal-data: \"" . $ +F[1] . " A 0.0.0.0\""; } ' > ads.conf

Perl switches

$ perl --help Usage: perl [switches] [--] [programfile] [arguments] ... -a autosplit mode with -n or -p (splits $_ into @F) -e program one line of program (several -e's allowed, omit pr +ogramfile) -l[octal] enable line ending processing, specifies line term +inator -n assume "while (<>) { ... }" loop around program -w enable many useful warnings ...

Regards, Mario


In reply to Re: Making this script process 56,000 lines 5 times faster by marioroy
in thread Making this script process 56,000 lines 5 times faster by kris004

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.