Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Tree Structure Challenge

by Anonymous Monk
on Nov 29, 2015 at 23:42 UTC ( #1148839=note: print w/replies, xml ) Need Help??


in reply to Tree Structure Challenge

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; dd( deeef( 'Cobra', 'Fox' ) ); #~ should return #~ ( [qw[ Fox Canine Mammal ]], #~ [qw[ Cobra Snake Reptile ]] #~ ) sub deeef { my( @animals ) = @_; my %catcatdog = ( Mammal => { Bovine => ["Cow", "Bison"], Canine => ["Dog", "Fox", "Wolf"], Equine => ["Horse", "Zebra", "Pony"], }, Reptile => { Bird => ["Pigeon", "Canary", "Owl"], Lizard => ["Salamander", "Chameleon"], Snake => ["Python", "Cobra"], }, ); my %dogcatcat; for my $cat ( keys %catcatdog ){ for my $catcat ( keys %{ $catcatdog{ $cat } } ){ for my $dog( @{ $catcatdog{$cat}{$catcat} } ){ #~ $dogcatcat{$dog}{$cat}{$catcat}++; #~ $dogcatcat{$dog}{$catcat}++; #~ $dogcatcat{$dog}{$cat}++; push @{ $dogcatcat{$dog} }, $catcat, $cat, ; } } } #~ return map {; [ $_, keys %{ $dogcatcat{$_} } ] } @animals; return map {; [ $_, @{ $dogcatcat{$_} } ] } @animals; }

Replies are listed 'Best First'.
Re^2: Tree Structure Challenge
by choroba (Archbishop) on Nov 30, 2015 at 00:00 UTC
    How should I run your solution to get the result for the following?
    'Zoo'->diff( 'Zoo'->new(qw( Dog Fox Wolf )), 'Zoo'->new(qw( Fox )));

    Not saying that I'm getting

    Can't use an undefined value as an ARRAY reference at ./zoo.pl line 40 +.
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      How should I run your solution to get the result for the following?

      What should the result look like?

      Not saying that I'm getting ...

      Huh?

      dd( deeef( qw/ Dog Fox Wolf / ) ); __END__ ( ["Dog", "Canine", "Mammal"], ["Fox", "Canine", "Mammal"], ["Wolf", "Canine", "Mammal"], )
        What should the result look like?
        ( [], [ 'Dog', 'Wolf' ] )

        Huh?
        I know how to run your code. It doesn't follow the specification: you haven't implemented a static method.
        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2020-11-01 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (291 votes). Check out past polls.

    Notices?