in reply to Command Line

#!/usr/intel/bin/perl use warnings; use strict; my $find_flag; #using a flag variable my ($iFile, $oFile, $replacement) = @ARGV; open my $iHandle, '<', $iFile or die $@; open my $oHandle, '>', $oFile or die $@; while ( <$iHandle> ){ if (/^\S/){ #match a line that start wit +h no space if (/^\w+clk\[\d+\]/){ #match requested headline $find_flag = 0; } else{ $find_flag = 1; } } next if $find_flag and s/\s+QUALIFIED_CLOCK/$replacement/; #skip +s the line requested print $oHandle $_; #printing ordinary line }


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Command Line
by guyov1 (Novice) on Oct 22, 2008 at 12:41 UTC
    Great, thanks! Just one thing - I want the third input - STRING , to be the word that I look for and not replace with. If I don't put anything there I want the code to work as it is, and if I do I need it to look for STRING instead of looking for QUALIFIED_CLOCK...
      I was trying to replace the line mentioned with
      next if ( $find_flag and ( if ($replacement == "") { /\s+QUALIFIED_C +LOCK/ } else { /\s+$replacement/ } ));
      But it writes me "syntax error". I cant understand why... What I'm trying to do is check whether I entered a string and then look for it, and If not, look for QUALIFIED_CLOCK .
        like that?
        my ($iFile, $oFile, $searchFor) = @ARGV; $searchFor = quotemeta( $searchFor || 'QUALIFIED_CLOCK ); .... next if $find_flag and /\s+$searchFor/;


        holli, /regexed monk/
        Hint: Try counting your open and close parens, per block.