- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl - best practises
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
Discussions
Discussions
Forums
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
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
тАО10-27-2003 10:22 PM
тАО10-27-2003 10:22 PM
Perl - best practises
After intending to get into Perl for a while a problem at work demanded its use and so I have begun to use it. At present I'm only writing some basic stuff so have a few basic questions..
In the shell version of my script I would have a line such as
echo "$(date): $(hostname) has a problem" >> outfile
I want to do the same thing in perl.. I have seen people doing this by making a system call or using `date`. However, I was hoping to keep to JUST perl. Is it acceptable to still use 'shell' commands within your perl script or is there a better way?
Cheers,
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-27-2003 10:31 PM
тАО10-27-2003 10:31 PM
Re: Perl - best practises
I love perl but it doesn't have a "lvdisplay -v vg00" command so I would quite happily use the shell to do that and so why not use the shell for more simple things too if it is actually easier. Having said that, extracting the date is very easy in perl and gives you individual variables that can be manipulated.
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
I remember when I started using perl that the temptation to just jump out to a shell for a quick "grep" was immense but it's not as flexible.
I would suggest, as a rule of thumb, do it with perl but if you know how to do it in shell and it has already taken half an hour to get it working in perl, use the shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-27-2003 10:56 PM
тАО10-27-2003 10:56 PM
Re: Perl - best practises
printf "%s: %s has a problem\n",strftime('%d-%m-%Y %H:%M',gmtime(time)),ENV['HOSTNAME']);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-27-2003 11:25 PM
тАО10-27-2003 11:25 PM
Re: Perl - best practises
my $now = locatime time;
2. Use modules for more advanced stuff (these are still pure perl (most of them), but offer a perl-style interface, and are mostly portable)
use Sys::Hostname;
use Time::gmtime;
use Time::HiRes;
use Time::Local;
use Time::localtime;
use Time::tm;
Using POSIX' strftime is easy, but slow.
There are modules for HP-UX specific environment, ALSO FOR LVM :)
ftp://download.xs4all.nl/pub/mirror/CPAN/modules/by-module/HPUX/HPUX-LVM_0.06.tar.gz
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-28-2003 01:21 AM
тАО10-28-2003 01:21 AM
Re: Perl - best practises
Just to show some flexibility.
--------------------------
$time_text = localtime(time);
print $time_text, "\n"; # outputs whatever date/time it is
---------------------
time() will give "seconds since the epoch"
$today = time();
$tomorrow_at_this_time = time() + (24 * 60 * 60);
in case of date calculations
---------------------
Finally the statement
echo "$(date): $(hostname) has a problem" >> outfile
transaltes in perl as
open OUTFILE,"filename";
print OUTFILE "$time_text:$(hostname) has a problem"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-28-2003 01:48 AM
тАО10-28-2003 01:48 AM
Re: Perl - best practises
use Sys::Hostname
open OUTFILE, ">> outfile" or die "outfile: $!";
print OUTFILE scalar localtime, ": ", hostname, " has a problem\n";
close OUTFILE;
Enjoy, have FUN! H.Merijn