Re: Newbie Perl Question




""Rod Burgess"" <rodbandkimb@xxxxxxx> wrote in message
news:BAY116-F293D6F8A3796D64F78AE7DB8620@xxxxxxxxxx
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?


You bet. This is what perl was made for:

$ cat tab2csv.dat
DR03555 45600062888 00008FLAT WASHER
DR03555 228765329 00001GASKET

$ cat tab2csv.pl
while (my $line = <>) {
my( $order, $part, $qty, $descr ) = $line =~ m|(.+?)\t(.+?)\t(\d+)(.+)$|;
print( join(';', $part, $qty + 0, $descr), "\n" );
}

$ perl tab2csv.pl tab2csv.dat
45600062888;8;FLAT WASHER
228765329;1;GASKET

Enjoy,

Todd W.


.



Relevant Pages

  • Re: Newbie Perl Question
    ... $InputFileName) or die "Could not open $InputFileName for reading: ... or die "Could not open $OutputFileName for output: ... Subject: Newbie Perl Question ... DR035554560006288800008FLAT WASHER ...
    (perl.beginners)
  • Re: Newbie Perl Question
    ... that Perl will not work for what I am trying to do however, ... would be a great tool to use and I feel this coworker is wrong. ... DR035554560006288800008FLAT WASHER ... perldoc -f readline ...
    (perl.beginners)
  • Re: Newbie Perl Question
    ... I am trying to adopt your script to my need, and, basically, it works ... this really great part of perl:) ... DR035554560006288800008FLAT WASHER ... basiclly I need a file that lists the following: ...
    (perl.beginners)
  • Re: Newbie Perl Question
    ... "Rod Burgess" schreef: ... Your Subject has no quality. ... I think Perl would be a great tool to use and I feel this coworker ... DR035554560006288800008FLAT WASHER ...
    (perl.beginners)
  • Re: Dumb printing question
    ... If you want to split the output and both drive the printer and save a file copy then look at the jetdirectprint script.. ... # cat jetdirectprint ... open a socket to the printer. ... My PERL is nonexistent, so don't ask me for syntactically correct PERL. ...
    (comp.os.linux.misc)