Again, please use <code> tags and read How do I post a question effectively?
I have found strict to be very helpful to identifying and avoiding bugs in my code -- see Use strict warnings and diagnostics or die. If I were going to write your posted code, it might look more like:
use strict;
use warnings;
open (my $out, ">", "Results.txt") or die ("Could not open file Result
+s.txt; $!");
open (my $in, "<", "Textfile.txt") or die ("Can not open input file: $
+!");
local $/;
while (<$in>) {
if (/(web site.{250})/i) {
print $out $1;
}
}
Changes that I made include:
- I swapped to lexical file handles and 3 argument open, which are considered better practice for a number of reasons. See perlopentut. In particular, this gives strict more power to help and removes the need for explicit close.
- I corrected inconsistency between your file name and error message; file names are generally case sensitive.
- I swapped to slurp mode using $/. Given the large number of characters you are interested in, it is unlikely they will all fall on the same line.
- Your while(<>) loop read data into $_ not $ARG, so I corrected that.
- I swapped your regular expression to the regular expression I posted above, with the addition of the s modifier. This makes it so . also matches new lines, and is essential when working in slurp mode.
You may consider going to http://learn.perl.org to gather some learning resources before trying to run too far.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.