On 4/18/05, Keith Worthington <[EMAIL PROTECTED]> wrote: > Hi All, > > 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. > > Kind Regards, > Keith >
Is this the data you expect to get out of the database...or data from somewhere else that you're going to insert into the database...or...? Becuase at the moment it doesn't really look like a database problem. We need some more here, including some sample code. What are you doing, and where is it going wrong? As far as quickstarts go, for database work, the two sources Chris mentioned are really the place to go. For a general perl intoductions, the first place to go is perldoc perlfaq, man perl, and perldoc perlintro, and the best printed resourse is by far _Learning Perl, 3rd Ed._ from O'Reilly. It's short and shout get you up and running in about a day, depending on your general programming ability. As for your specific question, you'll want to use some kind of regex. The following should give you some ideas and show a fairly perlish appraoch to variable declarations, but this is just an example. The perl motto is "There's more than one way to do it." How you end up storing the data into variables will hopefully be deterined by what you ultimately want to do with it. #!/usr/bin/perl use strict; use warnings; my $data = "815 HTPP Black 2in sq Border: RMFP025BK Size: 7'10\" x 16' Tag: None" ; $data =~ /.*Border: (.*) Size: (.*) Tag: (.*)$/; my ($border, $size, $tag) = ($1, $2, $3) ; my ($length, $width) = split / x /, $size ; my (%length, %width); ($length{feet}, $length{inches}) = split /(?:'|")/, $length ; ($width{feet}, $width{inches}) = split /(?:'|")/, $width ; print "$border\n$length{feet}\n$length{inches}\n$width{feet}\n$width{inches}\n$tag\n"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>