Happy New Year Monks!
My question and code posted below. I would like to delete the SAME line in multiple files. The below code works fine for 2 files however I have an additional 3 files or more the data could show up in but not always. Instead of listing each file is there away to combine EVERYTHING into one block of code? Thanks for the help!

my $process_file = $rrconfig::locodata; my $process_file2 = $rrconfig::availlocodata; my @data; my @data2; { open(my $data_file_handle, '<', "$process_file") or die("Can't open file: $process_file"); open(my $data_file_handle2, '<', "$process_file2") or die("Can't open file: $process_file2"); @data = <$data_file_handle>; @data2 = <$data_file_handle2>; close($data_file_handle); close($data_file_handle2); close $process_file; close $process_file2; } chomp(@data); chomp(@data2); open(my $out_file_handle,'>', $process_file) or die("Can't open file: $process_file"); open(my $out_file_handle2,'>', $process_file2) or die("Can't open file: $process_file2"); foreach my $line_from_file ( @data ) { my @field = split( /\:/, $line_from_file ); next if( ($field[1] eq $delroad) && ($field[2] == $delnumber) ); print $out_file_handle $line_from_file, "\n"; } foreach my $line_from_file2 ( @data2 ) { my @field2 = split( /\:/, $line_from_file2 ); next if( ($field2[1] eq $delroad) && ($field2[2] == $delnumber) ); print $out_file_handle2 $line_from_file2, "\n"; } close $out_file_handle; close $out_file_handle2; close $process_file; . close $process_file2;


In reply to Delete Lines Across Multiple Files by PilotinControl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.