Dan Langille wrote: > Hi folks, > > Some scripting help wanted please. Either Perl or Python. Details > at <http://news.freshports.org/2006/07/19/virtual-categories-have-no- > descriptions/> (also known as <http://tinyurl.com/hhzxh>).
Try this. Run it as: cat-parse.pl categories or even cat-parse.pl < categories Cheers, Matthew -- Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW
#!/usr/bin/perl -w use strict; # Read in the categories file from the filehandle passed as the # argument to this function and return a hash keyed on category name # containing category description and group. See # http://www.freebsd.org/cgi/cvsweb.cgi/www/en/ports/categories for # the imput. # sub cat_parse (*) { my $filehandle = shift; my %categories; my $c; my $d; my $g; while (<$filehandle>) { next unless ( ( $c, $d, $g ) = m/^([^,]+),"([^"]+)",([A-Z]+)/g ); #" $categories{$c} = { DESCR => $d, GROUP => $g }; } return \%categories; } MAIN: { my $categories; $categories = cat_parse(ARGV); for my $c ( keys %{$categories} ) { print "$c\t$categories->{$c}{DESCR}\t$categories->{$c}{GROUP}\n"; } }
signature.asc
Description: OpenPGP digital signature