Two Plus Two Older Archives

Two Plus Two Older Archives (http://archives2.twoplustwo.com/index.php)
-   Software (http://archives2.twoplustwo.com/forumdisplay.php?f=43)
-   -   Regexp Guru wanted (http://archives2.twoplustwo.com/showthread.php?t=298306)

Rudbaeck 07-22-2005 02:15 PM

Regexp Guru wanted
 
I have a text file consisting of a single column of player names.

I want this to turn into a series of rows, none of which is over 100 characters in length, with the player names comma deliminated and all duplicate player names removed.

Or for a high level view, if you can think of another way to do it: I want to take the export of all fish names from PT and make it into a bunch of strings that I can copy and paste into the Party Search function. [img]/images/graemlins/smile.gif[/img]

tlnini 07-22-2005 03:34 PM

Re: Regexp Guru wanted
 
Perl script with 5-6 lines, or just open it up in Excel, and copy/paste using transpose, and save it as CSV

Rudbaeck 07-22-2005 05:43 PM

Re: Regexp Guru wanted
 
[ QUOTE ]
Perl script with 5-6 lines, or just open it up in Excel, and copy/paste using transpose, and save it as CSV

[/ QUOTE ]

Using excel is how I have been doing it. But as the datamining continues the fish list is growing rather long. There is essentially no way around copying and pasting the finished search strings into Party manually, so I wanted to cut down on the rest of the work as much as possible.

Dr. Neau 07-22-2005 08:58 PM

Re: Regexp Guru wanted
 
Perl:

1. Rip through file, parsing out player names into an associative array
2. Join the array with commas

awr000 07-22-2005 10:23 PM

Re: Regexp Guru wanted
 
myFish

It is by no means feature complete but should be functional enough to get started. I'll try and finish/augment it sometime over the next few days.

StevieG 07-23-2005 04:08 PM

Re: Regexp Guru wanted
 
[ QUOTE ]
Perl:

1. Rip through file, parsing out player names into an associative array
2. Join the array with commas

[/ QUOTE ]

Assuming you have Perl, save this as list_from_row.pl

<font class="small">Code:</font><hr /><pre>
#!/usr/bin/perl
# usage: list_from_row.pl [[filename]...]

my $MAX_LENGTH = 100;
my $OUTPUT_FILE = "fishFrySearch.txt";

my %fish;

open OUT, "&gt;$OUTPUT_FILE" ||
die "Could not open output file $OUTPUT_FILE for writing.\n";

foreach my $file (@ARGV) {
my $count=0;
if (! -f $file) {
print "$file is not a file.\n";
} else {
open IN, $file || die "Could not open $file";
while (my $name = &lt;IN&gt;) {
$count++;
$name =~ s/^\s*//;
$name =~ s/\s*$//;
$fish{$name}++ if ($name);
}
}
print "Processed $count lines from $file.\n",
scalar(keys %fish)," unique names total.\n";
}

my $line='';
foreach my $name (sort keys %fish) {
if (length($line) + length($name) &gt;= $MAX_LENGTH) {
printLine($line);
} else {
$line .= $name . ',';
}
}
printLine($line);

sub printLine() {
my $line = shift @_;
$line =~ s/,$//;
print OUT $line, "\n";
}

</pre><hr />

Rudbaeck 07-23-2005 10:16 PM

Re: Regexp Guru wanted
 
Awesome! Thank you so much.


All times are GMT -4. The time now is 02:56 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.