in reply to BEGIN and END with -p or -n


"When you use the -n or -p switches to Perl, BEGIN and END work just as they do in awk"

What confuses me about this is the corollary that without -n and -p BEGIN and END don't work as they do in awk.

That is, it seems to imply that BEGIN and END work differently with -n and -p than in other cases (apart from the obvious exception of -c).

Is that the case?

--
John.

Replies are listed 'Best First'.
Re^2: BEGIN and END with -p or -n
by TimToady (Parson) on Dec 01, 2005 at 16:13 UTC
    No, they work the same. It's the rest of the code that works differently, insofar as it's not inside an implicit loop any more. BEGIN and END don't care whether they're inside a loop or not, which is why they "degenerate" to the case of awk and sed when they are in an implicit loop.
      So it seems that the statement in perlmod is extraneous, and should be cut, as BEGIN and END do what they do, regardless.

      There's no reason to mention awk, or imply a different behavior under -p or -n.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of