LoginSignup
1
1

More than 5 years have passed since last update.

Perlのボイラープレート

Last updated at Posted at 2016-02-17

あまりperlを書かない自分のための備忘録

boiler.pl
#!/usr/bin/perl

use strict;
use Sys::Hostname;

my %time;
my %hostname;

&getTime(\%time);
&getHostname(\%hostname);

sub getTime (\%) {
  my $time = shift;
  my ($sec, $min, $hour, $day, $month, $year, $mday) = (localtime(time))[0,1,2,3,4,5,6];
  $$time{'year'}  = $year + 1900;
  $$time{'month'} = sprintf("%02d",$month + 1);
  $$time{'day'}   = sprintf("%02d",$day);
  $$time{'hour'}  = sprintf("%02d",$hour);
  $$time{'min'}   = sprintf("%02d",$min);
  $$time{'sec'}   = sprintf("%02d",$sec);
}

sub getHostname (\%) {
  my $hostname = $_[0];
  $$hostname{'fqdn'}  = hostname();
  $$hostname{'short'} = (split(/\./,$hostname{'fqdn'}))[0];
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1