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

Hi Perlmonks.. Is there any way to make a counter combined of digit and alphanumeric character?? for eq: I have a value :
while(<>){ print " C=A000001\n"; }
then next time( in the while loop ) I want to print A000002 in the next iteration A000003... etc. Do I have to save the value A000001 inside an array or a scalar?? Thanks so much....

Replies are listed 'Best First'.
Re: make a counter
by grep (Monsignor) on Jan 22, 2002 at 11:17 UTC
    All you need to use is the auto-increment operator.
    $a = 'A000001'; while (1) { print "$a\n"; $a++; }


    look up the ++ operator in perlop under Auto-increment.

    Also you should avoid the <> operator for <STDIN> unless you want the side-effects. merlyn explains it better than I.

    UPDATE: If you want, take a look at a fun use of auto-increment.

    OR
    $a = 'A000000'; while (1) { print $a++,"\n"; }


    grep
    grep> cd pub
    grep> more beer
      Thanks Grep...:p :p