Reputation: 523
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?
Upvotes: 4
Views: 11040
Reputation: 385657
\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));
}
Upvotes: 5