

Imagine we need to grab the first param from some input file.tex. We are lucky, the following works fine:

\def\do#1{<do something with #1>}
\expandafter\do\input file.tex

And what if we would like to execute \do from the file.tex level, catching the parameter that lays just
after the \input command in the outer level document?
Well, since \do requires an argument, it cannot occur at the very end of the input file.tex. We may try this:

% outer document content:
\def\do#1{#1 indeed}
\input file.tex {crazy}?\end

% file.tex content
Isn’t that
\expandafter\do\endinput

But TeX complains

! File ended while scanning use of \do

So we don't expand endinput, but the end of the file itself:

% outer document content the same as before

% file.tex content
Isn’t that
\expandafter\do

¡And this works!

The actual example is in my package makepattern, file mkpatter.tex in CTAN.
