tags:

views:

97

answers:

2

In the discussion of ?PATTERN?, perlop states "This usage is vaguely deprecated". Does this mean that the ?? matching operator itself will be removed from perl, or does it mean that its semantics will change? Is using ?? a bad idea, or can that warning in perlop be ignored?

+5  A: 

I would assume it means more or less what it says:

This usage is vaguely deprecated, which means it just might possibly be removed in some distant future version of Perl, perhaps somewhere around the year 2168.

So that means they'll remove it when they release Perl 6.

I kid, I kid. I would assume "vaguely deprecated" would mean that it's not a terrible construct, but you might want to rethink your design. I personally didn't even know what it was (or that the reset() function even existed) until I looked it up just now, and having seen it, I don't know if I would ever use it for anything. The example they give in perlop is a bit cryptic:

while (<>) {
  if (?^$?) {
    ...
  }
} continue {
  reset if eof;
}

I would write the equivalent and more obvious:

my $reset = 1;
while (<>) {
  if ($reset and /^$/) {
    ...
    $reset = 0;
  }
} continue {
  $reset = 1 if eof;
}

It's more verbose, but it's a little more obvious and easier on the brain (and maintainer).

Chris Lutz
I wouldn't call it `$reset`; I think `$searching` or something like that would make it much clearer.
cjm
@cjm - I agree, but `$reset` was the first thing that came to my head.
Chris Lutz
+5  A: 

Did you not read the rest of the sentence? It seems clear enough:

This usage is vaguely deprecated, which means it just might possibly be removed in some distant future version of Perl, perhaps somewhere around the year 2168.

To me, that says that the maintainers of Perl don't like the special-case behavior and would rather that people didn't use it but have no plans to change it.

It's safe to use. It would have to go through a real deprecation cycle (which can last quite a while) before it would be removed. That said, I wouldn't use it. This feature is esoteric enough that it could easily confuse whomever ends up maintaining your code (which could be future you).

Michael Carman
"it might ... be removed" is ambiguous. Does "it" refer to the operator itself, or "this usage". The construction of the sentence implies that 'it' refers to 'this usage', indicating that the operator would remain with different semantics.
William Pursell
`?PATTERN?` is a special case of the `m//` operator. There's no chance the operator itself going away. What would change is the behavior when using `?` as the delimiter; presumably it would no longer be special.
Michael Carman