I haven't tried to understand your full program, but I think the problem you have is probably there:

Code

my $qw=induced(@{ $subgraphs[$d-1] });

The induced subroutine returns an array (@triplet), but $qw is a scalar. If you are using an array in scalar context, you will get the number of elements of the array, rather than the elements of the array.

this is probably OK, because this is the way data dumper will print it the way you use it. But if you look closely at it, it says that the variable you are dumping contains 3 variables, b, c and a, whicj is what you expect.

Laurent maybe I couldnt explain properly.Let me explain what is wanted.Consider for example component 2. It has two vertices e,d. Now I want to see if any of the rows from "DATA" is a subset of these points.Now since each of the row of "DATA" has 3 vertices/points,therefore clearly for component 2 there isnt any induced line from DATA. Therefore there should be anything to print for the subroutine "induced" for this case.

But for component 1,which has vertices as = c,a,b; the first line of "DATA" which is "b c a" gets induced.

Similarly if component=a,b,c,d ; then first two rows of DATA get induced ,as they are both the subset of the component. So what i want now is that,I want to save this induced vertices in a variable/array etc. AS i need to do further processing on this induced part.

out of the loop. The induced content depends on the content of component,so it should be kept inside the loop.For if there are 5 components and 3 of them are capable of inducing then "keeping it outside for loop" logic wont work

I did not claim a complete solution. I moved one print statement out of the loop because your expected output has only one copy of that output. Are you sure that your posted expected output is correct?

It is a good idea to use Data::Dumper as a debug tool. Perhaps you should remove the dumps as soon as you are convinced that they are correct. (They can be put back in to check out changes) Good Luck, Bill

I am traveling this week and don't have acces right now to a Perl environment, so I can't try your code. And it is too long for me to try to follow its logics manually.

But my impression is that you are expecting from Data::Dumper things that are beyond the scope of this module. Actually, I have the feeling that your program gives you what you need, but that you can't recognize it because you expect the same data in a format that is different from what Dumper provides you.

Clearly since, "b c a" is a subset of component1(c a b) therefore it gets printed. But Bill I just want to save this "b c a" in a suitable array/variable etc. As I need it for further processing.That's why I want to save this output,rather than just getting it printed.

Also there would be a case for example consider a component 3,which has these points= "a c d e". Then row 2nd and 3rd of "DATA" are a subset of these points.So for component3 I'm expecting this output

Code

component 3 = a c d e induced= a c d d e b

I want to save these induced values in a suitable data structure as I need to further process them.

Clearly since, "b c a" is a subset of component1(c a b) therefore it gets printed. But Bill I just want to save this "b c a" in a suitable array/variable etc. As I need it for further processing.That's why I want to save this output,rather than just getting it printed.

But you have "b c a" stored in the @qw array (BTW, you should give it a more sensible name, but it is a different matter), what else do you need?

Laurent I get that,but if you see Post #7, u'll see that that @qw gets printed even when component 2 =" e d" (But it shouldn't get printed ). Shouldnt it be something like this then ( if I keep this line "print Dumper @qw;" uncommented)

I am confused. Allow me to start over. I am unable to exactly duplicate your original problem with the following proceedure.

Paste your code into editor.

Restore newlines with perltidy

Change input operator to <DATA>

Add data to end of file[\li]

Install Graph module on my system[\li]

Remove reference to Graph::Subgraph -- not used

I tried Laurent's suggestion from post 2. The resultls diverge even more from those in post 3.

Later posts bring up more issues. Let's settle the first one first. Please attach (this avoids the newline problem) a complete working copy of your script that we can both run. I have attached my script as a sample of what I need. Good Luck, Bill

So if the count is 0, you know that @y is a subset of @x and hence you want to return it from the "induced" subroutine. I hope this would even clear out the mess. Now can this be incorporated as a subroutine. The input will be DATA taken in as an array. The second array will hold the connected components.

Code

____DATA_____ b c a a c d d e b e f g g d f h i g

@Components

Code

a b c a b d c e f d g

So I want to see if any row of @DATA is contained inside @Components. So the output expected is

I understand that you want subroutine induced to accept one component and return the first line of DATA which is a subset of it. Return an empty array if there is none. This subroutine is called for each component. I have not yet tried to integrate this with your graph code.