in reply to Between-text range operator problem

if ((/$beg/ .. /$end/) or (/$beg/ .. eof())) {
That's close. You want instead:
if (/$beg/ .. (/$end/ || eof())) { ... }

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: •Re: Between-text range operator problem--eof() HELL
by jlongino (Parson) on May 18, 2002 at 00:55 UTC
    Well, chalk one up for shaving serendipities. This morning while I was shaving, I had a flash--maybe I should've explicitly used eof(INFILE) instead of eof(). Unfortunately, I didn't have time to test it until I got home from work this evening.

    Both of the following will work:

    if (/$beg/ .. (/$end/ || eof )) { ... } if (/$beg/ .. (/$end/ || eof(INFILE) )) { ... }
    but the original will not: if (/$beg/ .. (/$end/ || eof() )) { ... } After figuring this out, I checked a few resources (the best explanation came from perlfunc eof):
    An eof without an argument uses the last file read as argument. Using eof() with empty parentheses is very different. It indicates the pseudo file formed of the files listed on the command line, i.e., eof() is reasonable to use inside a while (<>) loop to detect the end of only the last file.
    Obvously, I made some faulty assumptions as to how eof() works. Given how seldom I've actually used eof, I should've checked the docs when I first encountered the "freeze-up" problem.

    --Jim

Re: •Re: Between-text range operator problem
by jlongino (Parson) on May 17, 2002 at 02:13 UTC
    Thanks for replying merlyn. Actually, this is one of the variations I tried, but it goes into an infinite loop in the first file after hitting the range statement on the fourth iteration (I believe when the successful /$end/ match occurs).

    --Jim