Re: Script for Sheduling jobs on NT

2001-07-28 Thread Walt Mankowski

On Sat, Jul 28, 2001 at 01:56:46PM +0200, Ackim Chisha wrote:
 Does any one already have a perl script for NT that I could use to run like
 a cron job in unix.  Am writing a scrip that I need to have running every 5
 minuteseveryday. Or is there a way I can write my script so that it runs
 every 5 minutes. Task sheduler on NT looks like it cant help run my script
 every 5minutes everyday.
 
 Any help will be appreciated.

Three thoughts:

1.  Schedule at jobs to run your script every five minutes.

$script_path = 'c:\path\to\myscript.pl';
for $hour (0..23) {
  for ($min = 0; $min  60; $min += 5) {
$cmd = sprintf (at %02d:%02d /e:m,t,w,th,f,sa,su %s,
$hour, $min, $script_path);
system($cmd);
  }
}

2.  Have your script run in an infinite loop.  At the bottom of the
loop, sleep until 5 minutes are up:

$five_minutes = 5 * 60;
while (1) {
  $start_time = time;
  do_stuff;
  sleep($five_minutes - (time - $start_time));
}

3.  Search the net for a Windows-native cron program, of which I'm
sure there must be a bunch.

Walt



 PGP signature


Re: my, strict, and function references

2001-07-28 Thread Walt Mankowski

On Sat, Jul 28, 2001 at 07:10:59PM -0700, Dan Grossman wrote:
 I'm wondering why Perl doesn't complain about the following code:
 
 --
 #!/usr/bin/perl -w
 use strict;
 
 my $funcRef = \otherDummyFunc;
 my $oneVar = callTheReferredFunc();
 print $oneVar;
 
 sub dummyFunc {
 return 42;
 }
 
 sub otherDummyFunc {
 return your mom;
 }
 
 sub callTheReferredFunc {
 my $returnVal = $funcRef;
 return $returnVal;
 }
 --
 
 Output: your mom
 
 I don't pass $funcRef to callTheReferredFunc, and yet -w doesn't
 generate a warning for an undefined reference.  Are function
 references somehow global in nature?  This doesn't seem to be true of,
 say, variable references.
 
 I'm clearly missing something.  Explanations would be helpful ...

Since $funcRef isn't declared inside a block, it's global to the
entire file.

For more information, perldoc perlsub and look for the section
entitled Private Variables via my().  You might also want to read
Mark-Jason Dominus's article Coping With Scoping, available on the
web at http://perl.plover.com/FAQs/Namespaces.html

Walt


 PGP signature


Re: last line

2001-07-27 Thread Walt Mankowski

COLLINEAU writes:
 How can i do to delete the last line of a file ?

From perlfaq5...

 How do I change one line in a file/delete a line in a
 file/insert a line in the middle of a file/append to the
 beginning of a file?

 snip

 In the unique case of deleting lines at the end of a file,
 you can use tell() and truncate().  The following code
 snippet deletes the last line of a file without making a
 copy or reading the whole file into memory:

 open (FH, + $file);
 while ( FH ) { $addr = tell(FH) unless eof(FH) }
 truncate(FH, $addr);

 Error checking is left as an exercise for the reader.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Hi, what time() ^ $$ means?

2001-07-10 Thread Walt Mankowski

On Tue, Jul 10, 2001 at 09:56:55PM -0400, Jeff 'japhy' Pinyan wrote:
 Just so you know, you don't need to call srand() in modern versions of
 Perl.

Unless, of course, you want to seed the random number generator to a
specific value.  :-)

Walt




Re: Hi, what time() ^ $$ means?

2001-07-10 Thread Walt Mankowski

On Tue, Jul 10, 2001 at 07:27:04PM -0700, Erik W wrote:
 Thanks a lot, then what  means?

From perldoc perlop...

   Binary  returns the value of its left argument shifted left
   by the number of bits specified by the right argument.
   Arguments should be integers.  (See also the Integer Arithmetic
   entry elsewhere in this document.)

