FireBall
asked on
Perl for loop for 2000 ms
We need a for loop which cancel after two seconds sth. like that
$time = startup + 2000 ;
while (1)
{
some rules to do
if (time< now){ go to git;
}
git :
$time = startup + 2000 ;
while (1)
{
some rules to do
if (time< now){ go to git;
}
git :
sleep(2)
ASKER
we do not want to let it sleep for 2 seconds we want to let it work for 2000ms
$time = 2+time;
while( time<$time ){
}
while( time<$time ){
}
ASKER
we are looking for in ms format seconds should be disgusting in some conditions
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
we tryed that given code below but sometimes it never reaches to +1000ms and goes on working :S
use Time::HiRes qw/gettimeofday/;
my $seconds = gettimeofday(); #in scalar context it returns a fractional number of seconds
my $ms = int($seconds*1000); #convert into milliseconds
($seconds, my $fraction) = gettimeofday();
$ms = $fraction + $seconds * 1000 + 1000 ; #convert into milliseconds
while(1){
my $seconds2 = gettimeofday(); #in scalar context it returns a fractional number of seconds
my $ms2 = int($seconds2*1000); #convert into milliseconds
($seconds2, my $fraction2) = gettimeofday();
$ms2 = $fraction2 + $seconds2 * 1000 ; #convert into milliseconds
print $ms2."-".$ms."\n";
if( ($ms < $ms2) > 2 ){
goto ATLA;
}
}
}
ATLA :
1433297085562-1433296948616
1433297085573-1433296948616
1433297085582-1433296948616
1433297085592-1433296948616
1433297085602-1433296948616
1433297085612-1433296948616
1433297085622-1433296948616
1433297085632-1433296948616
1433297085642-1433296948616
1433297085652-1433296948616
1433297085672-1433296948616
1433297085683-1433296948616
1433297085693-1433296948616
1433297085703-1433296948616
1433297085713-1433296948616
1433297085723-1433296948616
1433297085733-1433296948616
1433297085743-1433296948616
1433297085753-1433296948616
1433297085765-1433296948616
1433297085777-1433296948616
1433297085793-1433296948616
1433297085805-1433296948616
1433297085815-1433296948616
1433297085825-1433296948616
1433297085835-1433296948616
1433297085847-1433296948616
1433297085857-1433296948616
1433297085867-1433296948616
1433297085877-1433296948616
1433297085887-1433296948616
1433297085897-1433296948616
1433297085909-1433296948616
1433297085919-1433296948616
1433297085929-1433296948616
1433297085939-1433296948616
1433297085949-1433296948616
1433297085959-1433296948616
1433297085969-1433296948616
1433297085979-1433296948616
1433297085989-1433296948616
1433297086002-1433296948616
1433297086013-1433296948616
1433297086023-1433296948616
1433297086032-1433296948616
1433297086042-1433296948616
1433297086052-1433296948616
1433297086062-1433296948616
1433297086072-1433296948616
1433297086082-1433296948616
1433297086094-1433296948616
1433297086104-1433296948616
1433297086114-1433296948616
1433297086124-1433296948616
1433297086134-1433296948616
1433297086144-1433296948616
1433297086154-1433296948616
1433297086165-1433296948616
1433297086175-1433296948616
1433297086186-1433296948616
1433297086195-1433296948616
1433297086205-1433296948616
1433297086217-1433296948616
1433297086227-1433296948616
1433297086237-1433296948616
1433297086247-1433296948616
1433297086257-1433296948616
1433297086267-1433296948616
1433297086277-1433296948616
1433297086287-1433296948616
1433297086297-1433296948616
1433297086307-1433296948616
1433297086320-1433296948616
1433297086330-1433296948616
1433297086340-1433296948616
1433297086350-1433296948616
1433297086361-1433296948616
1433297086380-1433296948616
1433297086399-1433296948616
1433297086410-1433296948616
1433297086422-1433296948616
1433297086432-1433296948616
1433297086442-1433296948616
1433297086454-1433296948616
1433297086464-1433296948616
1433297086474-1433296948616
1433297086485-1433296948616
1433297086495-1433296948616
1433297086506-1433296948616
1433297086516-1433296948616
1433297086527-1433296948616
1433297086537-1433296948616
1433297086547-1433296948616
1433297086557-1433296948616
1433297086567-1433296948616
1433297086577-1433296948616
1433297086587-1433296948616
1433297086597-1433296948616
1433297086607-1433296948616
1433297086617-1433296948616
1433297086627-1433296948616
1433297086637-1433296948616
1433297086648-1433296948616
1433297086659-1433296948616
1433297086671-1433296948616
1433297086681-1433296948616
1433297086691-1433296948616
1433297157952-1433296948616
1433297157966-1433296948616
1433297157977-1433296948616
1433297157987-1433296948616
1433297158002-1433296948616
1433297158012-1433296948616
1433297158022-1433296948616
1433297158032-1433296948616
1433297158042-1433296948616
1433297158059-1433296948616
1433297158075-1433296948616
1433297158086-1433296948616
1433297158098-1433296948616
1433297158108-1433296948616
1433297158118-1433296948616
1433297158128-1433296948616
1433297158142-1433296948616
1433297158153-1433296948616
1433297158369-1433296948616
1433297158381-1433296948616
1433297158391-1433296948616
1433297158401-1433296948616
1433297158411-1433296948616
1433297158421-1433296948616
1433297158431-1433296948616
1433297158441-1433296948616
1433297158451-1433296948616
1433297158463-1433296948616
1433297158474-1433296948616
1433297158484-1433296948616
1433297158494-1433296948616
1433297158504-1433296948616
1433297158514-1433296948616
1433297158524-1433296948616
1433297158536-1433296948616
1433297158546-1433296948616
1433297158556-1433296948616
1433297158567-1433296948616
1433297158577-1433296948616
1433297158588-1433296948616
1433297158599-1433296948616
1433297158609-1433296948616
1433297158620-1433296948616
1433297158631-1433296948616
1433297158641-1433296948616
1433297158650-1433296948616
1433297158660-1433296948616
1433297158670-1433296948616
1433297158680-1433296948616
1433297158690-1433296948616
1433297158700-1433296948616
1433297158710-1433296948616
1433297158720-1433296948616
1433297158730-1433296948616
1433297158740-1433296948616
1433297158750-1433296948616
1433297158760-1433296948616
1433297158771-1433296948616
1433297158781-1433296948616
1433297158800-1433296948616
1433297158814-1433296948616
1433297158825-1433296948616
1433297158837-1433296948616
1433297158847-1433296948616
1433297158859-1433296948616
1433297158869-1433296948616
1433297158879-1433296948616
1433297158890-1433296948616
1433297158900-1433296948616
1433297158910-1433296948616
1433297158920-1433296948616
1433297158930-1433296948616
1433297158940-1433296948616
1433297158951-1433296948616
1433297158961-1433296948616
1433297158972-1433296948616
1433297158981-1433296948616
1433297158991-1433296948616
1433297159001-1433296948616
1433297159011-1433296948616
1433297159021-1433296948616
1433297159033-1433296948616
1433297159043-1433296948616
1433297159053-1433296948616
1433297159072-1433296948616
1433297159086-1433296948616
1433297159096-1433296948616
1433297159106-1433296948616
1433297159118-1433296948616
1433297159128-1433296948616
1433297159139-1433296948616
1433297159149-1433296948616
1433297159159-1433296948616
1433297159169-1433296948616
1433297159181-1433296948616
1433297159191-1433296948616
1433297159201-1433296948616
1433297159211-1433296948616
1433297159221-1433296948616
1433297159231-1433296948616
1433297159241-1433296948616
1433297159251-1433296948616
1433297159261-1433296948616
1433297159273-1433296948616
1433297159285-1433296948616
1433297159295-1433296948616
1433297159305-1433296948616
1433297159317-1433296948616
1433297159327-1433296948616
1433297159337-1433296948616
1433297159347-1433296948616
1433297159357-1433296948616
1433297159367-1433296948616
1433297159377-1433296948616
1433297159387-1433296948616
1433297159397-1433296948616
1433297159407-1433296948616
1433297159417-1433296948616
1433297159427-1433296948616
1433297159444-1433296948616
1433297159454-1433296948616
1433297159464-1433296948616
1433297159474-1433296948616
1433297159485-1433296948616
1433297159496-1433296948616
1433297159508-1433296948616
1433297159518-1433296948616
1433297159528-1433296948616
1433297159538-1433296948616
1433297159557-1433296948616
1433297159567-1433296948616
1433297159577-1433296948616
1433297159586-1433296948616
1433297159596-1433296948616
1433297159605-1433296948616
1433297159617-1433296948616
1433297159627-1433296948616
1433297159636-1433296948616
1433297159646-1433296948616
1433297159656-1433296948616
1433297159675-1433296948616
1433297159685-1433296948616
1433297159704-1433296948616
1433297159714-1433296948616
1433297159878-1433296948616
1433297159897-1433296948616
1433297159908-1433296948616
1433297159918-1433296948616
1433297159928-1433296948616
1433297159938-1433296948616
1433297159949-1433296948616
1433297159959-1433296948616
1433297159969-1433296948616
1433297159986-1433296948616
1433297160000-1433296948616
1433297160013-1433296948616
1433297160024-1433296948616
1433297160033-1433296948616
1433297160043-1433296948616
1433297160053-1433296948616
1433297160062-1433296948616
1433297160079-1433296948616
1433297160092-1433296948616
1433297160103-1433296948616
1433297160112-1433296948616
1433297160122-1433296948616
1433297160135-1433296948616
1433297160145-1433296948616
1433297160155-1433296948616
1433297160164-1433296948616
1433297160174-1433296948616
1433297160184-1433296948616
1433297160194-1433296948616
1433297160203-1433296948616
1433297160213-1433296948616
1433297160223-1433296948616
1433297160232-1433296948616
1433297160242-1433296948616
1433297160251-1433296948616
1433297160261-1433296948616
1433297160271-1433296948616
1433297160282-1433296948616
1433297160292-1433296948616
1433297160302-1433296948616
1433297160311-1433296948616
1433297160323-1433296948616
1433297160333-1433296948616
1433297160344-1433296948616
1433297160354-1433296948616
1433297160364-1433296948616
1433297160374-1433296948616
1433297160383-1433296948616
1433297160393-1433296948616
1433297160403-1433296948616
1433297160412-1433296948616
1433297160422-1433296948616
1433297160432-1433296948616
1433297160443-1433296948616
1433297160455-1433296948616
1433297160465-1433296948616
1433297160475-1433296948616
1433297160485-1433296948616
1433297160494-1433296948616
1433297160504-1433296948616
1433297160514-1433296948616
1433297160523-1433296948616
1433297160533-1433296948616
1433297160543-1433296948616
1433297160554-1433296948616
1433297160564-1433296948616
1433297160574-1433296948616
1433297160583-1433296948616
1433297160594-1433296948616
1433297160604-1433296948616
1433297160614-1433296948616
1433297160625-1433296948616
1433297160636-1433296948616
1433297160645-1433296948616
1433297160655-1433296948616
1433297160665-1433296948616
1433297160675-1433296948616
1433297160684-1433296948616
1433297160694-1433296948616
1433297160704-1433296948616
1433297160713-1433296948616
1433297160723-1433296948616
1433297160733-1433296948616
1433297160743-1433296948616
1433297160754-1433296948616
1433297160765-1433296948616
1433297160775-1433296948616
ASKER
thank you i have resolved.
I have one more awk question please check it out
I have one more awk question please check it out