Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SandBox
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
PotatoGim
SandBox
Commits
525f59e1
Commit
525f59e1
authored
Mar 03, 2015
by
PotatoGim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Perl 연관 배열을 이용한 설정 관리 일부 코드 추가
parent
c39204ed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
134 additions
and
0 deletions
+134
-0
configurator.pl
perl/configurator.pl
+134
-0
No files found.
perl/configurator.pl
0 → 100644
View file @
525f59e1
#!/usr/bin/perl
#=============================================================================
# FILE: configurator.pl
# USAGE: ./configurator.pl
# BRIEF:
# OPTIONS: ---
# AUTHOR: Ji-Hyeon Gim <potatogim@gluesys.com>
# ORGANIZATION: Network Storage Team
# DATE: 03/03/2015 05:15:06 PM
# VERSION: 1.0
# LICENSE: BSD 3-Clause License
# NOTE: ----
#=============================================================================
use
strict
;
use
warnings
;
use
utf8
;
sub
set_config
{
my
$self
=
shift
;
my
%
args
=
@_
;
if
(
!
defined
(
$args
{
key
})
||
!
length
(
$args
{
key
}))
{
warn
"[ERR] Invalid parameter: key"
;
return
-
1
;
}
my
$table
=
$self
->
table
;
for
(
my
@q
=
({
path
=>
""
,
val
=>
\
$table
})
;
@q
;
)
{
my
$node
=
shift
(
@q
);
if
(
$node
->
{
path
}
eq
$args
{
key
})
{
$
{
$node
->
{
val
}}
=
$args
{
value
};
last
;
}
elsif
(
ref
(
$
{
$node
->
{
val
}})
eq
"HASH"
)
{
push
(
@q
,
map
{
{
path
=>
length
(
$node
->
{
path
})
?
$node
->
{
path
}
.
"."
.
$_
:
$_
,
val
=>
\
$
{
$node
->
{
val
}}
->
{
$_
},
};
}
keys
(
%
{
$
{
$node
->
{
val
}}}));
}
}
return
0
;
}
sub
get_config
{
my
$self
=
shift
;
my
%
args
=
@_
;
if
(
!
defined
(
$args
{
key
})
||
!
length
(
$args
{
key
}))
{
warn
"[ERR] Invalid parameter: key"
;
return
undef
;
}
my
$table
=
$self
->
table
;
my
$value
=
undef
;
for
(
my
@q
=
({
path
=>
""
,
val
=>
$table
})
;
@q
;
)
{
my
$node
=
shift
(
@q
);
if
(
$node
->
{
path
}
eq
$args
{
key
})
{
$value
=
$node
->
{
val
};
last
;
}
elsif
(
ref
(
$node
->
{
val
})
eq
"HASH"
)
{
push
(
@q
,
map
{
{
path
=>
length
(
$node
->
{
path
})
?
$node
->
{
path
}
.
"."
.
$_
:
$_
,
val
=>
$node
->
{
val
}
->
{
$_
},
};
}
keys
(
%
{
$node
->
{
val
}}));
}
}
return
$value
;
}
1
;
__END__
=encoding utf8
=head1 NAME
configurator.pl
=head1 SYNOPSIS
=head1 DESCRIPTION
=over
=item B<Item 1>
=item B<Item 2>
=item B<Item 3>
=back
=head1 AUTHOR
Ji-Hyeon Gim <potatogim@gluesys.com>
=head1 CONTRIBUTORS
=head1 COPYRIGHT AND LICENSE
=head1 SEE ALSO
=cut
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment