Created
October 29, 2012 16:16
-
-
Save patch/3974568 to your computer and use it in GitHub Desktop.
parse key/string pairs in xmlish markup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Data::Dump qw( dump ); | |
# slurp in filehandle as one string | |
my $input = do { local $/; <DATA> }; | |
my %data; | |
# parse out key/string pairs into hash | |
$data{ $+{key} } = $+{string} while $input =~ m{ | |
<key> (?<key> .+? ) </key> \s* | |
<string> (?<string> .*? ) </string> | |
}xg; | |
dump(\%data); | |
__DATA__ | |
<key>_name</key> | |
<string>Fibre Channel Domain 0</string> | |
<key>spfibrechannel_addressidentifier</key> | |
<string>04:0B:00</string> | |
<key>spfibrechannel_bus</key> | |
<string>spfibrechannel_pci_device</string> | |
<key>spfibrechannel_cablingtype</key> | |
<string>Fiber Optic</string> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment