I am confused about what you are looking for. You are setting the text to encode three different times, and generating two separate images, although you only save the last one to a file. That last one has a fixed string ("CODE 128") so you should be getting the same .png file each time.

Here's some quick-n-dirty code that produces three barcodes with different integer texts, hope it can help you.

#/usr/bin/perl use strict; use warnings; use diagnostics; use Barcode::Code128; my $times = 3; print "Running Barcode... encoding $times random integers\n"; my $object = Barcode::Code128->new(); $object->code('A'); # Enforce 128A? srand(0); # More interested in repeatability than randomness foreach (1 .. $times) { my $text = ""; # Make up a 10-digit decimal number $text .= "".int(rand(10)) foreach (1 .. 10); my $filename = "code128_".$_.".png"; open(my $png, ">", $filename) || die("Cannnot open $filename: $!") +; binmode($png); print $png $object->png($text); close($png); print "Text \"$text\" encoded in file $filename\n"; }


In reply to Re: help with Barcode::Code128 by gmargo
in thread help with Barcode::Code128 by djbryson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.