die alias

G

George Bouras

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";
}
 
J

Jürgen Exner

George Bouras said:
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
 
R

Rainer Weikusat

George Bouras said:
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').
 
R

Rainer Weikusat

Rainer Weikusat said:
George Bouras said:
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"; }
}
 
C

C.DeRykus

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.
 
G

George Mpouras

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]<<"; }
 
G

George Mpouras

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
 
G

George Mpouras

BEGIN { *CORE::GLOBAL::die = sub { ... } };

is great, can we make it work with print also ?
 
K

Keith Keller

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
 
G

George Mpouras

perldoc -f die and perldoc perlvar (search for __DIE__) for details.

die is solved . Now I have to solve the print alias
 
J

J. Gleixner

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.
 
G

George Mpouras

Óôéò 22/3/2013 01:39, ï/ç J. Gleixner Ýãñáøå:
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;
 
G

George Mpouras

#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';
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top