From: ian Date: Wed, 14 Apr 2004 16:19:38 +0000 (+0000) Subject: resistor converter mk 1 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=e985130b55aa0b39abc83a1ebc77166a60840b74;p=trains.git resistor converter mk 1 --- diff --git a/farnell/farnell-resistor-convert.pl b/farnell/farnell-resistor-convert.pl new file mode 100755 index 0000000..d8ed939 --- /dev/null +++ b/farnell/farnell-resistor-convert.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl +# ways to invoke: +# 1. Get a search list from farnell and feed HTML source to +# this script with no args. Will produce part number list. +# 2. Feed one or more outputs from farnell-find to +# this script with args ... +# where is the re for the first part of the mfr +# code and is the words of the part name prefix. +if (@ARGV>=2) { + ($kind,@prefix)= @ARGV; + while () { + if (m/^Avail\s/) { + undef $value; + } elsif (m/^Description\s+\[$kind (\d[0-9MKR]+)\]\s+RESISTOR/) { + $value= lc $1; + } elsif (m/^Description\s+(\S.*)/) { + print "# $1\n"; + $value= ''; + } elsif (m/^Item\s+([-0-9]+)$/) { + die unless defined $value; + next unless length $value; + printf "%s\t%s\n", join(' ',@prefix,$value), $1; + undef $value; + } + } +} elsif (!@ARGV) { + while () { + if (m/viewproductdetails.*\?prodId\=(\d{3})(\d{3,7})\"/) { + print "$1-$2\n" or die $!; + } + } +} else { + die; +}