S
Stephan Mann
Hi!
I'm relatively new to Perl and I'm not a RegEx guru either. I'd like to
understand, why the following code does not work as I expect.
Obviously, I'm oblivious to some detail of how the RegEx engine works.
my @foo = ('one', 'two', 'three');
print join " ", grep { /[^(two)]/ } @foo, "\n";
my @bar = ('123:44', '123:45', '123:46');
print join " ", grep { /[^(123:45)]/ } @bar, "\n";
print join " ", grep { !/123:45/ } @bar, "\n";
Output:
one three
123:46
123:44 123:46
I'm completely lost as to why the second grep doesn't work like the first
one. The colon doesn't seem to be the problem, since the behavior stays
the same without it. How or why are numbers handled differently?!
The third grep works, but it forces me to handle this in a separate
RegEx which I can't extend if a want to do more with one RegEx.
tia, stephan
PS: This is my first post to a non-test group with slrn. Please let me
know if there is anything wrong with my post.
I'm relatively new to Perl and I'm not a RegEx guru either. I'd like to
understand, why the following code does not work as I expect.
Obviously, I'm oblivious to some detail of how the RegEx engine works.
my @foo = ('one', 'two', 'three');
print join " ", grep { /[^(two)]/ } @foo, "\n";
my @bar = ('123:44', '123:45', '123:46');
print join " ", grep { /[^(123:45)]/ } @bar, "\n";
print join " ", grep { !/123:45/ } @bar, "\n";
Output:
one three
123:46
123:44 123:46
I'm completely lost as to why the second grep doesn't work like the first
one. The colon doesn't seem to be the problem, since the behavior stays
the same without it. How or why are numbers handled differently?!
The third grep works, but it forces me to handle this in a separate
RegEx which I can't extend if a want to do more with one RegEx.
tia, stephan
PS: This is my first post to a non-test group with slrn. Please let me
know if there is anything wrong with my post.