Subject:
|
Re: Access a LEGO set DB with your phone!
|
Newsgroups:
|
lugnet.off-topic.geek
|
Date:
|
Wed, 20 Mar 2002 22:22:28 GMT
|
Viewed:
|
335 times
|
| |
| |
In lugnet.off-topic.geek, Christopher L. Weeks writes:
> > > http://guide.lugnet.com/set/list/bynumber.txt
> [...]
> Also, what tool should I be using the parse that web page? I can't seem to
> get the right expression to make split break it down by the fields apparent
> in the table. Am I missing something simple?
Chris,
Save the attached Perl5 program to a file (parse.pl) and try this:
cat bynumber.txt | perl parse.pl | more
--Todd
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#!/usr/local/bin/perl5 -w
use strict;
while (<STDIN>) { last if m/^_/; } # Skip document header
chop(my $fields = scalar(<STDIN>)); # Extract field names
my @fields = split /\t/, $fields;
my @sets = map { # Slurp all the sets into a big huge
chop; # array of hashes.
my %set;
@set{@fields} = split /\t/;
\%set;
} <STDIN>;
dump_list(sort by_setid @sets); # Print list sorted by set id.
dump_list(sort by_name @sets); # Print list sorted by set name.
dump_list(sort by_theme @sets); # Print list sorted by theme.
exit;
sub by_setid { # Compare two sets by id.
my @A = split /-/, $a->{'Unique ID'};
my @B = split /-/, $b->{'Unique ID'};
return ($A[0] <=> $B[0]) || ($A[1] <=> $B[1]);
}
sub by_name { # Compare two sets by name.
return $a->{'Name'} cmp $b->{'Name'};
}
sub by_theme { # Compare two sets by theme.
return $a->{'Theme'} cmp $b->{'Theme'};
}
sub dump_list { # Print list of all sets
foreach my $set (@_) {
print "-" x 79, "\n";
foreach my $i (0..$#fields) {
print "$fields[$i] = $set->{$fields[$i]}\n";
}
}
}
|
|
Message is in Reply To:
| | Re: Access a LEGO set DB with your phone!
|
| (...) I were a programmer! I've spent the last eight hours trying to learn enough perl to massage the data into a multidimensional array, but I think I'm giving up, for the day at least. I can't find a reference, tutorial, or FAQ that describes more (...) (23 years ago, 17-Mar-02, to lugnet.off-topic.geek)
|
9 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|