A left shift of n bits is the same as multiplying by 2 n times, and a
right shift is the same as dividing by 2 n times.  Sometimes it's
easier to think of the bits as moving to the left or right than to
think of multiplying or dividing by powers of 2, but they're really
the same operation.

 $$15 ???

This shifts the value of $$ 15 bits to the left, which is the same as
multiplying $$ by 2**15.

 perl is really unreadable!

Actually bit manipulation is pretty basic computer science.  Perl
borrowed the operators from C.

Walt



Re: Hi, what time() ^ $$ means?

2001-07-10 Thread Walt Mankowski

On Wed, Jul 11, 2001 at 12:34:37AM -0400, Walt Mankowski wrote:
 On Tue, Jul 10, 2001 at 07:27:04PM -0700, Erik W wrote:
  $$15 ???
 
 This shifts the value of $$ 15 bits to the left, which is the same as
 multiplying $$ by 2**15.

I forgot to reference the code you were referring to:

 time() ^ ($$ + ($$  15))

The reason they're shifting $$ 15 bits to the left is that they're
assuming that the process id (which is what $$ is) is a 15-bit
integer.  This has been traditionally true in Unix, but I believe I've
read about some support in recent Linux kernels for 32767 processes.

Once they leftshift it 15 bytes, the rightmost 15 bytes are 0.  By
adding $$ to it they fill in those empty bytes with $$ again.  The
result is a 30-bit number consisting of the bits in $$ repeated twice.

There are better methods of seeding random number generators, so this
method is mainly of educational and historical interest.  As Jeff
mentioned, in modern perls rand() will call srand() automatically the
first time it's called.

Walt



Re: How to make a resource intensive script less intensive.

2001-07-08 Thread Walt Mankowski

On Sun, Jul 08, 2001 at 02:20:40PM -0400, Jim Conner wrote:
 I am writing a script that is quite cool imo once I get it done.  But 
 already I am seeing that it takes a ton of system resources.  Simply put, 
 the script watches a log file (like tail -f) and then reacts to certain 
 things that occur.  I am thinking that the loop that it is in might be 
 taking up all the resources but that doesn't quite jive with my knowledge 
 of how this kind of thing works.  Here is a snippet of the resource usage 
 from top(3):

You're using up all those resources because your program is sitting in
a hard loop.  Try inserting a sleep at the bottom of your outer for
loop.  You might also want to take a look at How do I do a 'tail -f
in perl?' in perlfaq5.

Walt




Re: problems with chmod

2001-07-07 Thread Walt Mankowski

On Sat, Jul 07, 2001 at 10:48:14AM -0500, [EMAIL PROTECTED] wrote:
 #!/usr/bin/perl -w
 
 use strict;
 
 my $dir = cody;
 mkdir($dir,0770);
 
 
 i am running this in my home directory on a linux machine, so i have full
 rights. when i run this however, the permissions on the directory are:
 
 drwxr-x---2 cmenzes  cmenzes  1024 Jul  7 10:39 cody/
 
 which translates to 0750. i am thinking that this limit may have to do
 with my shell umask setting which is at 022, but i am not certain why it
 is taking precedence over the perl setting. if i change my second argument
 in my mkdir statement to 0660 or 0444, the proper permissions are set. the
 only pattern that i see is that i *can* explicitly set the permissions in
 a mkdir statement if they are more restrictive than my umask. otherwise
 the perms default to my umask.
 i know i can get past this by following the mkdir statement with a chmod,
 but i just wanted to verify that my logic on this one is correct.

The second parameter to mkdir is just a mask, it's not the permission
settings for the new directory.  See perldoc -f mkdir for more
information.

Walt




Re: syntax highlighting module

2001-07-07 Thread Walt Mankowski

On Fri, Jul 06, 2001 at 12:27:14PM +0500, Rizwan wrote:
 Where can I find a systax highlighting module for perl in perl.
 I want to call it from within the script and pass a perl script file to be 
 syntactically highlighted..

