in reply to Re: script optmization
in thread script optmization
A couple of very,very minor nits which I show in code below:
Another Monk queried about the OP's purpose? Sometimes a post is just an academic question. Sounds like there is some real application here that we don't understand. The only reason to put these "markers" into the text is for later processing. Maybe that processing, whatever it is, can be combined into a single step? That could lead to a big speed increase. I mean that second step of processing will have to search the entire text to find the bbb markers yet again.
#!/usr/bin/env perl use strict; use warnings; use Inline::Files; my %seq; # example: 'scooped up again' => 'scoopedbbbupbbbagain', while (my $line = <SEQ>) { $line =~ s/^\s+//; $line =~ s/\s+$//; ($seq{$line} = $line) =~ s/\h+/bbb/g; } my $search_phrases = join '|', keys %seq; my $re = qr{($search_phrases)}; while (<TXT>) { s/$re/$seq{$1}/g; print; } __SEQ__ scooped up by social travesty without proper sanitation __TXT__ Many of them are scooped up by chambermaids, thrown into bin bags and +sent off to landfill sites, which is a disaster for the environment a +nd a social travesty given that many people around the world are goin +g without proper sanitation.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: script optmization
by kcott (Archbishop) on May 16, 2017 at 07:08 UTC |