How to implement "sleep" in Perl ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to implement "sleep" in Perl ?
# 1  
Old 01-27-2012
Question How to implement "sleep" in Perl ?

I tried,
Code:
#!/usr/bin/perl
print "check 1";
print "check 2";
sleep(5);

The above works fine but sleep takes the higest priority. Looks weird

In above program "sleep" executes first and then "print" comes next. I would like the program to be executed in "sequence" , Print at first and then sleep ( Well that is how it should be Smilie)

Thanks in advance

Last edited by Franklin52; 01-28-2012 at 04:22 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-27-2012
Code:
#!/usr/bin/perl
print "check 1";
print "check 2\n";
sleep 5;

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 01-27-2012
Hi Bala,

It worked. I wander, \n is for new line. How does that make difference in the program ? .

If I have to implement many sleep function in a very huge program/script, do I have to add "\n" for print statement befor every sleep function. Well, what should I do if there is no print statement before sleep.

Thanks,

Last edited by frintocf; 01-27-2012 at 01:46 AM..
# 4  
Old 01-27-2012
Code:
#!/usr/bin/perl
$|++; #set STDOUT unbuffered; use with caution
print "check 1";
print "check 2";
sleep 5;

This User Gave Thanks to frank_rizzo For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Solaris

Do Linux "Sleep Mode" Problems Happen on UNIX?

I am an experienced MS Windows user who has tried four different flavors of Linux: Mandriva, Centos, Debian, and Ubantu---each on a different PC. (I always used a dual-boot configuration with Grub and Win XP or Win 7). Each time, I encountered the following two problems: While resuming from... (2 Replies)
Discussion started by: mjdz
2 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

How to implement "not in" logic in UNIX script?

Hi Gurus, I need use "not in " logic in my script, like below if $name not in exception_file_list, then do something. anyone can help out this? Thanks in advance. (5 Replies)
Discussion started by: ken6503
5 Replies

6. Shell Programming and Scripting

How to implement the logical express --- A(B+C) within single "if" statment in shell script?

On Linux OS, bash environment, I want implement the following code: if && ( || ) A,B,C represents some compare conditions. How to realize it ? Thanks! (1 Reply)
Discussion started by: qcmao
1 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

question about "sleep" command in expect script

I wrote some expect script to telnet to some device to execute some commands.Firstly,I can't get full result some time,then I try to add some "sleep" command in it.Fortunately it works. My idea about it is that it uses sleep command to wait the result to be displayed.Am I right or correct the... (4 Replies)
Discussion started by: robbiezr
4 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question