Rick S
Rick S

Reputation: 81

Converting a line of C regexp code to Perl

I'm trying to convert a line of old code from C (which I do not know) to Perl (which I sorta know).

It has a data structure I don't understand, that being a number followed by /* character */

if (lSeries != 18 /*S*/ &&  lSeries !=  2 /*C*/ && lSeries != 4  /*E*/ &&  lSeries != 6  /*G*/) {}

Upvotes: 1

Views: 94

Answers (2)

mob
mob

Reputation: 118605

In C, the /* ... */ construction indicates a comment. It will not be compiled or executed by the program.

So the executable part of that code snippet is

if (lSeries != 18 && lSeries != 2 && lSeries != 4 
    && lSeries != 6) {}

A literal translation to Perl would be

if ($lSeries != 18 && $lSeries != 2 && $lSeries != 4
    && $lSeries != 6) { }

Upvotes: 5

thirdeye
thirdeye

Reputation: 302

/* C style for multiline comments */

C code:

if(  lSeries != 18 /*S*/
  && lSeries != 2  /*C*/
  && lSeries != 4  /*E*/
  && lSeries != 6  /*G*/  
) {}

#perl style for single line comments. for more please refer Acme::Comment

Perl Code:

if(  $lSeries != 18 #S
  && $lSeries != 2  #C
  && $lSeries != 4  #E
  && $lSeries != 6  #G 
) {}

Upvotes: 5

Related Questions