I haven't tried it, but if you want the output to be HTML you might
check out the Apache::PrettyPerl module on CPAN.




Re: syntax highlighting module

2001-07-07 Thread Walt Mankowski

On Fri, Jul 06, 2001 at 12:27:14PM +0500, Rizwan wrote:
 Where can I find a systax highlighting module for perl in perl.
 I want to call it from within the script and pass a perl script file to be 
 syntactically highlighted..

I haven't tried it, but if you want the output to be HTML you might
check out the Apache::PrettyPerl module on CPAN.




Re: Joining variables

2001-06-27 Thread Walt Mankowski

On Wed, Jun 27, 2001 at 02:07:22PM +0100, Pierre Smolarek wrote:
 $newvar = $var1.-.$var2.-.$var3;

or $newvar = $var1-$var2-$var3;



Re: HELP! this has me rather ummm PISSED ;)

2001-06-26 Thread Walt Mankowski

On Tue, Jun 26, 2001 at 03:04:33PM -0400, Yacketta, Ronald wrote:
 the following should
 1) suck in all the files in a dor
 2) split them into 3 arrays (logger files only)
 3) run a forked egrep on each array of files

I don't understand why you're going to all the trouble of building
three arrays and shelling out to egrep when you can use perl's own
regexes.  Would something like this work?

$lookFor=Test App 
Finished|Fault2-0|ORA-|Bind|SystemError|SystemException|Communication|ORBA|Get Q 
Error;
opendir DIR, ../logs/set1/ or die Can't open ../logs/set1/: $!;
while (my $file = readdir(DIR)) {
  next unless $file =~ /logger/;

  my $filename = ../logs/set1/$file;
  open FP, $filename;
  while (my $line = FP) {
print $filename: $line if $line =~ /$lookFor/;
  }
  close FP;
}

Walt




Re: Date in NT?

2001-06-26 Thread Walt Mankowski

On Wed, Jun 27, 2001 at 12:23:36AM -0400, Jeff 'japhy' Pinyan wrote:
 Or use the POSIX::strftime() function, which uses its own %X formats to
 create a date string.

Or the UnixDate() function in Date::Manip.pm, although that's almost
certainly overkill for what you're doing here.

Walt




Re: how to wait 50 second ?

2001-06-01 Thread Walt Mankowski

On Fri, Jun 01, 2001 at 01:53:17PM +0200, [EMAIL PROTECTED] wrote:
 Is it possible to use a commando in Perl that will wait for example 50 
 seconds an then will continue ?

Yes -- sleep(50)

See perldoc -f sleep for more information.

Walt



Re: looping over an array of hashes

2001-06-01 Thread Walt Mankowski

On Fri, Jun 01, 2001 at 03:29:43PM -0700, Chuck Ivy wrote:
 First post, quick question:
 
 I've got an array of hashes that I'm defining the most basic way I can...
 
 my $gSeasonID;
 my @season_list = '';
 while (@fields = $sth-fetchrow_array) {
   $gSeasonID = $fields[0];
   $season_list[$gSeasonID]{number} = $fields[1];
   $season_list[$gSeasonID]{title} = $fields[2];
   $season_list[$gSeasonID]{active} = $fields[3];
 }
 
 where @fields is coming from a DBI query.
 
 Essentially I have
 
 $season_list[1]{number} = 1;
 $season_list[1]{title} = 'Season One';
 $season_list[1]{active} = 0;
 $season_list[2]{number} = 1;
 $season_list[2]{title} = 'Season Two';
 $season_list[2]{active} = 1;
 
 That's fine, and it seems to be writing correctly. But I'd like to loop 
 on my array index later to get back, say {title} from each season.
 
 Is there a clean way to do this with foreach or while? What I'd be 
 looking for would be $season_list[$loop_season]{name}, if I were using a 
 for loop with $loop_season as my index. Is there a way to do this 
 with $_ or something and foreach so that I don't have to know the size 
 of my array?

