Hello Mariano,

I realize that there may be a number of ways to do what I need to do
(most of them better, I bet), and I'd love to learn about them. But
now I'm mostly curious about why grep// cannot "see" words with
parentheses in either (or both lists). I suspect the trick may be
somehow escaping the (), but I tried a number of ways of doing that to
no avail.

Characters having specific meanings in regular expressions have to be escaped. You could either use the quotemeta function or enclose the regular expression within \Q and \E:

grep /^ \Q $array1[$ctr1] \E $/x, @array2;

Some comments about the code:

#!usr/bin/perl
For increased portability, use the shebang #!/usr/bin/env perl

use warnings;
Also use strict;.

$path1 =<STDIN>; chomp $path1;
Declare variables before they are used.

open (INPUT1, "$path1"); open (INPUT2, "$path2"); open (INPUT3, "$path3");
Try to use the 3-argument version of open.

my ($array1,$array2,$in1and2);
Avoid naming scalars and arrays (or hashes) the same.

An alternative solution:

=pod code

#!/usr/bin/env perl

use strict;
use warnings;

use File::Slurp qw( slurp );
use List::MoreUtils qw( any each_array );

my %path;
print "Enter path to list 1: ";
chomp( $path{'list_1'} = <STDIN> );
print "Enter path to list 2: ";
chomp( $path{'list_2'} = <STDIN> );

chomp( my @list_1 = slurp( $path{'list_1'} ) );
chomp( my @list_2 = slurp( $path{'list_2'} ) );

my @common_list;

for my $word (@list_1) {
    any { $_ eq $word } @list_2 and push @common_list, $_;
}

printf "in 1 = %d
in 2 = %d
in 1 and 2 = %d\n", scalar @list_1, scalar @list_2, scalar @common_list;

=cut

> Any help will be greatly appreciated! And as usual, if you ever have
> questions about molecular biology and genetics, fire away - I'd love
> to pay the favor back.

Thank you.

Hope this message helps. :-)

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to