I wrote some code for you below. I didn't completely test it but it does illustrate some basic ideas.

1. A loop like this, which is common in 'C' is seldom needed in Perl: for ($i=1; $i < 119000; $i++) because we have a foreach(@xyz){} iterator that "visits" all elements of @xyz without having to know the number in advance.

2. There are a number of ways to get the files within a directory that match a pattern. Below I show the way needed with Active State Perl 5.6 within comments, but if you have say Perl 5.10 the glob() method below will work fine.(there are at least 3 variants of glob that I know of).

3. The way that is the most safe when modifying a file is make a temp file, do your thing and then if all works ok, delete the original file and replace with the new file. There are actually even more safe ways than I've shown here for that. But this is good for 99% of cases.

use warnings; use strict; # is one way to get the file names # I think here we can just use glob() if you are at Perl 5.10 # my $source_dir = "C:/convs"; # opendir (DIR, $source_dir) || die "unable to open $source_dir $!"; # @files = grep{m/conv\d+\.txt/}readdir DIR; my $source_dir = "C:/convs"; my @files = glob("$source_dir/conv*.txt"); foreach my $file (@files) { open (IN, "$source_dir/$file") || die "unable to open $source_dir/$file $!"; open (TEMP, "$source_dir/$file.tmp" || die "unable to open $source_dir/$file.tmp $!; while (<IN>) { s/^.*Mina olen.{1561}//s; #/s allows "." to match newline #I'm not sure that it is needed here. print TEMP $_; } close TEMP || die "$!"; #unlikely to fail (file is "open") close IN || die "$!"; unlink ("$source_dir/$file") || die "$!"; rename ("$source_dir/$file.tmp", "$source_dir/$file") || die "$!"; }

In reply to Re: Removing a chunk of HTML? by Marshall
in thread Removing a chunk of HTML? by Anonymous Monk

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.