Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- department=value1
- location=valueA
- location=valueB
- department=value2
- use File::Slurp;
- use Data::Dumper;
- my %hash = map {
- s/#.*//;
- s/^s+//;
- s/s+$//;
- m/(.*?)s*=s*(.*)/;
- } read_file($file);
- print Dumper(%hash);
- $VAR1 = {
- 'location' => 'valueB',
- 'department' => 'value2'
- };
- $VAR1 = {
- 'location' => 'valueA,valueB',
- 'department' => 'value1,value2'
- };
- my %hash;
- while (<FILE>)
- {
- chomp;
- my ($key, $val) = split /=/;
- $hash{$key} .= exists $hash{$key} ? ",$val" : $val;
- }
- name: Wally Jones
- department: [foo, bar]
- location: [baz, biff]
- use File::Slurp;
- use YAML::XS;
- use Data::Dumper;
- print Dumper Load scalar read_file(shift);
- $VAR1 = {
- 'department' => [
- 'foo',
- 'bar'
- ],
- 'location' => [
- 'baz',
- 'biff'
- ],
- 'name' => 'Wally Jones'
- };
Add Comment
Please, Sign In to add comment