Loading ...
Sorry, an error occurred while loading the content.

Redefining the behaviour of warn.

Expand Messages
  • Muttley Meen
    Hi. I have the code: $SIG{__WARN__} = sub { print $_[0]; } ; I m expecting that when i use warn WARN ; only WARN will be printed to STDERR, no other text.
    Message 1 of 4 , Jan 10, 2007
    • 0 Attachment
      Hi.

      I have the code:

      $SIG{__WARN__} = sub { print $_[0]; } ;

      I'm expecting that when i use
      warn "WARN"; only "WARN" will be printed to STDERR, no other text.
      but perl is smart to tell me the file and the line, even though I did
      not requested
      that:
      WARN at ./1.pl line 4.


      Is there a way not to print the file and the line ?


      --
      Thanks
    • merlyn@stonehenge.com
      ... Muttley Hi. Muttley I have the code: Muttley $SIG{__WARN__} = sub { print $_[0]; } ; Muttley I m expecting that when i use Muttley warn WARN ; only
      Message 2 of 4 , Jan 10, 2007
      • 0 Attachment
        >>>>> "Muttley" == Muttley Meen <muttley.meen@...> writes:

        Muttley> Hi.
        Muttley> I have the code:

        Muttley> $SIG{__WARN__} = sub { print $_[0]; } ;

        Muttley> I'm expecting that when i use
        Muttley> warn "WARN"; only "WARN" will be printed to STDERR, no other text.
        Muttley> but perl is smart to tell me the file and the line, even though I did
        Muttley> not requested
        Muttley> that:
        Muttley> WARN at ./1.pl line 4.


        Muttley> Is there a way not to print the file and the line ?

        $ perldoc -f warn
        warn LIST
        Produces a message on STDERR just like "die", but doesn't exit
        or throw an exception.
        ...
        $ perldoc -f die
        die LIST
        ...
        If the last element of LIST does not end in a newline, the
        current script line number and input line number (if any) are
        also printed, and a newline is supplied. Note that the "input
        line number" (also known as "chunk") is subject to whatever
        notion of "line" happens to be currently in effect, and is also
        available as the special variable $.. See "$/" in perlvar and
        "$." in perlvar.
        ...

        What part of that is unclear? How much of this did you look up
        before posting?

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      • Rob Biedenharn
        ... Try: warn WARN n ; And then read about why die and warn: perldoc perlfunc The entry for die explains the behavior on the ending n -Rob Rob Biedenharn
        Message 3 of 4 , Jan 10, 2007
        • 0 Attachment
          On Jan 10, 2007, at 7:23 AM, Muttley Meen wrote:

          > Hi.
          >
          > I have the code:
          >
          > $SIG{__WARN__} = sub { print $_[0]; } ;
          >
          > I'm expecting that when i use
          > warn "WARN"; only "WARN" will be printed to STDERR, no other text.
          > but perl is smart to tell me the file and the line, even though I did
          > not requested
          > that:
          > WARN at ./1.pl line 4.
          >
          >
          > Is there a way not to print the file and the line ?
          >
          >
          > --
          > Thanks

          Try:
          warn "WARN\n";

          And then read about why die and warn:
          perldoc perlfunc

          The entry for 'die' explains the behavior on the ending "\n"

          -Rob

          Rob Biedenharn http://agileconsultingllc.com
          Rob@...
        • Muttley Meen
          ... thanks
          Message 4 of 4 , Jan 10, 2007
          • 0 Attachment
            On 1/10/07, Rob Biedenharn <Rob@...> wrote:
            >
            >
            >
            > Try:
            > warn "WARN\n";
            >
            thanks
          Your message has been successfully submitted and would be delivered to recipients shortly.