Perl - Uninitialize value

Discussion in 'Programming' started by lektrikpuke, Jul 20, 2010.

  1. #1
    Hi y'all,

    Just dabbling with Perl and running the below gives me this error: Use of uninitialized value $i in sprintf. I'm new so googling this just made my head swim.

    Thanks for any help. :)

    Rob

    #!C:/Perl/bin/perl.exe
    use strict;
    use warnings;

    my $Column = 1;
    my $Out = '';
    for(my $i=33; $i<=126; $i++){
    $Out .= sprintf("%3s" . $i) . "=" . chr($i) . " ";
    if(($Column % 10) == 0){
    $Out .= "\n";
    }
    $Column += 1;
    }

    print $Out . "\n";
    print "Finished!\n";
     
    lektrikpuke, Jul 20, 2010 IP
  2. belltower

    belltower Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't have a compiler handy atm, but shouldn't it be sprintf("%3s", $i) ? That is, comma instead of period?
     
    belltower, Jul 20, 2010 IP
  3. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #3
    Thanks, it would work fine without use strict, so I thought I copied it correctly (from a book). Guess my eyes aren't as good as they used to be.
     
    lektrikpuke, Jul 20, 2010 IP