- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl quries - Newbie
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2010 10:16 PM
01-12-2010 10:16 PM
How to print out the hour, min and sec of time before and after sleep?
I tried the following but the output is the same:
#!/usr/bin/perl
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime time;
my $string="$hour$min$sec";
print "It is now $string\n";
sleep 15;
my $string_1="$hour$min$sec";
print "It is now $string_1\n";
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2010 10:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2010 10:49 PM
01-12-2010 10:49 PM
Re: Perl quries - Newbie
As Dennis noted, you never called 'localtime' a second time.
There are a number of ways to shorten and make your script more efficient.
Close to your original would be:
#!/usr/bin/perl
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime time;
printf "It is now %02d:%02d:%02d\n",$hour,$min,$sec;
sleep 15;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime time;
printf "It is now %02d:%02d:%02d\n",$hour,$min,$sec;
A more Perl-ish approach would be:
#!/usr/bin/perl
printf "It is now %02d:%02d:%02d\n", (localtime(time)) [2,1,0];
sleep 15;
printf "It is now %02d:%02d:%02d\n", (localtime(time)) [2,1,0];
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2010 11:46 PM
01-12-2010 11:46 PM
Re: Perl quries - Newbie
$ perl -MPOSIX=strftime -le 'print strftime("%T",localtime);sleep 15;print strftime("%T",localtime)'
08:42:25
08:42:40
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2010 12:40 AM
01-13-2010 12:40 AM
Re: Perl quries - Newbie
If I want to assign to $string, how to go about it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2010 02:28 AM
01-13-2010 02:28 AM
Re: Perl quries - Newbie
>
>If I want to assign to $string, how to go about it?
$time = join ':', (localtime)[2,1,0];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2010 02:49 AM
01-13-2010 02:49 AM
Re: Perl quries - Newbie
> If I want to assign to $string, how to go about it?
Yet another way:
#!/usr/bin/perl
my $string1 = sprintf "It is now %02d:%02d:%02d", (localtime(time)) [2,1,0];
sleep 15;
my $string2 = sprintf "It is now %02d:%02d:%02d", (localtime(time)) [2,1,0];
print "$string1\n$string2\n";
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2010 07:32 PM
01-13-2010 07:32 PM
Re: Perl quries - Newbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2010 02:12 AM
01-14-2010 02:12 AM
Re: Perl quries - Newbie
> Thank you very much. Is there an URL where I can learn and raise my competent level for perl?
The Perl community is a vast one. You might begin by following some of the links here:
http://www.perl.org/docs.html
In my opinion, the O'Reilly stable of books on Perl is the best supplement too.
By the way, if you are happy with the answers you have received, please read:
http://forums13.itrc.hp.com/service/forums/helptips.do?#28
Regards!
...JRF...