Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Tree path analyzer regex problem (maybe other issues)?

by ikegami (Patriarch)
on Jun 23, 2009 at 16:50 UTC ( [id://774104]=note: print w/replies, xml ) Need Help??


in reply to Tree path analyzer regex problem (maybe other issues)?

Here is a more robust solution (input doesn't need to be ordered, supports multi-level paths) that produces sorted output.

use strict; use warnings; sub set { my $p = \shift; $p = \( $$p->{$_} ) for @_; } sub flatten { my $node = shift; print(join('|', @_), "\n") if @_; return if !$node; for (sort keys %$node) { flatten($node->{$_}, @_, $_); } } { my $tree; while (<DATA>) { chomp; set($tree, split(/\|/)); } flatten($tree); } __DATA__ Valentine's Day Valentine's Day|Cards Valentine's Day|Flowers Valentine's|Candy Valentine's|Telegrams
Valentine's Valentine's|Candy Valentine's|Telegrams Valentine's Day Valentine's Day|Cards Valentine's Day|Flowers

Replies are listed 'Best First'.
Re^2: Tree path analyzer regex problem (maybe other issues)?
by bryank (Acolyte) on Jun 23, 2009 at 16:56 UTC
    That is a thing of beauty -- thanks. Question. I'd like to flag any new tree nodes that are created. I wasn't sure where I'd insert that messaging in your script...?
      It wasn't designed to do that. To keep the strengths of this method and produce a listing of changes, you could diff the sorted input with the output.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://774104]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 05:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found