redmustang has asked for the wisdom of the Perl Monks concerning the following question:

Been studying hashes and lists but still need help making first loop

Want to this to $data1,$bob,$dog etc.. creates byte count of the string data

$data1_enc=encode('UTF-8',$data1); $data1_count=length $data1_enc; $bob_enc=encode('UTF-8',$bob); $bob_count=length $data2_enc;

Create a routine that adds preceding characters

making $some_count name variable a fixed length (8 character example) 150 add 5 x's , 1000 add 4 x's

$data1_count=150 $bob_count=1000 $data1_count_fixed= xxxxx150 $bob_count_fixed= xxxx1000

Replies are listed 'Best First'.
Re: Loop or sub routine
by GrandFather (Saint) on May 12, 2011 at 02:29 UTC

    It's not altogether clear to me what you want, but it seems sprintf may be the answer:

    $bob_count_fixed = sprintf '%06d', 150;

    will generate a six digit number with leading zeros.

    True laziness is hard work
Re: Loop or sub routine
by johngg (Canon) on May 12, 2011 at 12:32 UTC
Re: Loop or sub routine
by Marshall (Canon) on May 12, 2011 at 15:19 UTC
    #!/usr/bin/perl -w use strict; for (150, 1000) { print "x" x (8-length($_)); print "$_\n"; } __END__ xxxxx150 xxxx1000
Re: Loop or sub routine
by cjb (Friar) on May 12, 2011 at 10:23 UTC

    What exactly is the question your tutor actually asked you?