[31580] in Perl-Users-Digest
Perl-Users Digest, Issue: 2839 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 27 18:09:27 2010
Date: Sat, 27 Feb 2010 15:09:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 27 Feb 2010 Volume: 11 Number: 2839
Today's topics:
*main::exit = sub {die @_,"\n"} (was: eval exit/exec) <marc.girod@gmail.com>
Re: *main::exit = sub {die @_,"\n"} (was: eval exit/exe <marc.girod@gmail.com>
Re: eval exit/exec (was: macros: return or exit) <marc.girod@gmail.com>
Re: eval exit/exec (was: macros: return or exit) <marc.girod@gmail.com>
Re: eval exit/exec (was: macros: return or exit) <ben@morrow.me.uk>
Re: eval exit/exec (was: macros: return or exit) <ben@morrow.me.uk>
Re: eval exit/exec (was: macros: return or exit) <marc.girod@gmail.com>
Re: eval exit/exec <marc.girod@gmail.com>
Re: eval exit/exec <marc.girod@gmail.com>
Re: eval exit/exec <ben@morrow.me.uk>
Re: Requesting regular expression help sln@netherlands.com
Re: Requesting regular expression help sln@netherlands.com
Re: Requesting regular expression help <hjp-usenet2@hjp.at>
Re: Requesting regular expression help <tadmc@seesig.invalid>
Re: Requesting regular expression help <ben@morrow.me.uk>
Re: Requesting regular expression help <jurgenex@hotmail.com>
Re: UDP receive <aku@bluewin.ch>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 27 Feb 2010 11:48:55 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: *main::exit = sub {die @_,"\n"} (was: eval exit/exec)
Message-Id: <d5d04024-d09c-43e2-b05d-dc28961654ab@e23g2000yqd.googlegroups.com>
On Feb 27, 7:33=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:
> ClearCase::Wrapper::CODE(0x1ae0ab8)(/cygdrive/o/atcctest/ClearCase-
> Wrapper/blib/lib/ClearCase/Wrapper.pm:119):
> 119: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0next unless eval "exi=
sts \&$tglob";
Oh! Now I understood how '$DB::single =3D 1' works!
So, I could 'put a breakpoint' there.
DB<1> x %names
0 '__ANON__[/usr/lib/perl5/site_perl/5.10/ClearCase/Wrapper/DSB.pm:
13]'
1 *ClearCase::Wrapper::DSB::__ANON__[/usr/lib/perl5/site_perl/5.10/
ClearCase/Wrapper/DSB.pm:13]
2 'lock'
3 *ClearCase::Wrapper::DSB::lock
...
68 'update'
69 *ClearCase::Wrapper::DSB::update
ClearCase::Wrapper::CODE(0x1960c08)(/cygdrive/o/atcctest/ClearCase-
Wrapper/blib/lib/ClearCase/Wrapper.pm:120):
120: next unless eval "exists \&$tglob";
DB<2> p $_
__ANON__[/usr/lib/perl5/site_perl/5.10/ClearCase/Wrapper/DSB.pm:13]
DB<3> s
BEGIN not safe after errors--compilation aborted at /usr/lib/
perl5/5.10/Carp/Heavy.pm line 11.
Compilation failed in require at /usr/lib/perl5/5.10/Carp.pm line 33.
Attempt to reload Carp/Heavy.pm aborted.
Compilation failed in require at /usr/lib/perl5/5.10/Carp.pm line 33.
...
I hope I don't bore you...
Marc
------------------------------
Date: Sat, 27 Feb 2010 12:22:18 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: *main::exit = sub {die @_,"\n"} (was: eval exit/exec)
Message-Id: <ed4937aa-8b34-4e6c-bbdc-ffb4711224c7@b30g2000yqd.googlegroups.com>
On Feb 27, 7:48=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:
> > 119: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0next unless eval "e=
xists \&$tglob";
It would seem that this problem vanishes
(and leaves place to the original one) if
I change the syntax into either of:
next unless exists &{$tglob};
next unless eval { exists &{$tglob} };
Again I am not quite sure I am not also
changing the semantics... but under the
debugger, it looks like doing what I
understood was intended.
But as I said, I am only back to:
ClearCase-Wrapper> perl -Mblib blib/script/cleartool.plx des -s foo
Subroutine main::exit redefined at /usr/lib/perl5/site_perl/5.10/
ClearCase/Argv.pm line 21.
Subroutine main::exec redefined at /usr/lib/perl5/site_perl/5.10/
ClearCase/Argv.pm line 22.
foo
Marc
------------------------------
Date: Sat, 27 Feb 2010 10:44:30 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: eval exit/exec (was: macros: return or exit)
Message-Id: <b697ca52-be42-4dcc-abfb-7423fffbec9f@t23g2000yqt.googlegroups.com>
On Feb 25, 8:12=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> No... not unless you call ->exit as a method on a subclass. The
> builtin-override logic just looks in the current package, and
> CORE::GLOBAL::.
OK... Week-end, so I am back to my home work.
I set in the ClearCase::Argv.pm package (among
others...):
BEGIN {
if ($ENV{CLEARTOOL_PLX_LOOP}) {
package ClearCase::Argv;
*main::exit =3D sub { die @_, "\n" };
*main::exec =3D sub { die system(@_), "\n" };
}
}
This package does an 'exit' as part of its own
implementation of an 'exec' member.
I hope this 'ClearCase::Argv::exec' would not
collide with the 'main::exec' which we are
overriding here?
Well, I get errors:
BEGIN not safe after errors--compilation aborted at /usr/lib/
perl5/5.10/Carp/Heavy.pm line 11.
Compilation failed in require at /usr/lib/perl5/5.10/Carp.pm line 33.
Attempt to reload Carp/Heavy.pm aborted.
Compilation failed in require at /usr/lib/perl5/5.10/Carp.pm line 33.
Attempt to reload Carp/Heavy.pm aborted.
...
I read perldebug and set PERLDB_OPTS=3DAutoTrace
prior to starting my debug session.
This gives among the (long) output an indication
that the errors relate indeed to my change:
...
ClearCase::Argv::CODE(0x1f267b8)(/usr/lib/perl5/site_perl/5.10/
ClearCase/Argv.pm:19):
19: if ($ENV{CLEARTOOL_PLX_LOOP}) {
20: package ClearCase::Argv;
ClearCase::Argv::CODE(0x1f267b8)(/usr/lib/perl5/site_perl/5.10/
ClearCase/Argv.pm:21):
21: *main::exit =3D sub { die @_, "\n" };
Attempt to reload Carp/Heavy.pm aborted.
Compilation failed in require at /usr/lib/perl5/5.10/Carp.pm line 33.
ClearCase::Argv::CODE(0x1f267b8)(/usr/lib/perl5/site_perl/5.10/
ClearCase/Argv.pm:22):
22: *main::exec =3D sub { die system(@_), "\n" };
Attempt to reload Carp/Heavy.pm aborted.
Compilation failed in require at /usr/lib/perl5/5.10/Carp.pm line 33.
ClearCase::Argv::CODE(0x1f1b150)(/usr/lib/perl5/site_perl/5.10/
ClearCase/Argv.pm:26):
...
And I am lost again...
Marc
P.S. Why must I specify the package in the BEGIN block?
Or must I? On my command line test, it does seem so...
------------------------------
Date: Sat, 27 Feb 2010 10:56:22 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: eval exit/exec (was: macros: return or exit)
Message-Id: <9491d68e-4bbd-4218-849c-742e09140d4e@f35g2000yqd.googlegroups.com>
On Feb 27, 6:44=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:
> Well, I get errors:
That is... without the debugger, the errors I get are:
$ perl -Mblib blib/script/cleartool.plx des -s foo
Subroutine main::exit redefined at /usr/lib/perl5/site_perl/5.10/
ClearCase/Argv.pm line 21.
Subroutine main::exec redefined at /usr/lib/perl5/site_perl/5.10/
ClearCase/Argv.pm line 22.
Name "DB::single" used only once: possible typo at blib/script/
cleartool.plx line 9, <GEN1> line 16.
foo
Let's say that 'foo' is the expected output.
Only, it is here followed with a standard exit,
so that no following input is read with:
$ cat <<eot | perl -Mblib blib/script/cleartool.plx
des -s foo
des -s bar
Marc
------------------------------
Date: Sat, 27 Feb 2010 21:06:07 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: eval exit/exec (was: macros: return or exit)
Message-Id: <v2eo57-u6k1.ln1@osiris.mauzo.dyndns.org>
Quoth Marc Girod <marc.girod@gmail.com>:
> On Feb 25, 8:12 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>
> > No... not unless you call ->exit as a method on a subclass. The
> > builtin-override logic just looks in the current package, and
> > CORE::GLOBAL::.
>
> OK... Week-end, so I am back to my home work.
> I set in the ClearCase::Argv.pm package (among
> others...):
>
> BEGIN {
> if ($ENV{CLEARTOOL_PLX_LOOP}) {
> package ClearCase::Argv;
> *main::exit = sub { die @_, "\n" };
> *main::exec = sub { die system(@_), "\n" };
> }
> }
I don't understand what you are trying to acheive here. What the code
above will actually do is: any code compiled in package 'main' after the
BEGIN block runs, that calls 'exit' or 'exec', will call your custom
subs instead. Is that what you meant? (Exporting into a specific package
like that is usually a very mad idea. What if your caller isn't main::
but some other package?)
> This package does an 'exit' as part of its own
> implementation of an 'exec' member.
> I hope this 'ClearCase::Argv::exec' would not
> collide with the 'main::exec' which we are
> overriding here?
When you say 'member' you mean 'method', or perhaps 'function'? Method
calls to ClearCase::Argv->exec won't be affected. Calls to 'exit' or
'exec' from within the ClearCase::Argv package won't be affected, they
will call the builtin as usual.
> P.S. Why must I specify the package in the BEGIN block?
> Or must I? On my command line test, it does seem so...
Overrides of builtins must be imported while in another package, in an
attempt to stop you doing it accidentally. That is,
package Foo;
*main::exec = sub {...};
will be recognized as an override while in package main, but
package main;
*exec = sub {...};
won't. Since I presume your module starts with
package ClearCase::Argv;
you shouldn't need another package statement inside the BEGIN block.
Ben
------------------------------
Date: Sat, 27 Feb 2010 21:07:56 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: eval exit/exec (was: macros: return or exit)
Message-Id: <c6eo57-u6k1.ln1@osiris.mauzo.dyndns.org>
Quoth Marc Girod <marc.girod@gmail.com>:
> On Feb 27, 6:44 pm, Marc Girod <marc.gi...@gmail.com> wrote:
>
> > Well, I get errors:
>
> That is... without the debugger, the errors I get are:
>
> $ perl -Mblib blib/script/cleartool.plx des -s foo
> Subroutine main::exit redefined at /usr/lib/perl5/site_perl/5.10/
> ClearCase/Argv.pm line 21.
> Subroutine main::exec redefined at /usr/lib/perl5/site_perl/5.10/
> ClearCase/Argv.pm line 22.
> Name "DB::single" used only once: possible typo at blib/script/
> cleartool.plx line 9, <GEN1> line 16.
These are not errors, they are warnings. They appear to be fairly
self-explanatory...
> foo
>
> Let's say that 'foo' is the expected output.
> Only, it is here followed with a standard exit,
> so that no following input is read with:
>
> $ cat <<eot | perl -Mblib blib/script/cleartool.plx
> des -s foo
> des -s bar
That is a separate issue from the warnings, and since I haven't seen
the code I have no idea as to the cause.
Ben
------------------------------
Date: Sat, 27 Feb 2010 14:39:35 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: eval exit/exec (was: macros: return or exit)
Message-Id: <62811946-34e5-48a2-9a04-c1b4f2025832@y11g2000yqh.googlegroups.com>
On Feb 27, 9:07=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> These are not errors, they are warnings.
OK.
> They appear to be fairly self-explanatory...
Apart for the fact that in the end, the
behaviour of exit is still the original one...
So that I don't understand what was overridden.
Not what I intended...
> That is a separate issue from the warnings, and since I haven't seen
> the code I have no idea as to the cause.
*The* code?
If I check it in my Google site, will you read
it (given that you won't be able to run it as
previously explained)?
The previous version is of course already there.
It is only a matter of pushing new increments...
The site is:
http://code.google.com/p/clearcase-cpan/source/browse/#svn/branches
OK... DSB is not there yet, and even if the
changes to the versions there are small,
they are just what I am asking about.
But let's say that within cleartool.plx,
there is a 'one_cmd' function, and the
new code there looks like this:
my $rc =3D eval { $cmd->(@ARGV) };
if ($@) {
chomp $@;
$rc =3D $@;
} else {
warn "Normal return: $rc";
}
# ... and exit unless it returned zero.
return $rc;
And there is a loop a bit later such as:
my $rc;
require Text::ParseWords;
while (my $line =3D <>) {
chomp $line;
last if $line eq 'quit';
local @ARGV =3D Text::ParseWords::shellwords($line);
$rc =3D one_cmd;
}
exit $rc;
The problem so far being that in the case of 'des',
$cmd->(@ARGV) never returns or dies: it just exits.
I am sorry: I kind of believe you won't want to dig
into this in that way either.
This is a top-down way, and I believe it is not
the right way to communicate. It is the way to
avoid communications.
I believe we should be able to drive this bottom-up
which requires communications: that we understand
what prevents each other from understanding.
I don't say it is easy. I just believe it is the
only scalable way, because it depends on 'local'
complexity.
Thanks in any case,
Marc
------------------------------
Date: Sat, 27 Feb 2010 11:33:02 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: eval exit/exec
Message-Id: <6ea67e2e-42bc-49cb-9ece-cc15a65265e4@t23g2000yqt.googlegroups.com>
On Feb 27, 6:56=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:
> That is... without the debugger, the errors I get are:
And under the debugger, in my AutoTrace output,
the first error is:
ClearCase::Wrapper::CODE(0x1ae0ab8)(/cygdrive/o/atcctest/ClearCase-
Wrapper/blib/lib/ClearCase/Wrapper.pm:119):
119: next unless eval "exists \&$tglob";
BEGIN not safe after errors--compilation aborted at /usr/lib/
perl5/5.10/Carp/Heavy.pm line 11.
Compilation failed in require at /usr/lib/perl5/5.10/Carp.pm line 33.
Attempt to reload Carp/Heavy.pm aborted.
Compilation failed in require at /usr/lib/perl5/5.10/Carp.pm line 33.
This is a place in the ClearCase::Wrapper.pm code,
where it examines out of the AutoSplit modules
produced from Wrapper functions, which ones
correspond to 'commands' of the tool being
emulated:
# Now the overlay module is read in. We need to examine its
# newly-created symbol table, determine which functions
# it defined, and import them here. The same basic thing is
# done for the base package later.
my %names =3D %{"${pkg}::"};
for (keys %names) {
my $tglob =3D "${pkg}::$_";
# Skip functions that can't be names of valid cleartool ops.
next if m%^_?[A-Z]%;
# Skip typeglobs that don't involve functions. We can only
# do this test under >=3D5.6.0 since exists() on a coderef
# is a new feature. The eval is needed to avoid a compile-
# time error in <5.6.0.
if ($] >=3D 5.006) {
next unless eval "exists \&$tglob";
}
The AutoTrace transcript shows earlier 'require Carp;'
but for some reason, doesn't trace its loading,
contrarily to blib, Cwd, strict, Exporter, etc...
This only shows that I don't understand what gets traced.
Marc
------------------------------
Date: Sat, 27 Feb 2010 14:14:39 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: eval exit/exec
Message-Id: <e41ca553-d308-411a-99ed-57eaeff1b1cb@g7g2000yqe.googlegroups.com>
On Feb 27, 9:06=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> I don't understand what you are trying to achieve here. What the code
> above will actually do is: any code compiled in package 'main' after the
> BEGIN block runs, that calls 'exit' or 'exec', will call your custom
> subs instead. Is that what you meant?
I have no package explicitely named 'main',
so obviously I have misunderstood something
you wrote earlier.
Now, this makes indeed the 'redefine' errors
'self-explanatory' as you say.
Or... maybe not quite. I understood I was
redefining the meaning of a global 'exec'
in different package contexts.
> (Exporting into a specific package
> like that is usually a very mad idea.
> What if your caller isn't main::
> but some other package?)
Sorry, but what is 'main'? Is there a main?
In C, there is a 'main' symbol. It is
garanteed to be unique, in the context of
every program. This is what I understood.
In fact, I would still believe this is OK.
So, it is now that I must be misunderstanding
you...
At least I don't get errors mentioning
'*main::'...
I am writing a wrapper for a command line
tool, so my caller will be 'main'...
The caller is the 'cleartool.plx' script.
> When you say 'member' you mean 'method', or perhaps 'function'? Method
> calls to ClearCase::Argv->exec won't be affected. Calls to 'exit' or
> 'exec' from within the ClearCase::Argv package won't be affected, they
> will call the builtin as usual.
'Method' is the word Smalltalk used.
'Member' (function) is the word for C++.
'Function' is the C word for something
slightly different (but called 'procedure'
in Fortran). OK, there are functions in Lisp
as well, and there are significant
differences... The terminology is very
confusing. By member, I mean a function
in the restricted namespace of a class
(aka package). In addition, I assume that it
takes a first (syntactically implicit)
argument being a reference to an instance
of the class. This aspect is irrelevant here.
> Overrides of builtins must be imported while in another package, in an
> attempt to stop you doing it accidentally. That is,
>
> =A0 =A0 package Foo;
> =A0 =A0 *main::exec =3D sub {...};
>
> will be recognized as an override while in package main, but
>
> =A0 =A0 package main;
> =A0 =A0 *exec =3D sub {...};
>
> won't. Since I presume your module starts with
>
> =A0 =A0 package ClearCase::Argv;
>
> you shouldn't need another package statement inside the BEGIN block.
I have:
- a toplevl script: cleartool.plx (the wrapper)
- a ClearCase::Wrapper module, which does
define some functions, and use exit and exec
in ways I want to override
- a ClearCase::Argv module, which is used to
implement the functions, and offers one 'exec'
among other, which itself uses exit, in a way
which I want to override
- two specialized wrapper modules:
- ClearCase::Wrapper::DSB which defines more
functions (among which the 'des' which I use
in my tests), and does use exit and exec in
ways I want to override.
- ClearCase::Wrapper::MGI of which I am the
author, and thus does *not* use exit nor
exec .
These two modules are 'discovered' dynamically
and loaded by ClearCase::Wrapper.
There could in theory be more of them.
So, my understanding is that I must override
exec and exit in at least 3 packages:
ClearCase::Argv
ClearCase::Wrapper
ClearCase::Wrapper::DSB
(and probably in a 4th one: Argv, which is used
by ClearCase::Argv).
Where do I do this, and how do I prefix the
2 names?
So far, I thought the functions I was overriding
were global main:: functions, and I had to do it
*in* every package.
Obviously, this was wrong...
Thanks
Marc
------------------------------
Date: Sat, 27 Feb 2010 22:58:20 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: eval exit/exec
Message-Id: <clko57-q8t1.ln1@osiris.mauzo.dyndns.org>
Quoth Marc Girod <marc.girod@gmail.com>:
> On Feb 27, 9:06 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>
> > I don't understand what you are trying to achieve here. What the code
> > above will actually do is: any code compiled in package 'main' after the
> > BEGIN block runs, that calls 'exit' or 'exec', will call your custom
> > subs instead. Is that what you meant?
>
> I have no package explicitely named 'main',
> so obviously I have misunderstood something
> you wrote earlier.
Perl starts in package 'main', so any code that comes before a 'package'
statement is compiled in package main. I think you perlhaps need to
review perlmod.
> Now, this makes indeed the 'redefine' errors
> 'self-explanatory' as you say.
> Or... maybe not quite. I understood I was
> redefining the meaning of a global 'exec'
> in different package contexts.
Hmmm. Not quite. A statement like
exec "one", "two";
is usually compiled as a builtin. However, if there is a sub in the
current package called 'exec', *and* that sub was exported into the
current package by a different package, then it is compiled as a call to
that sub instead.
> > (Exporting into a specific package
> > like that is usually a very mad idea.
> > What if your caller isn't main::
> > but some other package?)
>
> Sorry, but what is 'main'? Is there a main?
> In C, there is a 'main' symbol. It is
> garanteed to be unique, in the context of
> every program. This is what I understood.
No, not at all. 'main' is just the name of the default package. See
above.
> In fact, I would still believe this is OK.
> So, it is now that I must be misunderstanding
> you...
> At least I don't get errors mentioning
> '*main::'...
>
> I am writing a wrapper for a command line
> tool, so my caller will be 'main'...
> The caller is the 'cleartool.plx' script.
OK, but since you are writing this as a module you must be at least
implicitly assuming it might be used elsewhere. The usual method is to
use 'caller' in your package's 'import' method, which will tell you
which package the 'use' statement happed from:
package ClearCase::Argv;
sub import {
my $pkg = caller;
{
no strict 'refs';
*{"$pkg\::exec"} = sub { ... };
}
# whatever else you need to do
# if you want Exporter to work you can
goto &Exporter::import;
}
Since it appears you are working 'backwards', and trying to change the
behaviour of modules that aren't loaded yet, you need to explicitly
export into ClearCase::Wrapper &c.
> > When you say 'member' you mean 'method', or perhaps 'function'? Method
> > calls to ClearCase::Argv->exec won't be affected. Calls to 'exit' or
> > 'exec' from within the ClearCase::Argv package won't be affected, they
> > will call the builtin as usual.
>
> 'Method' is the word Smalltalk used.
> 'Member' (function) is the word for C++.
> 'Function' is the C word for something
> slightly different (but called 'procedure'
> in Fortran). OK, there are functions in Lisp
> as well, and there are significant
> differences... The terminology is very
> confusing. By member, I mean a function
> in the restricted namespace of a class
> (aka package). In addition, I assume that it
> takes a first (syntactically implicit)
> argument being a reference to an instance
> of the class. This aspect is irrelevant here.
OK. 'Member' is not usually used in that sense in Perl. A function call
(or sub call) looks like
foo(1, 2, 3);
or
Some::Package::foo(1, 2, 3);
The first form will look for a builtin with that name, or a 'sub foo' in
the current package. The second form will always look for a 'sub foo' in
Some::Package. A method call looks like
Some::Package->foo(1, 2);
$obj->foo(1, 2);
and will look for a 'sub foo' in Some::Package or anything it inherits
from, and call it with an implicit first argument. Method calls never
compile as builtins, so you can have a method called 'exec' with no
problems.
> > Overrides of builtins must be imported while in another package, in an
> > attempt to stop you doing it accidentally. That is,
> >
> > package Foo;
> > *main::exec = sub {...};
> >
> > will be recognized as an override while in package main, but
> >
> > package main;
> > *exec = sub {...};
> >
> > won't. Since I presume your module starts with
> >
> > package ClearCase::Argv;
> >
> > you shouldn't need another package statement inside the BEGIN block.
>
> I have:
> - a toplevl script: cleartool.plx (the wrapper)
> - a ClearCase::Wrapper module, which does
> define some functions, and use exit and exec
> in ways I want to override
> - a ClearCase::Argv module, which is used to
> implement the functions, and offers one 'exec'
> among other, which itself uses exit, in a way
> which I want to override
Is this 'exec' called as a method or a function? If it's called as a
method, or if it's always called fully-qualified, you can simply ignore
the fact it's called 'exec'.
> - two specialized wrapper modules:
> - ClearCase::Wrapper::DSB which defines more
> functions (among which the 'des' which I use
> in my tests), and does use exit and exec in
> ways I want to override.
> - ClearCase::Wrapper::MGI of which I am the
> author, and thus does *not* use exit nor
> exec .
> These two modules are 'discovered' dynamically
> and loaded by ClearCase::Wrapper.
If you wish to override CC::W's use of 'exec', this must happen *before*
CC::W is loaded. This probably means you need to switch to using a
module MGI::ClearCase, which does the overrides and *then* loads
ClearCase::Wrapper, and avoid loading CC::W in cleartool.plx.
> There could in theory be more of them.
>
> So, my understanding is that I must override
> exec and exit in at least 3 packages:
> ClearCase::Argv
> ClearCase::Wrapper
> ClearCase::Wrapper::DSB
>
> (and probably in a 4th one: Argv, which is used
> by ClearCase::Argv).
>
> Where do I do this, and how do I prefix the
> 2 names?
I would say you want something like this:
package MGI::ClearCase;
use warnings;
use strict;
my $exec = sub {...};
my $exit = sub {...};
*ClearCase::Wrapper::exec = $exec;
*ClearCase::Wrapper::exit = $exit;
# leave CC::A::exec, since it's already being redefined
*ClearCase::Argv::exit = $exit;
*ClearCase::Wrapper::DSB::exec = $exec;
*ClearCase::Wrapper::DSB::exit = $exit;
# 'require' not 'use', so it isn't loaded until after the overrides
require ClearCase::Wrapper;
# more stuff
1;
You shouldn't get any 'redefined' warnings from this; if you do, it
indicates a problem.
> So far, I thought the functions I was overriding
> were global main:: functions, and I had to do it
> *in* every package.
> Obviously, this was wrong...
No, they aren't functions (that is, Perl subs) at all, they're builtins.
They are recognised specially by the compiler, and compiled into special
ops, *unless* they have been overridden at that point.
Ben
------------------------------
Date: Sat, 27 Feb 2010 00:10:49 -0800
From: sln@netherlands.com
Subject: Re: Requesting regular expression help
Message-Id: <m5kho5tsoq6r5sdl90db1pk0rga163gu7s@4ax.com>
On Sat, 27 Feb 2010 01:02:58 -0600, Tad McClellan <tadmc@seesig.invalid> wrote:
>sln@netherlands.com <sln@netherlands.com> wrote:
>
>> one would want to block
>> against a while($var = '0') condition
>
>
>There is no need to worry about that, as it generates a rather
>clear warning message. (and all sensible Perl programmers enable warnings)
>
>:-)
>
So simple is not better.
while($var = $bar)
while(<DATA>)
>
>> Kind of odd, only if the scalar is marked undefined
>> or is the code for '0' is it false.
>
>
>The "Truth and Falsehood" section in
>
> perldoc perlsyn
>
>states rather clearly what is considered false:
>
> The number 0, the strings C<'0'> and C<''>, the empty list C<()>, and
^^^^^^
What a pity the single character '0' is valid data in while(<DATA>) :-)
Who cares about C<''>.
> C<undef> are all false in a boolean context. All other values are true.
>
>
>> Not false for '00'.
>
>
>That isn't in the list from the docs quoted above, so it is "true".
I disagree, its not false, or is that not the case for true?
>
>
>> I probably got this all wrong
>
>
>The World is astounded at such a rare occurrence!
I'm sure this is a false positive.
-sln
------------------------------
Date: Sat, 27 Feb 2010 00:50:56 -0800
From: sln@netherlands.com
Subject: Re: Requesting regular expression help
Message-Id: <mfmho5h25eacifmc2vi3e2kh86r7njvat8@4ax.com>
On Fri, 26 Feb 2010 23:36:16 -0800 (PST), "C.DeRykus" <derykus@gmail.com> wrote:
>On Feb 26, 5:57 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>> Quoth David G <dgn...@gmail.com>:
>>
>> ...
>> Anyway, something like
>>
>> s{ (<<.*?>>) | "([^"]*)" | (.) }{
>> $1 // $3 // Translate(*TRANS, $1, "GenericString")
>> }iegx;
>>
>
>Did you mean to leave the (.) alternative in the solution?
Its not really necessary. And $2 would be passed in Translate().
Could have been written like:
s{ <<.*?>>\K | "([^"]*)" }{
defined $1 and ''
}iegx;
I doesen't matter though, its too simple of an expression.
Any combination of << "asdf>>" "asdf>>" type mixing and
matching will break it. Remember, the guard is against
<< " .. " >> which I'm not so sure he didn't mean in a
balanced sence in the first place. Either way, the expression
is much more complicated.
-sln
------------------------------
Date: Sat, 27 Feb 2010 12:33:34 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Requesting regular expression help
Message-Id: <slrnhoi0of.tti.hjp-usenet2@hrunkner.hjp.at>
On 2010-02-27 08:10, sln@netherlands.com <sln@netherlands.com> wrote:
> On Sat, 27 Feb 2010 01:02:58 -0600, Tad McClellan <tadmc@seesig.invalid> wrote:
>>sln@netherlands.com <sln@netherlands.com> wrote:
>>> Kind of odd, only if the scalar is marked undefined
>>> or is the code for '0' is it false.
>>
>>
>>The "Truth and Falsehood" section in
>>
>> perldoc perlsyn
>>
>>states rather clearly what is considered false:
>>
>> The number 0, the strings C<'0'> and C<''>, the empty list C<()>, and
> ^^^^^^
> What a pity the single character '0' is valid data in while(<DATA>) :-)
Doesn't matter.
while (<FH>)
is actually a shorthand for
while (defined($_ = <FH>))
so even if the last line of a file is "0" without a trailing newline,
the loop will still be executed.
>> C<undef> are all false in a boolean context. All other values are true.
>>
>>
>>> Not false for '00'.
>>
>>
>>That isn't in the list from the docs quoted above, so it is "true".
>
> I disagree, its not false, or is that not the case for true?
What's the difference between "true" and "not false"?
hp
------------------------------
Date: Sat, 27 Feb 2010 08:40:25 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Requesting regular expression help
Message-Id: <slrnhoibfn.vng.tadmc@tadbox.sbcglobal.net>
sln@netherlands.com <sln@netherlands.com> wrote:
> On Sat, 27 Feb 2010 01:02:58 -0600, Tad McClellan <tadmc@seesig.invalid> wrote:
>>The "Truth and Falsehood" section in
>>
>> perldoc perlsyn
>>
>>states rather clearly what is considered false:
>>
>> The number 0, the strings C<'0'> and C<''>, the empty list C<()>, and
>> C<undef> are all false in a boolean context. All other values are true.
>>
>>
>>> Not false for '00'.
>>
>>
>>That isn't in the list from the docs quoted above, so it is "true".
>
> I disagree,
You cannot disagree, because it is not a matter of opinion!
It is a fact.
> its not false,
so it is an "other value" with regards to "All other values are true".
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
------------------------------
Date: Sat, 27 Feb 2010 14:42:50 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Requesting regular expression help
Message-Id: <aknn57-92i1.ln1@osiris.mauzo.dyndns.org>
Quoth "C.DeRykus" <derykus@gmail.com>:
> On Feb 26, 5:57 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth David G <dgn...@gmail.com>:
> >
> > ...
> > Anyway, something like
> >
> > s{ (<<.*?>>) | "([^"]*)" | (.) }{
> > $1 // $3 // Translate(*TRANS, $1, "GenericString")
> > }iegx;
> >
>
> Did you mean to leave the (.) alternative in the solution?
I did, but since Tad posted almost the same thing I realise it's not
necessary.
Ben
------------------------------
Date: Sat, 27 Feb 2010 08:22:10 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Requesting regular expression help
Message-Id: <6ghio5tup33o937vvhh6bkas5947p5j4ql@4ax.com>
Tad McClellan <tadmc@seesig.invalid> wrote:
>sln@netherlands.com <sln@netherlands.com> wrote:
>> I disagree,
>
>You cannot disagree, because it is not a matter of opinion!
Tad,
you may want to check whom you are replying to. sln disagrees with
everyone and everything.
>It is a fact.
Those never got in his way before, why should they now?
Just killfile him, nobody is paying attention to that troll anyway.
jue
------------------------------
Date: Sat, 27 Feb 2010 11:48:30 -0800 (PST)
From: aku <aku@bluewin.ch>
Subject: Re: UDP receive
Message-Id: <936b5d75-2dab-4129-8194-284a7613561a@g10g2000yqh.googlegroups.com>
On Feb 26, 7:07=A0am, "Uri Guttman" <u...@StemSystems.com> wrote:
> >>>>> "a" =3D=3D aku =A0<a...@bluewin.ch> writes:
>
> =A0 a> Hi, got a UDP msg with format STXdataETX (without a LF)
> =A0 a> I use this:
>
> =A0 a> use IO::Socket;
> =A0 a> my $PORT=3D'4444';
> =A0 a> $sock =3D IO::Socket::INET -> new(LocalPort =3D> $PORT, Proto =3D>=
'udp') or
> =A0 a> die "socket: $@";
> =A0 a> print "Server Mode\n";
> =A0 a> while ($sock->recv($nachricht,1024))
> =A0 a> {
> =A0 a> =A0 =A0 =A0 =A0 print "$nachricht";
> =A0 a> };
>
> =A0 a> with my incoming format STXdataETX (without a LF) it do not work; =
if I
> =A0 a> add a LF it works
> =A0 a> is there a chance to change the delimiter in the recv function fro=
m LF
> =A0 a> to ETX or are there other solutions for my program?
>
> udp does not have a delimiter and you don't need one if your message is
> always under a packet size. i would bet the issue is on the client side
> as needing a lf implies it is line buffered and isn't being flushed
> until a lf (newline) is sent. are you using print to send the packet?
> try using send() on a udp client socket and it should work.
>
> uri
>
> --
> Uri Guttman =A0------ =A0u...@stemsystems.com =A0-------- =A0http://www.s=
ysarch.com--
> ----- =A0Perl Code Review , Architecture, Development, Training, Support =
------
> --------- =A0Gourmet Hot Cocoa Mix =A0---- =A0http://bestfriendscocoa.com=
---------
Hi,
no, I use the send(). I tried all the things I can imagin. No success
*) - at least I wrote the prog again locking exact as the oldone
(ascii). Then it works fine. Think there whos a kind of a whitspace
somewhere in the $msg
*) one thing which whose running was the >>print "$nachricht$/";<<
which tell me that there is a not expected delimiter
Ok, here the newritten running prg;
use strict;
use IO::Socket;
my $serverIP =3D '192.168.1.35';
my $serverPORT=3D'4444';
my $sock =3D IO::Socket::INET -> new(Proto =3D> 'udp') or die "socket:
$@";
my $ipaddr =3D inet_aton($serverIP);
my $portaddr =3D sockaddr_in($serverPORT,$ipaddr);
my ($msg,$tre);
while (1)
{
crea_msg();
print "$msg\n";
my $lmsg =3D length($msg);
send($sock,$msg,0,$portaddr) =3D=3D $lmsg or die "send problem\n";
sleep (3);
};
exit;
sub crea_msg
{
my @t =3D localtime(time);
if ($tre > 400){$tre =3D -100} else {$tre =3D $tre + 7};
$msg =3D sprintf("\x02%04d.%02d.%02d,%02d:%02d,%d\x03",
$t[5]+1900,$t[4]+1,$t[3],$t[2],$t[1],$tre);
return;
};
thanks again
Turi
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2839
***************************************