Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

You say you want to return instead of print?

Think about that for a minute, return instead of print

Hmm, how to return instead of print?

Write return instead of print?

Hmm, yes, write return instead of print, replace print with return, yes, I think that is it :)

But there is a problem with returning instead of printing -- there can be more than one matching triplet , so by returning you only get the first matching triplet

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ pp /; Main(@ARGV); exit(0); #~ sub DEBUG(){} # disable debugging sub DEBUG { my ( $p, $f, $l ) = caller; print "$f:$l: ", pp(@_), "\n"; + } sub induced { my $trip = shift; my @matches; for my $QT ( @_ ) { DEBUG( $QT ); for my $triplet ( @$trip ) { DEBUG($triplet); my %seen; # my %Pie; DEBUG( \%seen ); # DEBUG( \%Pie ); undef @seen{@$QT}; DEBUG( \%seen ); delete @seen{@$triplet}; DEBUG( \%seen ); DEBUG( { KEYS_LEFT => \%seen, QT_SIZE => scalar(@$QT), TRIPLET_SIZE => scalar(@$triplet), }, ); if ( keys( %seen ) <= ( @$QT - @$triplet ) ) { DEBUG( $triplet ); push @matches, $triplet; } } ## end for my $triplet ( @$trip ) } ## end for my $QT ( @_ ) return @matches; } ## end sub induced sub Main { my @S = ( [ "b", "c", "a" ], [ "a", "c", "d" ], [ "d", "e", "b" ] ); my @T = ( [qw[ a b c d ]], [qw[ b e d ]] ); for my $one (@S) { my @matches = induced( \@T, $one ); print "\nGot some? ", pp( $one => { MATCHES => \@matches } ), "\n\ +n"; } } ## end sub Main __END__ qtPie:16: ["b", "c", "a"] qtPie:18: ["a" .. "d"] qtPie:20: {} qtPie:22: { a => undef, b => undef, c => undef } qtPie:24: {} qtPie:25: { KEYS_LEFT => {}, QT_SIZE => 3, TRIPLET_SIZE => 4 } qtPie:18: ["b", "e", "d"] qtPie:20: {} qtPie:22: { a => undef, b => undef, c => undef } qtPie:24: { a => undef, c => undef } qtPie:25: { KEYS_LEFT => { a => undef, c => undef }, QT_SIZE => 3, TRIPLET_SIZE => 3, } Got some? (["b", "c", "a"], { MATCHES => [] }) qtPie:16: ["a", "c", "d"] qtPie:18: ["a" .. "d"] qtPie:20: {} qtPie:22: { a => undef, c => undef, d => undef } qtPie:24: {} qtPie:25: { KEYS_LEFT => {}, QT_SIZE => 3, TRIPLET_SIZE => 4 } qtPie:18: ["b", "e", "d"] qtPie:20: {} qtPie:22: { a => undef, c => undef, d => undef } qtPie:24: { a => undef, c => undef } qtPie:25: { KEYS_LEFT => { a => undef, c => undef }, QT_SIZE => 3, TRIPLET_SIZE => 3, } Got some? (["a", "c", "d"], { MATCHES => [] }) qtPie:16: ["d", "e", "b"] qtPie:18: ["a" .. "d"] qtPie:20: {} qtPie:22: { b => undef, d => undef, e => undef } qtPie:24: { e => undef } qtPie:25: { KEYS_LEFT => { e => undef }, QT_SIZE => 3, TRIPLET_SIZE => + 4 } qtPie:18: ["b", "e", "d"] qtPie:20: {} qtPie:22: { b => undef, d => undef, e => undef } qtPie:24: {} qtPie:25: { KEYS_LEFT => {}, QT_SIZE => 3, TRIPLET_SIZE => 3 } qtPie:34: ["b", "e", "d"] Got some? (["d", "e", "b"], { MATCHES => [["b", "e", "d"]] })

In reply to Re^3: Finding subgraphs induced by a set of given vertices. by Anonymous Monk
in thread Finding subgraphs induced by a set of given vertices. by zing

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (4)
    As of 2014-10-21 03:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (95 votes), past polls