Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use Data::Dump qq(pp);
- package Chiebukuro;
- sub new {
- return bless {};
- }
- sub get_info_json {
- my ($self, $id1, $id2, $mode) = @_;
- return {
- data => [
- {
- name => 'name_test',
- info1 => [
- {
- data1 => 'info1_data_01',
- data2 => 'info1_data_02'
- },
- {
- data1 => 'info1_data_11',
- data2 => 'info1_data_12'
- }
- ],
- info2 => [
- {
- data1 => 'info2_data_01',
- data2 => 'info2_data_02'
- },
- {
- data1 => 'info2_data_11',
- data2 => 'info2_data_12'
- },
- {
- data1 => 'info2_data_21',
- data2 => 'info2_data_22'
- }
- ]
- }
- ]
- };
- }
- sub getData {
- my ($self, $dataref, $id) = @_;
- my $json = $self->get_info_json('dummy', 'dummy', 0);
- my $key = $json->{data}->[0];
- $dataref->{$id}->{name} = $key->{name};
- for my $key2 (@{$key->{info1}}) {
- $dataref->{$id}->{data1} = $key2->{data1};
- $dataref->{$id}->{data2} = $key2->{data2};
- }
- for my $key2 (@{$key->{info2}}) {
- $dataref->{$id}->{data3} = $key2->{data1};
- $dataref->{$id}->{data4} = $key2->{data2};
- }
- return $dataref;
- }
- package main;
- my $c = Chiebukuro->new;
- pp $c->getData({}, 'ID');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement