guyov1 has asked for the wisdom of the Perl Monks concerning the following question:

Hey monks, I have used your kind help for making a code that edits my text. Removing QUALIFIED from headlines containing clkdigit. What I'm trying to do now is change the code in a way that the user will only have to type (cshell): CodeName SourceFile TargetFile AlternativeString . If no AlternativeString is defined it will still look for QUALIFIED. I also want to make Information note as for what lines were deleted, and a warning for unspecified SourceFile and/or TargetFile. Would appreciate any help! Thanks.
#!/usr/bin/perl use warnings; use strict; my $find_flag; #using a flag variable while ( <> ){ if (/^\S/){ #match a line that start with no space if (/^\w+clk\[\d+\]/){ #match requested headline $find_flag = 0; } else{ $find_flag = 1; } } next if $find_flag and /\s+QUALIFIED_CLOCK/; #skips line print qq{$_}; #printing ordinary line } __data__ qclk[6] INPUT ( ! "asdk fd sasd" VALID ( late_lead 3 ar qclk slope 20 late_lead 3 af qclk slope 04 early_dn 8 ar qclk slope 6 early_up 6 af qclk slope 6 ) cext %0.00394757 cmax %0.005504 QUALIFIED ) clkout_qclk_61[3] OUTPUT ( ) clkout_qclk_61[2] OUTPUT ( REQUIRED ( earlyp 0.5 br qclk clm(2) latel_up 5 bf qclk clk(2) ) REQUIRED ( early_lead_dn 0.004 bf qclk clkdom(2) late_trail_dn 0.005 br qclk clkdom(2) ) cext %0.0647336 max_ceff_up %0.187 QUALIFIED )

Replies are listed 'Best First'.
Re: Input/Output editing
by apl (Monsignor) on Oct 22, 2008 at 10:27 UTC
    What I'm trying to do now is change the code in a way that the user will only have to type (cshell): CodeName SourceFile TargetFile AlternativeString .
    You should take a look at GetOpt::Long.
    If no AlternativeString is defined it will still look for QUALIFIED. I also want to make Information note as for what lines were deleted, and a warning for unspecified SourceFile and/or TargetFile
    How would you test a variable for a valid value (or that a line was deleted)?
      I would test a variable just as if the file source and destination truly exists. And a line - if the "next line" in the while loop occurs.