develooper Front page | perl.perl6.users | Postings from May 2018

A s/// brain teaser to share

Thread Next
From:
ToddAndMargo
Date:
May 2, 2018 05:46
Subject:
A s/// brain teaser to share
Message ID:
435d43ae-dcb8-f941-0187-c9d9c995a51d@zoho.com
Hi All,

You guys will noticed a bunch of things you have been helping me with
in the following.  Thank you!

:-)

I have been working on cleaning up the file transfer of data from a
point of sale software (POS) program to a label printer.

The customer puts his margin on the end of the description line, so
his labels show his margin, not that anyone would know what that
meant.  He puts his margin and shipping after a slash.

Anyway, the transfer file is a comma delimited text file.
     "sss","dddd"   etc.

Well now, instead of writing out inches, he used a quote.
There goes the label program.  So I changed " to inches.

and the whacking to rid the margin was something to behold.

<code MarginRemoverTest.pl>
#!/usr/bin/env perl6

my $LabelStr='"00046436405","HALT 3/4" ORIG LNG #35-1333-RD/.55 + 
SHP","","     3.95","      0.00","      0.00","      0.00"," 
0.00","","","      0.00","35-1002-RD","WEAV","","","BRIDL","",""';

say "$LabelStr\n";

$LabelStr ~~ s:global|"3/4\""|3/4 inch|;
$LabelStr ~~ s:global|(.*)\/(.*?)(\"\,.*)|$0$2|;
# say "0 = <$0>\n1 = <$1>\n2 = <$2>";
say $LabelStr;


</code>

$ RemoveMarginTest.pl6

"00046436405","HALT 3/4" ORIG LNG #35-1333-RD/.55 + SHP",""," 
3.95","      0.00","      0.00","      0.00","      0.00","",""," 
0.00","35-1002-RD","WEAV","","","BRIDL","",""

"00046436405","HALT 3/4 inch ORIG LNG #35-1333-RD","","     3.95"," 
0.00","      0.00","      0.00","      0.00","",""," 
0.00","35-1002-RD","WEAV","","","BRIDL","",""


About killed me, but I got it.

Part numbers and prices changed to protect the innocent.

-T

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About