How to speed up subroutine?

Discussion in 'Perl' started by nospam, Aug 26, 2004.

  1. nospam

    nospam Guest

    The sub below uses the Tie::File module to perform a string
    substitution using strings in the hash %strings. The hash
    would contain IP addresses, an old and new address,
    corresponding to the key/value pairs. The idea is
    to replace IP addresses. Anyway, it worked well when
    there were about 10 elements in the array, but when
    there are ~ 100, the code runs unacceptably slow.
    I've tried deferring writing, but that didn't help much.
    Anything else I can do to speed up this code, and still
    continue using Tie::File?

    -Thanks



    sub DoReplace {

    $matchflag = 0;

    #Skip things that we don't want to process, namely binaries and dirs.
    #Do a "perldoc -f -f" to view test switches.
    return unless -T;

    my $obj = tie(@array, 'Tie::File', $_) || die "$!\n";

    (tied @array)->defer;

    for (@array) {

    while ((my $key, my $value) = each %strings) {

    if (s/$key/$value/){
    print "Processing==> $File::Find::name\n" unless $matchflag == 1;
    $matchflag = 1;
    }

    (tied @array)->flush;

    }

    }

    untie @array;

    }
     
    nospam, Aug 26, 2004
    #1
    1. Advertising

  2. nospam

    Guest

    Someone claiming to be nospam <> wrote in message news:<>...

    [snip]

    Do you actually work for Hormel or are you participating in a DDoS
    attack on them. If the latter, why, what have they done to you?

    This newsgroup does not exist (see FAQ). Please do not start threads
    here.
     
    , Aug 27, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ham

    I need speed Mr .Net....speed

    Ham, Oct 28, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    2,343
    Antony Baula
    Oct 29, 2004
  2. efiedler
    Replies:
    1
    Views:
    2,053
    Tim Ward
    Oct 9, 2003
  3. king
    Replies:
    5
    Views:
    188
  4. Rainer Weikusat

    speed of subroutine calls in perl

    Rainer Weikusat, Jul 5, 2013, in forum: Perl Misc
    Replies:
    0
    Views:
    151
    Rainer Weikusat
    Jul 5, 2013
  5. Rainer Weikusat

    speed of subroutine calls in perl

    Rainer Weikusat, Jul 5, 2013, in forum: Perl Misc
    Replies:
    1
    Views:
    173
    Charlton Wilbur
    Jul 6, 2013
Loading...

Share This Page