in reply to Tag pattern matching

Rather than a big block of if then elsifs, you might consider using a dispatch table:

#! perl -slw use strict; sub other{ print "Processing '$_[0]' with arg: '$_[1]'" } my %dispatch = map{ $_ => \&other } 'b'..'z'; $dispatch{a} = sub { print "\nNew section\nProcessing 'a' with arg '$_[1]'"; }; while( <DATA> ) { chomp; $dispatch{$1}->( $1, $2 ) while m/ \] ( [a-z] ) \[ ( [^]]+ ) /xg; } __DATA__ ...
P:\test>489332 New section Processing 'a' with arg '1' Processing 'b' with arg: 'FORTUNE BAY' Processing 'c' with arg: '(9)' Processing 'd' with arg: '58' Processing 'e' with arg: 'b g 9 Little Brown Jug-Gemfly (by Golden Eld +er (GB))' Processing 'f' with arg: '(BLINKERS)' Processing 'g' with arg: 'A W & Mrs P I Reynolds, T A Robinson, D J & +Mrs V G Stuart & A R Waghorn' Processing 'h' with arg: 'Gay Stuart, Riverton' Processing 'i' with arg: 'Emerald green, navy blue braces & diamond ar +mbands, emerald green cap' Processing 'j' with arg: '04640' Processing 'w' with arg: 'CANT 13 Aug H Rating 76 1600m 11 of 16 Taile +nd inr,btld closer inr TC Newton 58 (6) 15/15 Wnr: BRIGHTON PIER (AUS +) 1:42.69 13.8L Processing 'k' with arg: ' :(46-2-7-6-6-$21145)' Processing 'm' with arg: ' F(0-0-0) G(17-1-5) D(7-0-1) S(15-1-6) H(7-0 +-1) C(1-0-0) Dst(2-0-0)' New section Processing 'a' with arg '2' Processing 'b' with arg: 'LUCKY LAD' Processing 'c' with arg: '(10)' Processing 'd' with arg: '57' Processing 'e' with arg: 'ch g 6 Shinko King (IRE)-Argyll Dazzler (by +Tarrago (ITY))' Processing 'f' with arg: '(BLINKERS)' Processing 'g' with arg: 'D H F Green' Processing 'h' with arg: 'Kevin Hughes, Riccarton Park' Processing 'i' with arg: 'Emerald green & light blue diagonal stripes, + striped sleeves & cap' Processing 'j' with arg: 'X3333' Processing 'w' with arg: 'CANT 10 Aug H Rating 76 1800m 3 of 15 Trld l +dr,2nd tn,fght mid N G Harris 57 (4) 1/1 Wnr: SHRKAN 2:01.69 4.5L' Processing 'k' with arg: ' :(28-1-4-7-2-$12688)' Processing 'm' with arg: ' F(0-0-0) G(13-0-4) D(7-0-3) S(6-1-3) H(2-0- +1) C(0-0-0) Dst(3-0-2)' New section Processing 'a' with arg '3'

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Tag pattern matching
by Dizzley (Novice) on Sep 06, 2005 at 05:48 UTC
    Ooh I like that!

    Thx,
    ~Diz