目次

内容

クエリーストリングの解釈

use strict;
use URI;

my $url = "http://www.a.com/page?param=value";
$url =~ s/&/&/go;
my $uri = URI->new( $url );
my %paramList = $uri->query_form;
print Dumper( \%paramList );

四捨五入

use strict;
use warnings;
use Math::Round;

my $int = 5.668131223;
print nearest( .01, $int ). "\n";

CSVのパース

CSVの出力

日付の配列

use strict;
use warnings;
use Date::Calc( "Delta_Days", "Add_Delta_Days" );
use Data::Dumper;

my $startDate = "2008-12-22";
my $endDate   = "2008-12-28";

my @days = getDays( $startDate, $endDate );
print Dumper( \@days );


sub getDays {
    my $startDate = shift;
    my $endDate   = shift;
    my $daysDiff = Delta_Days( split( "-", $startDate ), split( "-", $endDate ) );
    my @result;
    for( 0 .. $daysDiff ){
        push( @result, sprintf( "%04d-%02d-%02d", Add_Delta_Days( split( "-", $startDate ), $_ ) ) );
    }
    return @result;
}

IPアドレスのチェック

use NetAddr::IP::Lite;
use strict;
use warnings;

#my $check_ip = "192.168.1.1";
my $check_ip = "150.70.1.1";

my @ignore_list = ( "150.70.0.0/16", "216.104.0.0/19" );

my $ip = NetAddr::IP::Lite->new( $check_ip );

foreach ( @ignore_list ){
    if ( $ip->within( NetAddr::IP::Lite->new($_) ) ) {
        print "$check_ip is in $_\n";
    } else {
        print "$check_ip is NOT in $_\n";
    }
}

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-09-25 (日) 19:27:03 (442d)