CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

Post #1 of 2 (2722 views)
Hello! Generate numbers, simple for you ? Can't Post

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

Post #2 of 2 (1773 views)
Re: [cooljojo] Hello! Generate numbers, simple for you ? [In reply to] Can't Post

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
}
}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives