Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.