in reply to Re: Here there be camels!
in thread Here there be cammels!

if you do this:
foreach(<>){ warn $_; }
you get <text> at dummy.pl line 5, <> line 6 I want to do that.

Replies are listed 'Best First'.
Re^3: Here there be camels!
by LanX (Saint) on Feb 28, 2015 at 22:27 UTC
      In the second pass the file is closed.
        warn takes a string as argument, so just add the coordinates you want.

        Just let the string end with a newline "\n" to avoid other numbers to be added automatically.

        warn "Warning at FILE.pl line 42, <> line 666.\n";

        et voila!

        Warning at FILE.pl line 42, <> line 666.

        besides:

        The example code you gave is nonsense, because foreach slurps the whole file, line-numbers are lost.

        Better use while !

        Otherwise please post code demonstrating your problem and the expected output.

        update

        If you want the first FILE and NUMBER to be the correct current ones, put your warn into a sub and use caller to get them, before constructing your string.

        Alternatively use Carp to report from the callers context.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)

        PS: Je suis Charlie!