Please bottom post....

> Use the following:
> 
> $option = "0" . $option if ($option / 10 < 1 && $option !~ /^0/);
> 

Why divide by 10 first? Why not just check less than 10?  Of course I
would probably drop the maths completely and use C<sprintf>,

perldoc -f sprintf

$option = sprintf('%02d', $option);

Of course I am assuming there has also been,

unless ($option =~ /^\d{2}$/ and $option <= 31) {
   die "I said a date you wacko";
}

And I won't even go into the point that some months only have 28, 29, or
30 days (damn leap years).

http://danconia.org

> ~Sid
> 
> On Thu, 9 Sep 2004 08:58:36 -0500, Errin Larsen
<[EMAIL PROTECTED]> wrote:
> > Hi All,
> > 
> > I have a variable I'm reading off of the command line:
> > 
> > my $option = shift;
> > 
> > That variable should hold a number between 1 and 31 (yes, a day of the
> > month)  I am checking to make sure that the number does indeed lie in
> > that range.
> > 
> > However, I need to pass that variable to another system command which
> > expects any "day" value less than 10 to have a leading zero, so 7th
> > day of the month should say '07'.  How can I check for that leading
> > zero?  If it's missing, I know I could easily:
> > 
> > $option = "0".$option;
> > 
> > But I can't seem to figure out an easy, clean way to check for it.
> > 
> > --Thanks,
> > 
> > --Errin
> > 
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > <http://learn.perl.org/> <http://learn.perl.org/first-response>
> > 
> > 
> 
> 
> 
> -- 
> http://www.upster.blogspot.com
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to