in reply to serial number generator
Hello royserna03, and welcome to the Monastery!
The following script should do what you want:
#!/usr/bin/perl use strict; use warnings; use Excel::Writer::XLSX; my $workbook = Excel::Writer::XLSX->new( 'simple.xlsx' ); my $worksheet = $workbook->add_worksheet(); print "How many Serial Numbers do you need?\n"; my $mal = <STDIN>; my $comp = 'ITS'; my @array; for (my $number = 1; $number <= $mal; $number++) { my $exp = $comp . sprintf("%04d", $number); push @array, $exp; } $worksheet->write_col(0, 0, \@array);
Some notes:
Always use strict; and declare lexical variables with my.
Barewords must be quoted: my $comp = 'ITS';
If you want (say) 5 serial numbers, and they start at 1, then the last number must be 5, so the loop condition needs to be $number <= $mal.
You can use sprintf to prepend 0s to the serial number.
The key point: Each time a new value of $exp is calculated, it must be added to the array. See push.
Hope that helps,
Athanasius <°(((>< contra mundum
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: serial number generator
by GrandFather (Saint) on Oct 03, 2012 at 04:26 UTC | |
|
Re^2: serial number generator
by royserna03 (Initiate) on Oct 03, 2012 at 20:31 UTC | |
by Athanasius (Archbishop) on Oct 04, 2012 at 02:59 UTC | |
by royserna03 (Initiate) on Oct 04, 2012 at 03:51 UTC | |
by Anonymous Monk on Oct 04, 2012 at 04:21 UTC | |
by royserna03 (Initiate) on Oct 04, 2012 at 23:30 UTC |