regular expressions - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

regular expressions

tonyntonyn Posts: 7Member
Hi,

I have a file name which have these lines in the file. I want to compare if the schematic port and layout port are different then I report this file has port name different. Below is my code but it has problem with $1 and $2. How can I get $1 and $2?

thanks,
Tony


while () {
$port_session = 1 if ( /ports*Port classs*Schematic ports*Layout port/ ) ;
if ( /*s+d+s+(S+) (S+)$/ && $port_session ) {
$mismatch = 1 if ( $1 !~ $2 );
}
}

close(INF);








port Port class Schematic port Layout port
---------- ---------- -------------------- --------------------
L 1 D D
L 4 Q Q
L 6 RST x_6
L 5 SET SET
L 2 XCLK x_3
L 3 XQ XQ

Comments

  • leeb003leeb003 Posts: 12Member
    I'm sure it could be done more efficiently but this will work...

    #!/usr/local/bin/perl
    use strict;
    use warnings;

    my $data;
    my @data;
    open FILE, "data.txt";

    while () {
    if ($_ =~ /port Port class Schematic port Layout port/) {
    next;
    }
    elsif ($_ =~ /---/) {
    next;
    }
    elsif ($_ =~ /S+?/) {
    @data = split(/ /,$_);
    chomp @data;
    if ($data[2] ne $data[3]) {
    print "$data[2] and $data[3] are not equal
    ";
    }
    if ($data[2] eq $data[3]) {
    print "$data[2] and $data[3] are equal
    ";
    }
    }
    }
  • tonyntonyn Posts: 7Member
    Hi,

    thanks for your help.

    Tony
Sign In or Register to comment.