Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting rid of the first 0 digit when counting

Status
Not open for further replies.

perlnewbie9292

Programmer
Jul 15, 2009
25
0
0
US
Hello everyone,

I am pretty new to Perl and hoping someone can please point me in the right direction. I am trying to do stuff based on timestamp from the hour field.

I am doing something like this:

Code:
if ( $hour = 2..9 )
{
    DOING STUFF HERE
}

If there anyway to either only show single digits for hours 00-09 or when running a range to be able to specify or be count ignoring the first 0 in the 00..09. Not sure if that make sense to everyone :).

So what I am trying to do is:
$hour = 2..9 instead of this:
$hour = 02..09

I guess I could do a substitution to get rid of the first 0 if it starts with a 0 digit but hoping there is cleaner/better way to do this.

I am using my $hourOfTheDay = strftime( '%H', localtime );
to get the hour digits.

Thanks for the help in advance.
 
Sorry used the wrong example meant:

Code:
if ( $hour = 2..12 )
{
    DOING STUFF HERE
}
 
Not sure to understand what you want to do with
[tt]if ( $hour = 2..12 )[/tt]
perhaps this
[tt]if($hour>=2 && $hour<=12)[/tt]
and it doesn't matter if [tt]$hour[/tt] had a trailing 0, perl correctly interprets it as a number in numerical operations and comparisons.

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
You can also do this to remove the leading zero:

$hour=(1*$hour);

But as prex1 says, why bother?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top