Re: regex matching statements

[email protected] (Levi Elias Nystad-Johansen via beginners) Wed, 19 Jun 2024 06:41:16 +0000
Newsgroups perl.beginners
Message-ID <HYWHorOKT1xgwmshoOB4aLxXwCLzkFrohv4nVuWsnOgvvl3T5OK4k1bQHYNgpG2bBjIlKWeOEV_MuxDTGrqsan2Tea83ZlER72CRjYnA6ZI=@protonmail.com>
Hi,=20

Yes, they are the same.=20

I like to use $_ only when the data comes in $_ naturally. Like in a for lo=
op:=20
for (qw< abc >)
{
  if ( !/\w+\d+/ )
  {
    print "not matched";
  }
}

Otherwise, I have to write $_, then I prefer to name the variable something=
 descriptive instead.=20
Makes the code more readable and maintainable down the road.=20


-L=20


On Wednesday, June 19th, 2024 at 3:55 AM, Jeff Peng via beginners <beginner=
[email protected]> wrote:

> Hello list,
>=20
> are these statements the same in perl?
>=20
> $ perl -le '$_=3D"abc";if (!/\w+\d+/){print "not matched"}'
> not matched
>=20
> $ perl -le '$_=3D"abc";if ($_ !~ /\w+\d+/){print "not matched"}'
> not matched
>=20
> or which is the better one?
>=20
> Thanks.
>=20
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/