RE: Block Confusion





> -----Original Message-----
> From: Jeff 'japhy' Pinyan [mailto:japhy@xxxxxxxxxxxx]
> Sent: Tuesday, September 27, 2005 8:20 PM
> To: Ryan Frantz
> Cc: beginners perl
> Subject: Re: Block Confusion
>
> On Sep 27, Ryan Frantz said:
>
> > # list the processes to hunt for
> > my @findProcesses = (
> > "putty",
> > "firefox",
> > );
> >
> > foreach my $process (in
> > $serverObj->InstancesOf("Win32_PerfFormattedData_PerfProc_Process"))
{
> > foreach my $matchProcess ( @findProcesses ) {
> > if ( $process->{Name} =~ /$matchProcess/oi ) {
>
> You're using the /o modifier here, and that's causing your problem.
I'm
> guessing you don't actually know what the /o modifier does. It tells
Perl
> the regex won't change after it's been compiled the first time.
Remove
> the /o modifier and I believe your code will run fine.

I misunderstood the documentation I read about the /o modifier; I
thought it was necessary for a variable whose value was a regex and then
assumed (yes, due to my ignorance) that the next iteration through the
list would do the same.

I have modified my code and it works as intended. Thanks for the heads
up.




>
> --
> Jeff "japhy" Pinyan % How can we ever be the sold short or
> RPI Acacia Brother #734 % the cheated, we who for every service
> http://www.perlmonks.org/ % have long ago been overpaid?
> http://princeton.pm.org/ % -- Meister Eckhart
.



Relevant Pages

  • Re: the only difference is the x after /g
    ... the first of the two regex lines. ... You added the /x modifier. ... effect this has is to make the pattern match ignore white spaces. ... recognize a particular whitespace character, ...
    (perl.beginners)
  • Re: search and replace
    ... The /o modifier tells the internal regex compiler that, after this regex has been compiled 'o'nce, it is never to be compiled again. ... The /s modifier often carries the mnemonic "so you can match your string as though it were a single line" and that all of the sudden makes people think all sorts of crazy things. ...
    (perl.beginners)
  • Re: Regular Expresssion - Matching over multiple lines
    ... No modifier to a regex changes the greediness of the quantifiers ... three regexes have the /gc modifier, when the first one fails, it'll try ... CPAN ID: PINYAN [Need a programmer? ...
    (perl.beginners)
  • Fwd: regex matching conditionally
    ... Subject: regex matching conditionally ... The /o modifier only applies if you have variables in the regular expression. ... optimizes and only compiles static regex once? ... will give rise to dom! ...
    (perl.beginners)
  • Re: Nested {}
    ... The /x modifier is so that I can have extra whitespace, ... contents as PART of the regex to match. ... CPAN ID: PINYAN [Need a programmer? ...
    (perl.beginners)