Skip to content

Instantly share code, notes, and snippets.

@sioncojp
Created May 27, 2014 02:29
Show Gist options
  • Save sioncojp/defb5b77c7ba26a2716b to your computer and use it in GitHub Desktop.
Save sioncojp/defb5b77c7ba26a2716b to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Cache::Memcached::Fast;
my (@even, @odd, $str, $ii, $i, @data, $key, $value, $exptime, $file, $memd);
### ファイル名を指定してください
$file = "/tmp/11211.dump";
### memcacheのデータ保持時間を指定してください
$exptime = "86400";
### connect Memcached
$memd = Cache::Memcached::Fast->new({
servers => [{address => 'localhost:11211'}],
utf8 => ($^V ge v5.8.1 ? 1 : 0),
});
open(FILE, $file) or die("Error!!");
@data = <FILE>;
&add(@data);
close(FILE);
sub add {
$i=0;
$ii=0;
### 偶数行。中身にkeyとexptimeを含むので2次元配列にする。
@even = grep ++$i % 2, @_;
@even = map { [split /\s+/] } @even;
### 奇数行。mapで改行を外している。
@odd = grep $i++ % 2, @_;
@odd = map { [split /\n/] } @odd;
foreach (@odd){
### 主要の値格納
$key = $even[$ii][1];
$exptime = $even[$ii][3];
$value = $odd[$ii][0];
$memd->set($key, $value, $exptime);
$ii++
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment