shoura has asked for the wisdom of the Perl Monks concerning the following question:
seq.txt example :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.
scooped up by social travesty without proper sanitation
use strict; use warnings; use autodie; open Newfile ,">./Newfile.txt" or die "Cannot create Newfile.txt"; my %rep; my ($f1, $f2) = ('seq.txt', 'mytext.txt'); open(my $fh, $f1); my @seq; foreach (<$fh> ) { chomp; s/^\s+|\s+$//g; push @seq, $_; } close $fh; @seq = sort bylen @seq; # need to sort @seq by length. open($fh, $f2); foreach (<$fh> ) { foreach my $r (@seq) { my $t = $r; $t =~ s/\h+/bbb/g; s/$r/$t/g; } print Newfile; } close $fh; close Newfile ; exit 0; sub bylen { length($b) <=> length($a); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: script optmization
by 1nickt (Canon) on May 14, 2017 at 16:37 UTC | |
|
Re: script optmization
by tybalt89 (Monsignor) on May 14, 2017 at 21:13 UTC | |
|
Re: script optmization
by BillKSmith (Monsignor) on May 14, 2017 at 14:56 UTC | |
|
Re: script optmization
by kcott (Archbishop) on May 15, 2017 at 03:53 UTC | |
by Marshall (Canon) on May 15, 2017 at 23:21 UTC | |
by kcott (Archbishop) on May 16, 2017 at 07:08 UTC | |
|
Re: script optmization
by Anonymous Monk on May 14, 2017 at 13:40 UTC | |
by shoura (Novice) on May 14, 2017 at 14:41 UTC | |
by Anonymous Monk on May 14, 2017 at 17:13 UTC | |
|
Re: script optmization
by Anonymous Monk on May 14, 2017 at 21:33 UTC | |
by Anonymous Monk on May 14, 2017 at 22:04 UTC | |
by Anonymous Monk on May 14, 2017 at 23:00 UTC | |
by Anonymous Monk on May 14, 2017 at 23:27 UTC | |
|
Re: script optmization
by zentara (Cardinal) on May 14, 2017 at 13:04 UTC | |
by shoura (Novice) on May 14, 2017 at 13:23 UTC | |
by Anonymous Monk on May 14, 2017 at 13:43 UTC |