Thanks for reading another post from a frustrated Perl noob
Sorry for the long post but I want to be as clear as possible.
setup to reproduce:
3 test files containing names:
File name --- File Content
---------- ------------------------------------
mailgroup1 - MARY BOB FRANK MYNAME JANE
mailgroup2 - SUSAN CHRIS WANDA
mailgroup3 - ANNE MYNAME DEBBIE JOHN MIKE FRANK
Code:
Quote:
1 #!/bin/perl
2
3 use strict;
4
5 system(clear);
6
7
8 my $user = "MYNAME";
9 my @groups = ('mailgroup1', 'mailgroup2','mailgroup3',);
10
11 foreach my $group (@groups) {
12 chomp $group;
13 my @group_list = `cat $group`;
14 print "$group\n";
15 foreach my $match (@group_list) {
16 chomp $match;
17 if ($match eq $user) {
18 print "*** $match ***\n\n";
19 } else {
20 print "$match\n\n";
21 }
22
23 }
24 }
25
26 print "$user <--- is what \$user returns.\n\n";
27
|
I want to print to the screen all members from the mailgroups with *'s surrounding MYNAME i.e. *** MYNAME ***
This does not happen
With the above I get this:
Quote:
mailgroup1
MARY BOB FRANK MYNAME JANE
mailgroup2
SUSAN CHRIS WANDA
mailgroup3
ANNE MYNAME DEBBIE JOHN MIKE FRANK
MYNAME <--- is what $user returns.
|
If I change line 17 to this:
17 if ($match = $user) {
I get this:
Quote:
mailgroup1
*** MYNAME ***
mailgroup2
*** MYNAME ***
mailgroup3
*** MYNAME ***
MYNAME <--- is what $user returns.
|
If I change line 17 to this:
17 if ($match =~ $user) {
I get this:
Quote:
mailgroup1
*** MARY BOB FRANK MYNAME JANE ***
mailgroup2
SUSAN CHRIS WANDA
mailgroup3
*** ANNE MYNAME DEBBIE JOHN MIKE FRANK ***
MYNAME <--- is what $user returns.
|
The output I am looking for is this:
Quote:
mailgroup1
MARY BOB FRANK *** MYNAME *** JANE
mailgroup2
SUSAN CHRIS WANDA
mailgroup3
ANNE *** MYNAME *** DEBBIE JOHN MIKE FRANK
|
What am I doing wrong? Why does eq not work?
Thanks,
-OG-