Hi All,
Hello,
I am new to the list and need some quick help. I have been kicking around with vi and sed for years but never took the time to learn Perl. Now I need to use Perl and could really use a jumpstart.
I am writing a function in the Postgresql database using Perl because of its text processing power. My other options are less than pretty. :-(
I will be processing inputs like the following:
815 HTPP Black 2in sq Border: RMFP025BK Size: 7'10" x 16' Tag: None 3000 HTPP Black 4in sq Border: WNY200BK Size: 17' x 50' Tag: None 3000 HTPP Black 4in sq Border: WNY200BK Size: 12' x 12'2" Tag: None Netform Lily Pad Net Size: 5' X 32' W & L Body Length:24' Rope Color:Yellow Joint Color:Red 1250 HTPP Black Bonded 2in sq Border: RMFP025BK Size: 39" X 100' Tag: None 1250 HTPP Black Bonded 2in sq Border: RMFP025BK Size: 83" X 40' Tag: None 3000 HTPP Black 4in sq Border: WNY200BK Size: 16'6" x 21'3" Tag: None 250 HTPP Black 1in sq Border: TW84NTBK Size: 9' x 25' Tag: 200' sec 1250 HTPP Yellow 2in sq Border: TW84NYYL Size: 6'1" x 12'7" Tag: 1855mm x 3840mm
I need to parse them up into the pieces Border, Size and Tag. Furthermore I need to break up the Size piece into width and length components, feet and inches.
Using the first example I would like to obtain: 'RMFP025BK' 7 10 16 0 '' (or NULL)
Any help would be appreciated.
This appears to do what you want:
while ( <DATA> ) {
next unless / Border: \s* (.+?) \s+ Size: \s* (?:(\d+)')? (?:(\d+)")? \s*x\s* (?:(\d+)')? (?:(\d+)")? \s+ Tag: \s* (.*) /ix;
print "Border: $1 ", 'Size: ', $2 ? "$2 feet " : '', $3 ? "$3 inches " : '', 'by ', $4 ? "$4 feet " : '', $5 ? "$5 inches " : '', 'Tag: ', "\L$6" eq 'none' ? '' : $6, "\n"; }
__DATA__
815 HTPP Black 2in sq Border: RMFP025BK Size: 7'10" x 16' Tag: None
3000 HTPP Black 4in sq Border: WNY200BK Size: 17' x 50' Tag: None
3000 HTPP Black 4in sq Border: WNY200BK Size: 12' x 12'2" Tag: None
Netform Lily Pad Net Size: 5' X 32' W & L Body Length:24' Rope Color:Yellow Joint Color:Red
1250 HTPP Black Bonded 2in sq Border: RMFP025BK Size: 39" X 100' Tag: None
1250 HTPP Black Bonded 2in sq Border: RMFP025BK Size: 83" X 40' Tag: None
3000 HTPP Black 4in sq Border: WNY200BK Size: 16'6" x 21'3" Tag: None
250 HTPP Black 1in sq Border: TW84NTBK Size: 9' x 25' Tag: 200' sec
1250 HTPP Yellow 2in sq Border: TW84NYYL Size: 6'1" x 12'7" Tag: 1855mm x 3840mm
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>