Re: Find duplicate numbers and replace
Re: Find duplicate numbers and replace
- Subject: Re: Find duplicate numbers and replace
- From: Skeeve <email@hidden>
- Date: Wed, 14 May 2008 20:41:05 +0200
How long do you use perl, Mark? It's a bit inefficient what you wrote.
#!/usr/bin/perl -i.bak
use strict;
use warnings;
my %numbers; # here our numbers get "counted"
while (<>) {
# append the count if needed
# not: It was not defined what should happen after "z"
# here "aa" will follow
if (s/^(\d+)(?=\[F\])/$1.($numbers{$1}++||'')/e) {
# Was it the first occurence?
if ($numbers{$1} eq 1) {
# then fix the 1 to become an "a"
$numbers{$1}= 'a';
}
}
print;
}
It should work like yours but does not slurp in the whole file (which
could fail if we are working cross platform) and doesn't us as many
regexes as yours does.
as a do shell script:
do shell script "perl -i.bak -e " & (quoted form of "use strict;
use warnings;
my %numbers; # here our numbers get "counted"
while (<>) {
# append the count if needed
# not: It was not defined what should happen after "z"
# here "aa" will follow
if (s/^(\d+)(?=\[F\])/$1.($numbers{$1}++||'')/e) {
# Was it the first occurence?
if ($numbers{$1} eq 1) {
# then fix the 1 to become an "a"
$numbers{$1}= 'a';
}
}
print;
}") & " " & (quoted form of POSIX PATH of inputfile)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden