I'm developing an app that manages Excel files so each user can open a different, serialized file.
It has to add zeros to a number at some point (so the filename becomes nicely formatted), so I've made this into a sub. This sub is called from another sub that starts the process of creating and opening the Excel documents.
So this is the sub who does the job:
sub geraNova
{
my $ctrl = './control.dat';
open(CTR, "+>>$ctrl");
flock(CTR, 2);
my $id = <CTR>;
flock(CTR, 8);
close(CTR);
$id = $id + 1;
unlink $ctrl;
open(CTR, "+>>$ctrl");
flock(CTR, 2);
print CTR $id;
flock(CTR, 8);
close(CTR);
$id = addZeros($id);
#The above calls the sub passing the id to format
my $file = 'C:\Lobo\Sites\test'.$id.'.xls';
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Wi
+n32::OLE->new('Excel.Application');
$Excel->{DisplayAlerts} = 0;
$Excel->{Visible} = 1;
my $Book = $Excel->Workbooks->Add();
$Book->SaveAs($file);
my $ActBook = $Excel->Workbooks->Open("$file") || die "Não foi pos
+sível abrir a planilha. Erro: $!";
undef $Excel;
undef $Book;
undef $ActBook;
}
And this is the one who should add zeros to the control number wich was extracted from a text file:
sub addZeros
{
my $num = $_;
# Below is the line that I'm having problems.
#Perl tells me: Use of uninitialized value in length
while(length($num) < 6)
{
$num = "0".$num;
}
return $num;
}
I know I must be missing something very basic, but I still don't get it... Help, please.
my
($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br")
if ($author_name eq "Er
Galvão Abbott");
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.