1

Really simple question but the =()= operator (or operators) lets me count the matches in regex. What is this operator called and what exactly is it doing?

Example usage:

my $count_quotes =()= $csv_line =~ /\"/gi;

Thanks

RichM
  • 272
  • 1
  • 2
  • 14
  • 1
    Your question is covered in http://stackoverflow.com/q/3991766/133939 and http://stackoverflow.com/q/2897853/133939 – Zaid May 02 '13 at 10:30
  • Thanks Zaid, I had trouble searching for it and knowing the name is helpful now. I don't know why I got down voted as I asked a question because I didn't know or couldn't find the answer. – RichM May 02 '13 at 10:49
  • It's just a weird way or writing `my $count = () = ...;`. See [Mini-Tutorial: Scalar vs List Assignment Operator](http://www.perlmonks.org/?node_id=790129) – ikegami May 02 '13 at 15:41
  • 1
    The Perl secret operators are not so secret anymore as they have [some documentation on CPAN](https://metacpan.org/module/perlsecret) – dolmen May 02 '13 at 15:59

1 Answers1

2

FWIW, you could count the number of quotes with the tr/// operator as well:

my $count = $csv_line =~ tr/"/"/;
Zaid
  • 36,680
  • 16
  • 86
  • 155
  • Thanks, I'll mark it as accepted because it makes what the code is doing clear and understandable. – RichM Jun 06 '13 at 23:30