- 论坛徽章:
- 7
|
:- #!/usr/bin/perl
- use 5.018;
- sub P {
- local $_ = join '', map { s/^\s+//; s/\s+$//; $_ } @_;
- s/<\?.*?\?>//; s/(?<=[^>])<\/\w+>/",/g;
- s/<\/\w+>/},/g; s/></",{"/g; s/>/","/g;
- s/</"/g; s/.*?{/{/; eval;
- }
- my %note = %{ P <DATA> };
- say $note{to};
- say $note{info}{info2}{tel};
- __DATA__
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <note>
- <to>George</to>
- <from>John</from>
- <heading>Reminder</heading>
- <body>Don't forget the meeting!</body>
- <info>
-
- <info1>lv1</info1>
- <info2>
- <tel>010888888</tel>
- <addr>
- beijing
-
- </addr>
-
- </info2>
- </info>
- <to2>Mary</to2>
- </note>
复制代码 hash结构:- { to2 => Mary, to => George, from => John, heading => Reminder, body => Don't forget the meeting!, info => { info1 => lv1, info2 => { addr => beijing, tel => 010888888 } } }
复制代码 |
|