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

How to remove hyperlinks from the lines whichever line has special character using perl?
SL.NO CHECKLIST ITEM VALUE COMMENTS CONFIRMATION Revision1 0.00% 0.00% Revision2 0.88% 0.88% OVERALLSTATUS=0.88% PARTIALSTATUS=0.88%
I like to remove hyperlinks from the lines(whereever special character is present (i.e =,%).
my $href="https://nce.log.com/diay/DB/$root"; my $check=0; for my $word(@data){ $check++; print $fh_out '<td>'; if($check==1) { # print $fh_out '<a href="' .$href_to_what{$word}.'">'; print $fh_out '<a href="'.$href.' " >'; } print $fh_out $word; if($check==1) { print $fh_out '</a>'; } print $fh_out '</td>'; } print $fh_out "</tr>\n"; }
Expected output wiht hyperlinks: SL.NO CHECKLIST ITEM VALUE COMMENTS CONFIRMATION Revision1 0.00% 0.00% Revision2 0.88% 0.88%

Replies are listed 'Best First'.
Re: Remove hyperlinks from the lines which have special character?
by Corion (Patriarch) on Mar 13, 2017 at 08:56 UTC

    There are no hyperlinks in your posted input file.

    You can help us help you better by posting short, relevant input data.

    Looking at your input and output as stated, the easiest approach would be to reject any line that starts with OVERALLSTATUS or PARTIALSTATUS.

      Here am unable to fix the hyperlink line for lines.

      Yes you are absolutely right.I should omit the hyperlinks for the line starts with overall status and partial status.

        Ah. So the output you show is not the output your script actually generates.

        I would split up the task into two steps:

        1. Check whether a hyperlink should be added to a line
        2. Print the line with a hyperlink or print it without

        For the first step, you should write a subroutine needsHyperlink, which checks whether a line needs a hyperlink:

        sub needsHyperlink { my( $line ) = @_; ... # see perldoc perlre for checking }

        Then, you call that function to see whether you need to add a hyperlink in the output or not:

        my $outputHyperlink = needsHyperlink( $line ); if( $outputHyperlink ) { # print line with hyperlink } else { # print line without hyperlink, or maybe don't print it at all };

        Update: added second sentence about not printing things

Re: Remove hyperlinks from the lines which have special character?
by huck (Prior) on Mar 13, 2017 at 09:14 UTC

    ya know ... you dont explain very well, nor give full enough examples, we keep having having to guess.

    Kinda remembering from what was asked before

    while ($line=<$fhin>) { ... next if $data[0]=~m/[\=\%]/; ... place where you print out '<tr>'; ... for my $word(@data){ ...
    the "next if .." line has to be before you print the <tr> That may mean you have to move the @data=split(????,$line) up higher too

      This code will remove the entire hyperlink line.I like to remove only the hyperlinks from the line.THe line contents should be there the hyperlink line(means tha underlined line)how it can be removed.

        my $dolink=$data[0] !~ m/[\=\%]/; for my $word(@data){ $check++; print $fh_out '<td>'; if($check==1 && $dolink ) { print $fh_out '<a href="'.$href.'" >'.$word.'</a>'; } else { print $fh_out $word;} print $fh_out '</td>'; }
        That isnt what you showed as your sample output tho, whole lines were missing ya know. cleaned it up a little too. you dont really want the training TRAILING space in the href= either.