Minimal example exhibiting a double reference autovivification trick (learnt from Brian McCauley in a clpmisc thread) to convert a list of structured strings as that below the __END__ token to a complex data structure as that illustrated by the output of the program. More details follow.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %dirhash; while (<DATA>) { chomp; my $last=\\%dirhash; $last=\$$last->{$_} for split qr|/|; } print Dumper \%dirhash; __END__ /file.txt /a/file.txt /a/b/c /a/b/c/file.txt /z/m/w/file.txt
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Autovivification trick
by blazar (Canon) on Aug 12, 2006 at 10:56 UTC | |
by bobf (Monsignor) on Aug 13, 2006 at 00:11 UTC | |
Re: Autovivification trick
by polettix (Vicar) on Aug 12, 2006 at 19:14 UTC | |
by blazar (Canon) on Aug 12, 2006 at 19:47 UTC | |
Re: Autovivification trick
by planetscape (Chancellor) on Aug 13, 2006 at 22:06 UTC | |
Re: Autovivification trick
by ikegami (Patriarch) on Aug 13, 2006 at 22:52 UTC | |
Re: Autovivification trick (old)
by tye (Sage) on Aug 15, 2006 at 05:23 UTC | |
by blazar (Canon) on Aug 15, 2006 at 09:45 UTC |
Back to
Cool Uses for Perl