<html><div style='background-color:'><DIV class=RTE>
<P>Amen to Jeff's comments to say nothing of the code sample!</P>
<P>jvs<BR><BR></P></DIV>
<DIV></DIV>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #a0c6e5 2px solid; MARGIN-RIGHT: 0px"><FONT style="FONT-SIZE: 11px; FONT-FAMILY: tahoma,sans-serif">
<HR color=#a0c6e5 SIZE=1>
<DIV></DIV>From: <I>Jeff Stampes <jeff.stampes@xilinx.com></I><BR>Reply-To: <I>boulder-pm@pm.org</I><BR>To: <I>boulder-pm@pm.org</I><BR>Subject: <I>Re: [Boulder.pm] Newbie File Manipulation question</I><BR>Date: <I>Mon, 17 Jul 2006 11:43:21 -0600</I><BR>Rod Burgess wrote:<BR>> I am new to the Perl world and am trying to learn it. A coworker tells me<BR>> that Perl will not work for what I am trying to do<BR>Hopefully your coworker has other fields of expertise that they *are*<BR>qualified to address.<BR>> however, I think Perl<BR>> would be a great tool to use and I feel this coworker is wrong.<BR>><BR>You are correct. In fact, the stunning thing about your coworker's<BR>comments is that this sort of work is what perl excels at!<BR>> I have a file that contains
several lines all as below:<BR>> DR03555{tab} 45600062888{tab} 00008FLAT WASHER<BR>> DR03555{tab} 228765329{tab} 00001GASKET<BR>><BR>> The meaning of the file is<BR>> DR03555 = order number<BR>> 45600062888 = part number<BR>> 00008 = quantity<BR>> FLAT WASHER = Description<BR>><BR>> The lines all begin with the prefex DR I would like to read this file and<BR>> produce the following output:<BR>><BR>> 45600062888;8;FLAT WASHER<BR>> 228765329;1;GASKET<BR>><BR>> basiclly I need a file that lists the following: Part#;Quantity;Description<BR>><BR>> Is this possible with Perl?<BR>><BR>In many, many ways! Here's one:<BR><BR>#!/usr/bin/perl<BR><BR>use warnings;<BR>use strict;<BR><BR>while ( my
$orderData = <DATA> ) {<BR> chomp $orderData;<BR><BR> my ($quantity, $description );<BR> my ($orderNumber, $partNumber, $other ) = split /\t/, $orderData;<BR><BR> if ( $other =~ /^(\d{5})(.+)$/ ) {<BR> ($quantity, $description) = ( $1, $2 );<BR> } else {<BR> die "Bad quantity/description data found\n";<BR> }<BR><BR> print "$partNumber;$quantity;$description\n";<BR>}<BR><BR>__DATA__<BR>DR03555 45600062888 00008FLAT WASHER<BR>DR03555 228765329 00001GASKET<BR><BR><BR>_______________________________________________<BR>Boulder-pm mailing
list<BR>Boulder-pm@pm.org<BR>http://mail.pm.org/mailman/listinfo/boulder-pm<BR></FONT></BLOCKQUOTE></div><br clear=all><hr> <a href="http://g.msn.com/8HMAENUS/2728??PS=47575" target="_top">Check the weather anywhere, anytime - just type "weather" from MSN Search </a> </html>