Each element in @season_list is just a reference to a hash, so you can
loop through it with foreach using code like this:

foreach my $sl (@season_list) {
print $sl-{title}\n;
}





Re: Sockets help

2001-05-30 Thread Walt Mankowski

On Wed, May 30, 2001 at 09:47:51AM -0400, Jason wrote:
 I need to write a program that will take a list of url's for pictures
 and download them.  I was reading up on sockets but i found them a bit
 confusing.  Some assistance with sockets would be very helpfull.

Use LWP::Simple.  It can already do this out of the box, it's very
easy to use, and it doesn't require any knowlege of sockets.

Walt

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: Sleeping for less than a second

2001-05-30 Thread Walt Mankowski

On Wed, May 30, 2001 at 01:42:17PM -0400, Craig Moynes/Markham/IBM wrote:
 Hi all, my DNS server is down so I can't check online.

No need to check online.  This answer is in the FAQ that comes with
Perl.

 Is there anyway to sleep for less than a second using the default
 installation of perl ?
 And if not what CPAN module should I use when I get my internet connection
 back up ?

$ perldoc -q sleep
Found in /usr/local/lib/perl5/5.6.1/pod/perlfaq8.pod
 How can I sleep() or alarm() for under a second?

 If you want finer granularity than the 1 second that the
 sleep() function provides, the easiest way is to use the
 select() function as documented in the select entry in the
 perlfunc manpage.  Try the Time::HiRes and the BSD::Itimer
 modules (available from CPAN).

Walt

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: Sleeping for less than a second

2001-05-30 Thread Walt Mankowski

On Wed, May 30, 2001 at 01:47:55PM -0400, Jeff Pinyan wrote:
 =head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq8.pod

Looks like you're overdue for an upgrade... :-)

Walt

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: qw

2001-05-30 Thread Walt Mankowski

On Wed, May 30, 2001 at 03:38:35PM -0500, Nichole Bialczyk wrote:
 i'm trying to work my way throuh an existing script and it says
 
 @array = qw(stuff, more stuff, even more stuff);
 
 what does the qw do?

In your example, it's a broken way of trying to say:

$array[0] = stuff;
$array[1] = more stuff;
$array[2] = even more stuff;

I say broken because qw splits on whitespace, so what you really get
here is:

$array[0] = 'stuff;'
$array[1] = 'more';
$array[2] = 'stuff;'
$array[3] = 'even';
$array[4] = 'more';
$array[5] = 'stuff;';

qw is a shorthand way of initializing an array with individual words,
because it saves you the trouble of having to type all the quotes and
commas.  For example,

@array = qw(stuff more stuff even more stuff);

gives you

$array[0] = stuff;
$array[1] = more;
$array[2] = stuff;
$array[3] = even;
$array[4] = more;
$array[5] = stuff;

But if you need to initialize the array with strings that have
embedded whitespace, then you've got to do it the long way with all
the quotes and commas.  In your example, all you have to do is drop
the qw:

@array = (stuff, more stuff, even more stuff);

Walt

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: test for real number

2001-05-30 Thread Walt Mankowski

On Wed, May 30, 2001 at 01:56:40PM -0700, [EMAIL PROTECTED] wrote:
 How do I test an input to see if it is a real number?

$ perldoc -q float 

Found in /usr/local/lib/perl5/5.6.1/pod/perlfaq4.pod
 How do I determine whether a scalar is a
 number/whole/integer/float?

 Assuming that you don't care about IEEE notations like NaN
 or Infinity, you probably just want to use a regular
 expression.

