die alias

Discussion in 'Perl Misc' started by George Bouras, Mar 21, 2013.

  1. I want to to have my die, the following does not work


    use strict;
    use warnings;
    sub die;

    die "oups";

    sub die {
    print "There was a problem : $_[0]\n";
    }
    George Bouras, Mar 21, 2013
    #1
    1. Advertising

  2. George Bouras <> wrote:
    >I want to to have my die, the following does not work


    "Does not work" is about the worst problem description imaginable.
    Do you also walk into a garage and say just "My car doesn't work" and
    expect the mechanic to fix whatever problem there is without even
    telling him what the problem is?

    You provided code, well, that's one step in the right direction.

    But you should always also describe what you expected the code to do and
    what behaviour you observed instead.

    Without that the mechanic may fix the rattling ash tray without ever
    noticing the leaking radiator simply because you didn't tell him about
    it.

    jue
    Jürgen Exner, Mar 21, 2013
    #2
    1. Advertising

  3. George Bouras

    J. Gleixner Guest

    On 03/21/13 10:38, George Bouras wrote:
    > I want to to have my die, the following does not work
    >
    >
    > use strict;
    > use warnings;
    > sub die;
    >
    > die "oups";
    >
    > sub die {
    > print "There was a problem : $_[0]\n";
    > }


    You might find this useful:
    http://www.effectiveperlprogramming.com/blog/1310
    J. Gleixner, Mar 21, 2013
    #3
  4. George Bouras

    Justin C Guest

    On 2013-03-21, George Bouras <> wrote:
    > I want to to have my die, the following does not work
    >
    >
    > use strict;
    > use warnings;


    BEGIN {
    *CORE::GLOBAL::die = sub {
    print "There was a problem : $_[0]\n";
    }

    > die "oups";



    But is it a good idea?


    Justin.

    --
    Justin C, by the sea.
    Justin C, Mar 21, 2013
    #4
  5. George Bouras <>
    writes:
    > I want to to have my die, the following does not work
    >
    >
    > use strict;
    > use warnings;
    > sub die;
    >
    > die "oups";
    >
    > sub die {
    > print "There was a problem : $_[0]\n";
    > }


    The short answer is

    *CORE::GLOBAL::die = sub { print "There was a problem : $_[0]\n"; }

    more details are in the CORE manpage ('perldoc CORE').
    Rainer Weikusat, Mar 21, 2013
    #5
  6. Rainer Weikusat <> writes:
    > George Bouras <>
    > writes:
    >> I want to to have my die, the following does not work
    >>
    >>
    >> use strict;
    >> use warnings;
    >> sub die;
    >>
    >> die "oups";
    >>
    >> sub die {
    >> print "There was a problem : $_[0]\n";
    >> }

    >
    > The short answer is
    >


    BEGIN {
    > *CORE::GLOBAL::die = sub { print "There was a problem : $_[0]\n"; }

    }
    Rainer Weikusat, Mar 21, 2013
    #6
  7. George Bouras

    C.DeRykus Guest

    On Thursday, March 21, 2013 8:38:52 AM UTC-7, George Bouras wrote:
    > I want to to have my die, the following does not work
    >
    >
    >
    >
    >
    > use strict;
    >
    > use warnings;
    >
    > sub die;
    >
    >
    >
    > die "oups";
    >
    >
    >
    > sub die {
    >
    > print "There was a problem : $_[0]\n";
    >
    > }


    Does "not work" refer to the warning:

    Ambiguous call resolved as CORE::die(), qualify as such or use & at die.pl line 8.
    oops at die.pl line 8.

    Add 'use diagnostics' for further info.

    --
    Charles DeRykus
    C.DeRykus, Mar 21, 2013
    #7
  8. I must also a print alias; the same method does not work.


    #!/usr/bin/perl
    use strict;
    use warnings;

    BEGIN {
    *CORE::GLOBAL::die = \&error;
    *CORE::GLOBAL::print = \&NotifyAll
    };

    die "oups";

    sub error { print "There was a problem : $_[0]" }
    sub NotifyAll { CORE::print ">>$_[0]<<"; }
    George Mpouras, Mar 21, 2013
    #8
  9. There is no other way. It is a apache xml interface between different
    systems , where some existing 3rd party code must wraped and run as it is to
    send back messages
    George Mpouras, Mar 21, 2013
    #9
  10. > BEGIN { *CORE::GLOBAL::die = sub { ... } };

    is great, can we make it work with print also ?
    George Mpouras, Mar 21, 2013
    #10
  11. George Bouras

    Keith Keller Guest

    On 2013-03-21, George Mpouras <> wrote:
    > There is no other way.


    Whenever I think this is true, I usually stop for a moment and try to
    figure out whether it's actually true. It almost always ends up false.

    In this case, did you look into $SIG{__DIE__} as others have suggested?
    perldoc -f die and perldoc perlvar (search for __DIE__) for details.

    --keith

    --
    -francisco.ca.us
    (try just my userid to email me)
    AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
    see X- headers for PGP signature information
    Keith Keller, Mar 21, 2013
    #11
  12. perldoc -f die and perldoc perlvar (search for __DIE__) for details.

    die is solved . Now I have to solve the print alias
    George Mpouras, Mar 21, 2013
    #12
  13. dead end here
    George Mpouras, Mar 21, 2013
    #13
  14. George Bouras

    J. Gleixner Guest

    On 03/21/13 17:01, George Mpouras wrote:
    > perldoc -f die and perldoc perlvar (search for __DIE__) for details.
    >
    > die is solved . Now I have to solve the print alias


    How many times are you going to post that?? Once is enough...


    http://lmgtfy.com/?q=perl override print

    I didn't really read about Devel::UncheckedOps because I'd never go that
    route.

    But seriously, it's going way beyond *normal* to go this route. Maybe a
    search/replace of 'print' to 'my_print' or something simple like that
    is enough.
    J. Gleixner, Mar 21, 2013
    #14
  15. Óôéò 22/3/2013 01:39, ï/ç J. Gleixner Ýãñáøå:
    > On 03/21/13 17:01, George Mpouras wrote:
    >> perldoc -f die and perldoc perlvar (search for __DIE__) for details.
    >>
    >> die is solved . Now I have to solve the print alias

    >
    > How many times are you going to post that?? Once is enough...
    >
    >
    > http://lmgtfy.com/?q=perl override print
    >
    > I didn't really read about Devel::UncheckedOps because I'd never go that
    > route.
    >
    > But seriously, it's going way beyond *normal* to go this route. Maybe a
    > search/replace of 'print' to 'my_print' or something simple like that
    > is enough.



    # the following is doing the job



    package IO::Override;
    use strict;
    use warnings;
    use base qw<Tie::Handle>;
    use Symbol qw<geniosym>;

    sub TIEHANDLE { return bless geniosym, __PACKAGE__ }
    tie *PRINTOUT, 'IO::Override';
    our $OLD_STDOUT = select( *PRINTOUT );

    sub PRINT
    {
    no strict;
    shift;

    my $var = $_[0] +1 ;

    CORE::print $OLD_STDOUT ">>$var<<\n";
    }



    print 99;
    George Mpouras, Mar 22, 2013
    #15
  16. #simpler ,but there is no reason any more, the "remote" guy agreed to
    use a printcustom




    use strict;
    use warnings;

    tie *PRINTOUT, 'main';
    sub TIEHANDLE { return bless {}, 'main' }

    my $NORMALPRINT = select( *PRINTOUT );


    sub PRINT
    {
    shift;
    no strict;
    print $NORMALPRINT ">>$_[0]<<\n";
    }

    print 'hello';
    George Mpouras, Mar 22, 2013
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Nilsson

    Assign program result or die

    Martin Nilsson, Jul 15, 2004, in forum: Perl
    Replies:
    1
    Views:
    503
    Jürgen Exner
    Jul 15, 2004
  2. daniel kaplan

    die question

    daniel kaplan, Sep 14, 2004, in forum: Perl
    Replies:
    2
    Views:
    514
    Sherm Pendley
    Sep 14, 2004
  3. Lloyd Sheen

    Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    403
    Natty Gur
    Jan 26, 2004
  4. Lloyd Sheen

    More Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    422
    Alvin Bruney
    Jan 25, 2004
  5. grocery_stocker
    Replies:
    9
    Views:
    727
    grocery_stocker
    May 24, 2008
Loading...

Share This Page