in reply to Simple prog isnt cooperating

In if($Namelist ~= ...), I think you meant:

=~. That's the "equals or contains" regex check. ~= doesn't mean much to perl.

Also, $1 is a special variable based on a regex capture. You're not capturing anything here. A capture in a regex is specified by parens. I've got a meeting to bounce to, so someone else will have to explain that issue.

Replies are listed 'Best First'.
Re^2: Simple prog isnt cooperating
by stevieb (Canon) on Oct 15, 2018 at 21:51 UTC

    Yet Another Boring Meeting (where when I'm not needed, I hack Perl). Here's the capture you need. Note that it was quick and dirty, so I have not inserted any checking at all (which should be promoted; always check the value of a capture):

    use v5.12; use warnings; my $Namelist = 'Wilma Fred Barney Betty Dino'; if ( $Namelist =~ m/(\w+a)/) { print "Matched|$<$&>$|\n"; say "The name that matched was $1 \n"; } else { print "No match: \n"; }

    Output:

    spek@scelia ~/scratch $ perl format.pl Matched|1000Wilma>0 The name that matched was Wilma