if (/\D/){ print has nondigits\n }
if (/^\d+$/) { print is a whole number\n }
if (/^-?\d+$/)   { print is an integer\n }
if (/^[+-]?\d+$/){ print is a +/- integer\n }
if (/^-?\d+\.?\d*$/) { print is a real number\n }
if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { print is a decimal number }
if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
 { print a C float }

 If you're on a POSIX system, Perl's supports the
 POSIX::strtod function.  Its semantics are somewhat
 cumbersome, so here's a getnum wrapper function for more
 convenient access.  This function takes a string and returns
 the number it found, or undef for input that isn't a C
 float.  The is_numeric function is a front end to getnum
 if you just want to say, ``Is this a float?''

 sub getnum {
 use POSIX qw(strtod);
 my $str = shift;
 $str =~ s/^\s+//;
 $str =~ s/\s+$//;
 $! = 0;
 my($num, $unparsed) = strtod($str);
 if (($str eq '') || ($unparsed != 0) || $!) {
 return undef;
 } else {
 return $num;
 }
 }

 sub is_numeric { defined getnum($_[0]) }

 Or you could check out the String::Scanf module on CPAN
 instead.  The POSIX module (part of the standard Perl
 distribution) provides the strtod and strtol for
 converting strings to double and longs, respectively.


-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: How to delete an element in array?

2001-05-29 Thread Walt Mankowski

On Tue, May 29, 2001 at 11:59:18AM -0700, Randal L. Schwartz wrote:
  Brett == Brett W McCoy [EMAIL PROTECTED] writes:
 
  Uh, careful.  This got added to 5.6.1 to support pseudo-hashes and is
  probably coming back out when pseudo-hashes get removed in 5.10.
  (Death to pseudo-hashes!)
 
 Brett Argh.  I didn't realize that.  Is this specifically delete on array
 Brett elements?
 
 Yes.

Is there any difference in 5.6.1 between

delete $array[$index];

and

$array[$index] = undef;

There doesn't seem to be from the man page.  If there's not, it
doesn't seem to be a particularly useful feature.

Walt

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: Simple question

2001-05-29 Thread Walt Mankowski

On Tue, May 29, 2001 at 05:25:18PM -0400, [EMAIL PROTECTED] wrote:
 
 
 Hi All,
   I am working on the following output.
 
 * /ebppvobstore/vobs/Core /ebppvobstore/vobs/aci.vbs public
 * /ebppvobstore/vobs/UCMCQ /ebppvobstore/vobs/UCMCQ.vbs public (ucmvob)
   /ebppvobstore/vobs/Comp_Care /ebppvobstore/vobs/Comp_Care.vbs/ public
 
 I want to check for the asterisks and if found do something else do something. I
 am having a little trouble to make this work.
 This is the code
 
 use strict ;
 my @vobtags = `cleartool lsvob` ;
 my $vobs ;
 my @check ;
 foreach $vobs (@vobtags) {
 chomp $vobs ;
 @check = split /\s+/, $vobs ;
 chomp $check[0] ;
 if ($check[0] ne  ) {
 print $check[1] \n ;
 }
 else{
 print  The vob $check[1] is not mounted\n ;
 }
 }
 
 This is the output I am getting (obviously not what I want)
 dug # perl vobmount
 /ebppvobstore/vobs/Core
 /ebppvobstore/vobs/UCMCQ
 /ebppvobstore/vobs/Comp_Care
 
 
 I would appreciate if somebody can help me, point my blunder.

A few hints:

1.  Indent your code.

2.  When code isn't doing what you expect, a good first step is to
either run the code in the debugger or print out the variable that
doesn't contain what you think it does.  Here you're assuming that
$check[0] will be a space on lines that don't start with a *, but in
fact it's an empty string ().

Walt

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: Regexp - missing matches

2001-05-25 Thread Walt Mankowski

