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: [Laurent_R] question about using m (match operator) with arrays: Edit Log



perlFun
Novice

Jun 14, 2013, 11:37 AM


Views: 490
Re: [Laurent_R] question about using m (match operator) with arrays

I'm sorry, I think I posted the question in a weird way. I do realize that first line is simply taking in the arguments. Here let me give an example:

here's the sub:

sub _str_comp {
my ($s1, $s2, $msg) = @_;
if ( $s1 !~ m/$s2/ ) {
#do error logging stuff here
return 1;
}
return 0;
}#end sub _str_comp


here's an example of where it's being called:
(note: $a and $b are both references to hashes)
my @arrt = keys %{$a};
my @arr1 = grep(/\w+\.\w+\.\w+/,@arrt);
@arrt = keys %{$b};
my @arr2 = grep(/\w+\.\w+\.\w+/,@arrt);
if ( _str_comp( $#arr1, $#arr2, "a message") ) {
#stuff being done
}


my understanding:
I have two hash references, $a and $b. I get an array which holds the keys of the first hash. I grep this array to find matches of the form w+.w+.w+ (alphanumeric chars with two . delimeters). I similarly get an array of the keys of the has referenced by $b and grep it to find matches of that type. I send these grep results (which are arrays) to that _str_comp subroutine. My confusion is kind of what is being checked for in this context. will I get a positive result in that case so long as the arrays simply contain all the same values, regardless of indeces? (so for example say the keys for the hash referenced by $a are 54.jk.1 and 99.1.99, both would get grepped. Now say the keys for the hash referenced by $b are key1, 99.1.99, and 54.jk.1. then 99.1.99 and 54.jk.1 would get grepped. you'd end up sending the arrays @arr1 = (54.jk.1, 99.1.99) and @arr2 = (99.1.99, 54.jk.1) (references to such arrays). would those be equal under the "m" operation? Or does it actually just look at the scalar context of those arrays (which would be the size of the arrays?)


(This post was edited by perlFun on Jun 14, 2013, 11:50 AM)


Edit Log:
Post edited by perlFun (Novice) on Jun 14, 2013, 11:40 AM
Post edited by perlFun (Novice) on Jun 14, 2013, 11:50 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