Perl

Moderators: Jonathan
Number of threads: 1259
Number of posts: 3644

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
regular expressions Posted by tonyn on 8 Apr 2009 at 2:00 PM
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 (<INF>) {
$port_session = 1 if ( /port\s*Port class\s*Schematic port\s*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

Report
Re: regular expressions Posted by leeb003 on 9 Apr 2009 at 5:31 PM
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 (<FILE>) {
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\n";
}
if ($data[2] eq $data[3]) {
print "$data[2] and $data[3] are equal\n";
}
}
}
Report
Re: regular expressions Posted by tonyn on 10 Apr 2009 at 10:10 AM
Hi,

thanks for your help.

Tony



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.