Hi, Yes, they are the same.
I like to use $_ only when the data comes in $_ naturally. Like in a for loop: for (qw< abc >) { if ( !/\w+\d+/ ) { print "not matched"; } } Otherwise, I have to write $_, then I prefer to name the variable something descriptive instead. Makes the code more readable and maintainable down the road. -L On Wednesday, June 19th, 2024 at 3:55 AM, Jeff Peng via beginners <beginners@perl.org> wrote: > Hello list, > > are these statements the same in perl? > > $ perl -le '$_="abc";if (!/\w+\d+/){print "not matched"}' > not matched > > $ perl -le '$_="abc";if ($_ !~ /\w+\d+/){print "not matched"}' > not matched > > or which is the better one? > > Thanks. > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/