Hey all,<br><br>Not sure if anyone here uses Freemind [<a href="http://freemind.sourceforge.net/wiki/index.php/Main_Page">http://freemind.sourceforge.net/wiki/index.php/Main_Page</a>], but I use it quite a bit for brainstorming and as an outliner.<br>
<br>One of the better uses of it for me is to hammer an idea for a perl hash tree very quickly. The problem is that once I have the hash tree exactly the way I want it in Freemind, I have to manually re-create the hash tree in perl source, with all the required formatting.<br>
<br>This is no longer the case, as I've written a quick and dirty "freemind2perl" script (below) which takes a Freemind mindmap file, and converts it into a perl hash tree automagically. Not sure it will work with all versions of Freemind, but their mindmap files are XML based, and they haven't really changed it across versions.<br>
<br>Just run this script with 'freemind2perl.pl <a href="http://file.mm">file.mm</a>'. It requires the "XML::Simple" perl module to be installed.<br><br>Again, not sure if anyone here uses Freemind, but I figured I'd share.<br>
<br>#--------------------------------------------------------------------------------<br>#!/usr/bin/perl -w<br><br>use strict;<br><br>use XML::Simple;<br>use Data::Dumper;<br><br>my $xml = new XML::Simple;<br>my $mm_file = shift;<br>
my $data = $xml->XMLin("$mm_file");<br>my $clean;<br><br>sub prep_clean<br>{<br> my $data = shift;<br> my $clean;<br><br> foreach my $key ( keys %{ $data } )<br> {<br> if ( $key eq "TEXT" )<br>
{<br> $clean->{$data->{$key}} = 1;<br> }<br><br> if ( $key eq "node" )<br> {<br> if ( ref( $data->{$key} ) eq "HASH" )<br> {<br> $clean->{$data->{'TEXT'}} = prep_clean(\%{$data->{$key}});<br>
}<br><br> if ( ref( $data->{$key} ) eq "ARRAY" )<br> {<br> my $sub_hashes = {};<br> for ( my $i = 0; $i <= $#{$data->{$key}}; $i++)<br> {<br>
foreach my $sub_hash ( \%{ $data->{$key}[$i] } )<br> {<br> my $subout = prep_clean( $sub_hash );<br> $sub_hashes = { %$sub_hashes, %$subout };<br>
}<br> }<br> $clean->{$data->{'TEXT'}} = $sub_hashes;<br> }<br> }<br> }<br> return $clean;<br>}<br><br>$clean = prep_clean( \%{ $data->{'node'} } );<br>
<br>print Dumper(\$clean);<br><br>exit;<br>#--------------------------------------------------------------------------------<br><br clear="all"><br>-- <br>J. Bobby Lopez<br>Web: <a href="http://jbldata.com/">http://jbldata.com/</a><br>
Twitter: <a href="http://www.twitter.com/jbobbylopez">http://www.twitter.com/jbobbylopez</a><br><br>