On Fri, May 25, 2001 at 11:43:21AM -0400, Craig Moynes/Markham/IBM wrote:
 I have the following regexp:
 
 @matches = $params{f} =~ /(%[aAbBcCdDehHIjmMnprStTuUVwWyY%])/g;
 
 If I have a script:
 
 [snip]
 my @matches;
 my ( %params );
 getopts('DRSa:f:s:d:r:b:w:n:h?', \%params);
 
 print $params{f}\n;
 print @matches\n;
 [snip]
 
 I am passing -f some string in on the command line.
 
 $params{f} = %E %e %d;
 output:
 %E %e %d
 %d
 
 So %e is not found
 
 $params{f} = %d %e;
 output:
 %d %e
 %e
 
 And now no %d.
 
 Any ideas why the first match is being lost ?

You must be doing something in the parts you snipped that effects
@matches.  I wrote the following code:

my @matches;
my ( %params );
$params{f} = %E %e %d;
@matches = $params{f} =~ /(%[aAbBcCdDehHIjmMnprStTuUVwWyY%])/g;
print $params{f}\n;
print @matches\n;

And my output was:

%E %e %d
%e %d

Looks fine to me...

Walt

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: How to touch a file for testing -C

2001-05-24 Thread Walt Mankowski

On Thu, May 24, 2001 at 11:00:19AM -0700, Mark Folse wrote:
 I was written a small application to check the date of the files to
 process, and sleep until the new days's files arrived. My problem was
 testing. Is there someway not in the man pages to touch a file so
 that the return from -C reflects the new file system date and time?

Why does it have to not be in the man pages?  :-)

$ perldoc -f utime
 utime LIST
 Changes the access and modification times on each
 file of a list of files.  The first two elements of
 the list must be the NUMERICAL access and
 modification times, in that order.  Returns the
 number of files successfully changed.  The inode
 change time of each file is set to the current time.
 This code has the same effect as the touch command
 if the files already exist:

 #!/usr/bin/perl
 $now = time;
 utime $now, $now, @ARGV;

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: script that runs all the time to monitor log file

2001-05-24 Thread Walt Mankowski

On Thu, May 24, 2001 at 02:37:18PM -0400, Craig Moynes/Markham/IBM wrote:
 
 This is a problem with tail that I have run into as well.
 
 If the file size gets reset the stored location of EOF remains the same
 which is a problem. As the file is written too the size is still below that
 of what tail is looking at.  You can add a stat check to watch filesize and
 reset the counter when the size is smaller than the previous one.
 
 I think there was another issue with using tail, hm.
 
 You can test it out on the command line though to ensure I have my brain in
 alignment.
 
 Ohh the other problem ...
 
 Your script will wait for more data from tail, and if the file size is
 reset it just sits there.  To solve this I created a controller process
 that spawns off the log reader and then the controller monitors the logfile
 size, if it drops below the last size it kills off the log reader process
 and respawns it.
 
 
 Any other solutions perl gods ?

There are several alternatives offered in perlfaq5 (search for 'How do
I do a tail -f in perl?'[1]).  Since the solutions there are variations 
on

loop forever
  reposition
  read to eof
  sleep a bit
end loop

they may (although I haven't tested it) get around the problems you
describe.

Walt

1.  Or, alternatively, perldoc -q tail.

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: handling flat-file layouts -- pack or sprintf or something else?

2001-05-24 Thread Walt Mankowski

On Thu, May 24, 2001 at 10:58:38PM -0400, Stephen P. Potter wrote:
 Lightning flashed, thunder crashed and chris brown [EMAIL PROTECTED] whispered:
 | I would prefer to write each record using pack, but I
 | can't see how to elegantly get pack to zero-fill
 | without using sprintf.  And I kind of feel like once
 | I'm using sprintf I might as well ONLY use sprintf for
 | the whole record.  And *that* doesn't feel very
 | Perlish to me, so I suspect there's a different
 | solution.
 
 Nope, pack works on bytes.  If you want to pad your output, you need to use
 something like sprintf.  See perlfunc:

What exactly feels unperlish about sprintf?  Perl is all about using
the right tool for the right job, and sprintf imho is the right tool
for zero-filling.

If you insist on doing it without sprintf, there are some alternatives
in perlfaq4.

Walt