Skip to content

Instantly share code, notes, and snippets.

@note103
Created October 31, 2013 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save note103/7253611 to your computer and use it in GitHub Desktop.
Save note103/7253611 to your computer and use it in GitHub Desktop.
Perl入学式in東京vol.3の復習問題「score.pl」より 第5問『JSON風Dumper』。
#!/usr/bin/env perl
use strict;
use warnings;
my $papix = {
name => 'papix',
affiliation => 'namba.pm',
perl => 60,
python => 50,
ruby => 50,
php => 80,
binary => 30,
sum => 270,
};
my $boolfool = {
name => 'boolfool',
affiliation => 'namba.pm',
perl => 40,
python => 10,
ruby => 20,
php => 30,
binary => 10,
sum => 110,
};
my $moznion = {
name => 'moznion',
affiliation => 'hachioji.pm',
perl => 100,
python => 70,
ruby => 80,
php => 50,
binary => 50,
sum => 350,
};
my $binarian = {
name => 'binarian',
affiliation => 'hachioji.pm',
perl => 10,
python => 11,
ruby => 1,
php => 100,
binary => 100,
};
my $uzulla = {
name => 'uzulla',
affiliation => 'hachioji.pm',
perl => 1,
python => 0.01,
ruby => 0.5,
php => 4,
binary => 0.01,
};
#ここから回答。
my @people = ($papix, $boolfool, $moznion, $binarian, $uzulla);
print "[\n";
for my $people (@people) {
print " {\n ";
for my $key (keys $people) {
print " \"$key\":$people->{$key}\n ";
}
print "} \n";
}
print "]\n";
@note103
Copy link
Author

note103 commented Oct 31, 2013

実行結果:

[
  {
    "python":50
    "binary":30
    "name":papix
    "ruby":50
    "perl":60
    "php":80
    "affiliation":namba.pm
    "sum":270
  }
  {
    "python":10
    "binary":10
    "name":boolfool
    "ruby":20
    "perl":40
    "php":30
    "affiliation":namba.pm
    "sum":110
  }
  {
    "python":70
    "binary":50
    "name":moznion
    "ruby":80
    "perl":100
    "php":50
    "affiliation":hachioji.pm
    "sum":350
  }
  {
    "php":100
    "perl":10
    "python":11
    "binary":100
    "name":binarian
    "ruby":1
    "affiliation":hachioji.pm
  }
  {
    "php":4
    "perl":1
    "python":0.01
    "binary":0.01
    "name":uzulla
    "ruby":0.5
    "affiliation":hachioji.pm
  }
]

@note103
Copy link
Author

note103 commented Oct 31, 2013

設問:URL

[
  {
    "python":10
    "binary":0
    "name":boolfool
    "ruby":20
    "perl":40
    "php":0
    "affiliation":namba.pm
    "sum":70
  }
  {
    "python":50
    "binary":0
    "name":papix
    "ruby":50
    "perl":60
    "php":0
    "affiliation":namba.pm
    "sum":160
  }
]
  • どんな方法でもよいので上記のような JSON 風 Dumper を作成して下さい

@note103
Copy link
Author

note103 commented Oct 31, 2013

関連URL:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment