Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Need RE. New to Perl
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 3
840mm

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 i
nches.

Using the first example I would like to obtain:
'RMFP025BK'
7
10
16
0
'' (or NULL)

Any help would be appreciated.

Kind Regards,
Keith

Report this thread to moderator Post Follow-up to this message
Old Post
Keith Worthington
04-19-05 01:56 AM


Re: Need RE. New to Perl
On Mon, 18 Apr 2005, Keith Worthington wrote:

> Any help would be appreciated.

Write a program.

Use the DBI module for the database programming.

Get the DBD::Pg plugin to DBI for the PostgreSQL driver.

Get this stuff from CPAN if it isn't on your system already.

Break the problem down into simpler steps if you need to.


From the *nix command line, read over `perldoc DBI` for the basics, or
get a copy of a book like _Programming the Perl DBI_ for details.


This list isn't a script writing service; while we are very happy to
help new learners, you have to at least take a stab at reading over the
documentation and writing your own code. Please show what you've tried
so far and indicate what you're getting stuck on, and we can help you
take it from there.


--
Chris Devers

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Devers
04-19-05 01:56 AM


Re: Need RE. New to Perl
Keith Worthington wrote:
> 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 ne
ed
> to use Perl and could really use a jumpstart.
>
> I am writing a function in the Postgresql database using Perl because of i
ts
> 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:Yell
ow
> Joint Color:Red
>  1250 HTPP Black Bonded 2in sq Border: RMFP025BK Size: 39" X 100' Tag:  No
ne
>  1250 HTPP Black Bonded 2in sq Border: RMFP025BK Size: 83" X 40' Tag:  Non
e
>  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

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
04-20-05 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:17 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.