From rodbandkimb at msn.com Mon Jul 17 10:26:24 2006 From: rodbandkimb at msn.com (Rod Burgess) Date: Mon, 17 Jul 2006 11:26:24 -0600 Subject: [Boulder.pm] Newbie File Manipulation question Message-ID: I am new to the Perl world and am trying to learn it. A coworker tells me that Perl will not work for what I am trying to do however, I think Perl would be a great tool to use and I feel this coworker is wrong. I have a file that contains several lines all as below: DR03555{tab} 45600062888{tab} 00008FLAT WASHER DR03555{tab} 228765329{tab} 00001GASKET The meaning of the file is DR03555 = order number 45600062888 = part number 00008 = quantity FLAT WASHER = Description The lines all begin with the prefex DR I would like to read this file and produce the following output: 45600062888;8;FLAT WASHER 228765329;1;GASKET basiclly I need a file that lists the following: Part#;Quantity;Description Is this possible with Perl? From jeff.stampes at xilinx.com Mon Jul 17 10:43:21 2006 From: jeff.stampes at xilinx.com (Jeff Stampes) Date: Mon, 17 Jul 2006 11:43:21 -0600 Subject: [Boulder.pm] Newbie File Manipulation question In-Reply-To: References: Message-ID: <44BBCC39.4020403@xilinx.com> Rod Burgess wrote: > I am new to the Perl world and am trying to learn it. A coworker tells me > that Perl will not work for what I am trying to do Hopefully your coworker has other fields of expertise that they *are* qualified to address. > however, I think Perl > would be a great tool to use and I feel this coworker is wrong. > You are correct. In fact, the stunning thing about your coworker's comments is that this sort of work is what perl excels at! > I have a file that contains several lines all as below: > DR03555{tab} 45600062888{tab} 00008FLAT WASHER > DR03555{tab} 228765329{tab} 00001GASKET > > The meaning of the file is > DR03555 = order number > 45600062888 = part number > 00008 = quantity > FLAT WASHER = Description > > The lines all begin with the prefex DR I would like to read this file and > produce the following output: > > 45600062888;8;FLAT WASHER > 228765329;1;GASKET > > basiclly I need a file that lists the following: Part#;Quantity;Description > > Is this possible with Perl? > In many, many ways! Here's one: #!/usr/bin/perl use warnings; use strict; while ( my $orderData = ) { chomp $orderData; my ($quantity, $description ); my ($orderNumber, $partNumber, $other ) = split /\t/, $orderData; if ( $other =~ /^(\d{5})(.+)$/ ) { ($quantity, $description) = ( $1, $2 ); } else { die "Bad quantity/description data found\n"; } print "$partNumber;$quantity;$description\n"; } __DATA__ DR03555 45600062888 00008FLAT WASHER DR03555 228765329 00001GASKET From jason_van_slyke at hotmail.com Mon Jul 17 12:32:15 2006 From: jason_van_slyke at hotmail.com (Jason Van Slyke) Date: Mon, 17 Jul 2006 19:32:15 +0000 Subject: [Boulder.pm] Newbie File Manipulation question In-Reply-To: <44BBCC39.4020403@xilinx.com> Message-ID: An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/boulder-pm/attachments/20060717/f522a473/attachment.html From jason_van_slyke at hotmail.com Mon Jul 17 12:32:15 2006 From: jason_van_slyke at hotmail.com (Jason Van Slyke) Date: Mon, 17 Jul 2006 19:32:15 +0000 Subject: [Boulder.pm] Newbie File Manipulation question In-Reply-To: <44BBCC39.4020403@xilinx.com> Message-ID: An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/boulder-pm/attachments/20060717/f522a473/attachment-0001.html