in reply to Re^2: Increment a mixed alphanumeric (Updated)
in thread Increment a mixed alphanumeric
By extension:
#! perl -slw use strict; =comment N1234Z becomes N12350 N12359 becomes N1235A N9999Z becomes NA0000 =cut my $id = "F00123Z"; for ( 1 .. 80 ) { print $id; last if substr( $id, -5 ) eq '9999Z'; if( substr( $id, -1 ) eq 'Z' ) { substr( $id, -1 ) = '0'; substr( $id, 1, -1 )++; } elsif( substr( $id, -1 ) eq '9' ) { substr( $id, -1 ) = 'A'; } else { substr( $id, -1 ) ++; } }
|
|---|