Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Hello! Generate numbers, simple for you ?



cooljojo
New User

Mar 10, 2010, 9:39 AM


Views: 5650
Hello! Generate numbers, simple for you ?

Good morning all !
I hope you're fine Smile

I would have a request about a perl program please. I tried to do it, but I failed. Seem that my brain is really not done for programing -_-... I think it's simple for you:

Example:


Quote

^XA
^PMN
^MNY
^MMR
^MTT
^MD20
^LH0,0
^LL150
^PR2
^JMA
^FO20,4^CI0^A0N,50,25^FR^FDID^FS00001^FS
^FO20,50^BY1.6,3.0,45^BCN,75,N,N,N^FR^FD^FS
^FO95,132^CI0^A0N,47,35^FR^FD00001^FS
^PQ1
^XZ

^XA
^PMN
^MNY
^MMR
^MTT
^MD20
^LH0,0
^LL150
^PR2
^JMA
^FO20,4^CI0^A0N,50,25^FR^FDID^FS00002^FS
^FO20,50^BY1.6,3.0,45^BCN,75,N,N,N^FR^FD^FS
^FO95,132^CI0^A0N,47,35^FR^FD00002^FS
^PQ1
^XZ

etc.



I would need a script that generate 10000 times the text block between "^XA" and "^XZ" (included) and that increment each time by 1. The zero and the space between each text block are very important. So it will be 00001, 00002, 00003 ... to 10000. There are only the number which change :).
I think it's cool if the final result is in a text file.

I would accept any help cause i would be honest with you, I'm not a developper but technician.

I thank you in advance.
Have a nice day ! Wink


Bianca
User

Jun 4, 2010, 6:56 AM


Views: 4701
Re: [cooljojo] Hello! Generate numbers, simple for you ?

Do you need this?


Code
#!/usr/bin/env perl -W 
use strict;
use warnings;
use Fcntl;
if (sysopen(my $fh,'myfile.txt',O_WRONLY|O_TRUNC|O_CREAT)) {
for (my $z = 1; $z <= 10000; $z ++) {
my $val = sprintf ("%05u",$z);
print $fh ($z > 1 ? "\n" : '') . <<CONTENT;
^XA
^PMN
^MNY
^MMR
^MTT
^MD20
^LH0,0
^LL150
^PR2
^JMA
^FO20,4^CI0^A0N,50,25^FR^FDID^FS$val^FS
^FO20,50^BY1.6,3.0,45^BCN,75,N,N,N^FR^FD^FS
^FO95,132^CI0^A0N,47,35^FR^FD$val^FS
^PQ1
^XZ
CONTENT
}
}