I have the following strings in array @stat
:
r> 10.12.44.0/24
r> 10.11.48.0/24
*> 10.15.49.0/24
r> 10.16.53.0/24
r> 10.14.59.0/24
*> 10.18.63.0/24
I want match the one who have "*>
". Note that there is whitespace before the *
. I tried using the following, but it didn't work.
foreach (@stat) {
if (/^\s\*\>/) {
# do something
}
}
What did I miss?
\s
matches one whitespace character. What you posted actually has two leading spaces. Tthe following should do the trick:
foreach (@stat) {
if (/^\s*\*>/) {
# do something
}
}
If not, check what's actually in your array more carefully.
use Data::Dumper qw( Dumper );
{
local $Data::Dumper::Useqq = 1;
print(Dumper(\@stat));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With