我有一个巨大的文件,其中包含以下类似的行,具有不同的时钟:
cmd -quiet [get_ports p1] ref_clocks "cudtclk_sp cudtclk"
cmd -quiet [get_ports p2] clock "cu2xdtclk_sp cu2xdtclk"
每当我的文件中有 ref_clocks 时,我都需要用其他名称(如 cdtclk)替换 cudtclk,全局。
我已经编写了以下代码,但它似乎不起作用。
#!/usr/bin/perl
use strict;
use warnings;
sub clock_change
{ # Get the subroutine's argument.
my $arg = shift;
# Hash of stuff we want to replace.
my %replace = (
"cudtclk" => "cdtclk",
);
# See if there's a replacement for the given text.
my $text = $replace{$arg};
if(defined($text)) {
return $text;
}
return $arg;
}
open PAR, "<file name>";
while(<PAR>) {
$_ =~ s/\S+\s\S+\s\S+\s\S+\sref_clocks\s+(\S+\s+\S+)/clock_change($1)/eig;
print $_; ##print it to some file later.
}