CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [BillKSmith] Problem printing return value from a subroutine: Edit Log



zing
Novice

Oct 6, 2012, 1:27 AM


Views: 2736
Re: [BillKSmith] Problem printing return value from a subroutine

thanks for cleaning it up BillK. Let me reformulate the exact part concerned.
Guys the problem is like to check if an array is contained inside another array.

Code
perl -le '@x = qw(a b c d e f); 
@y = qw(a d f);
$n = grep { $e = $_; not grep { $e =~ /\Q$_/i } @x } @y;
print "Count of elements in (@y) that are NOT present in (@x) = $n"
'
Count of elements in (a d f) that are NOT present in (a b c d e f) = 0


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

Code
component 1 = a b c 
induced = b c a
component = a b d c
induced = b c a
a c d
component 3 = e f d g
induced = e f g
g d f



(This post was edited by zing on Oct 6, 2012, 1:28 AM)


Edit Log:
Post edited by zing (Novice) on Oct 6, 2012, 1:28 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives