From rodbandkimb at msn.com Sat Mar 31 17:49:02 2007 From: rodbandkimb at msn.com (Rod Burgess) Date: Sat, 31 Mar 2007 18:49:02 -0600 Subject: [Boulder.pm] Perl Help Message-ID: I have the following file with three data fields separated by a "; semicol" 14567345;1;Oil Seal 4533457C;1;Heat Shield 56842204;1;Misc Part 5481206D;1;Gasket 81003589I;1;Washer T23546II;1;Shirt The 1st Data Field is Part# The 2nd Data Field is Number of Parts The 3rd Data Field is Part Description The only change that I need to this file is if the 1st data field being the part# ends in a "C,D,I, or II" I would like the file to look like this (having a space between the part number an its Identifier. If that possible with Perl? Could someone show me a sample perl program to do this? 14567345;1;Oil Seal 4533457 C;1;Heat Shield 56842204;1;Misc Part 5481206 D;1;Gasket 81003589 I;1;Washer T23546 II;1;Shirt From Robert.L.Harris at rdlg.net Sat Mar 31 18:35:40 2007 From: Robert.L.Harris at rdlg.net (Robert L. Harris) Date: Sat, 31 Mar 2007 21:35:40 -0400 Subject: [Boulder.pm] Perl Help In-Reply-To: References: Message-ID: <20070401013539.GI17856@rdlg.net> Being a little verbose. while() { chomp; ($Part, $Number, $Desc)=split(";",$_ine); if ($Part =~ /(.*)II/) { $NewPart=$1." II"; } elsif ( $Part =~ /(.*)([CDI])/) { $NewPart=$1." ".$2; } else { $NewPart=$Part; } print OUTPUT $NewPart.";".$Number.";".$Desc; } Thus spake Rod Burgess (rodbandkimb at msn.com): > I have the following file with three data fields separated by a "; semicol" > > 14567345;1;Oil Seal > 4533457C;1;Heat Shield > 56842204;1;Misc Part > 5481206D;1;Gasket > 81003589I;1;Washer > T23546II;1;Shirt > > The 1st Data Field is Part# > The 2nd Data Field is Number of Parts > The 3rd Data Field is Part Description > > The only change that I need to this file is if the 1st data field being the > part# ends in a "C,D,I, or II" > I would like the file to look like this (having a space between the part > number an its Identifier. > If that possible with Perl? Could someone show me a sample perl program to > do this? > > 14567345;1;Oil Seal > 4533457 C;1;Heat Shield > 56842204;1;Misc Part > 5481206 D;1;Gasket > 81003589 I;1;Washer > T23546 II;1;Shirt > > > _______________________________________________ > Boulder-pm mailing list > Boulder-pm at pm.org > http://mail.pm.org/mailman/listinfo/boulder-pm :wq! --------------------------------------------------------------------------- Robert L. Harris | GPG Key ID: E344DA3B @ x-hkp://pgp.mit.edu DISCLAIMER: These are MY OPINIONS With Dreams To Be A King, ALONE. I speak for First One Should Be A Man no-one else. - Manowar -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://mail.pm.org/pipermail/boulder-pm/attachments/20070331/7190b7dc/attachment.bin From rodbandkimb at msn.com Sat Mar 31 19:24:53 2007 From: rodbandkimb at msn.com (Rod Burgess) Date: Sat, 31 Mar 2007 20:24:53 -0600 Subject: [Boulder.pm] Perl Help In-Reply-To: <20070401013539.GI17856@rdlg.net> Message-ID: Robert, Thanks for providing this code. I continue to learn new Perl tricks all of the time. Again thanks. Rod >From: "Robert L. Harris" >Reply-To: boulder-pm at pm.org >To: boulder-pm at pm.org >Subject: Re: [Boulder.pm] Perl Help >Date: Sat, 31 Mar 2007 21:35:40 -0400 > > > > >Being a little verbose. > >while() { > chomp; > ($Part, $Number, $Desc)=split(";",$_ine); > if ($Part =~ /(.*)II/) { > $NewPart=$1." II"; > } elsif ( $Part =~ /(.*)([CDI])/) { > $NewPart=$1." ".$2; > } else { > $NewPart=$Part; > } > print OUTPUT $NewPart.";".$Number.";".$Desc; >} > > > > > >Thus spake Rod Burgess (rodbandkimb at msn.com): > > > I have the following file with three data fields separated by a "; >semicol" > > > > 14567345;1;Oil Seal > > 4533457C;1;Heat Shield > > 56842204;1;Misc Part > > 5481206D;1;Gasket > > 81003589I;1;Washer > > T23546II;1;Shirt > > > > The 1st Data Field is Part# > > The 2nd Data Field is Number of Parts > > The 3rd Data Field is Part Description > > > > The only change that I need to this file is if the 1st data field being >the > > part# ends in a "C,D,I, or II" > > I would like the file to look like this (having a space between the part > > number an its Identifier. > > If that possible with Perl? Could someone show me a sample perl program >to > > do this? > > > > 14567345;1;Oil Seal > > 4533457 C;1;Heat Shield > > 56842204;1;Misc Part > > 5481206 D;1;Gasket > > 81003589 I;1;Washer > > T23546 II;1;Shirt > > > > > > _______________________________________________ > > Boulder-pm mailing list > > Boulder-pm at pm.org > > http://mail.pm.org/mailman/listinfo/boulder-pm > >:wq! >--------------------------------------------------------------------------- >Robert L. Harris | GPG Key ID: E344DA3B > @ x-hkp://pgp.mit.edu >DISCLAIMER: > These are MY OPINIONS With Dreams To Be A King, > ALONE. I speak for First One Should Be A Man > no-one else. - Manowar > ><< signature.asc >> >_______________________________________________ >Boulder-pm mailing list >Boulder-pm at pm.org >http://mail.pm.org/mailman/listinfo/boulder-pm