[31760] in Perl-Users-Digest
Perl-Users Digest, Issue: 3023 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 8 18:09:30 2010
Date: Thu, 8 Jul 2010 15:09:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 8 Jul 2010 Volume: 11 Number: 3023
Today's topics:
debug code with system command exec other perl files <imiten@yahoo.com>
Re: debug code with system command exec other perl file <Peter@PSDT.com>
Re: FAQ 5.38 Why does Perl let me delete read-only file <nospam-abuse@ilyaz.org>
Re: how to pass a function name to a function, and have <nick@maproom.co.uk>
Re: how to pass a function name to a function, and have <uri@StemSystems.com>
Re: how to pass a function name to a function, and have <tzz@lifelogs.com>
Re: How to use $string=~s/(whatever)/${$i}/; with stric sln@netherlands.com
Re: who stole my returned list? <marc.girod@gmail.com>
Re: who stole my returned list? <marc.girod@gmail.com>
Re: who stole my returned list? <marc.girod@gmail.com>
Re: who stole my returned list? <marc.girod@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 8 Jul 2010 05:43:32 -0700 (PDT)
From: miten <imiten@yahoo.com>
Subject: debug code with system command exec other perl files
Message-Id: <f1dddc4b-bd42-4527-bad5-cfc03d81e650@7g2000prh.googlegroups.com>
Hi,
is there way we can debug code including those perl files which might
be exec with system command.
i have code which is like:
main.pl
---------
#....some code
system("other.pl");
I want to set break points in other.pl. In fact other.pl loads other
module like someother:submodule:subr and would like to set break point
in subr which is called from exec other.pl.
Regards,
Miten.
------------------------------
Date: Thu, 08 Jul 2010 14:22:53 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: debug code with system command exec other perl files
Message-Id: <1blZn.8321$Hw.1958@newsfe10.iad>
On Thu, 08 Jul 2010 05:43:32 -0700, miten wrote:
> Hi,
>
> is there way we can debug code including those perl files which might be
> exec with system command.
>
> i have code which is like:
>
> main.pl
> ---------
> #....some code
> system("other.pl");
>
> I want to set break points in other.pl. In fact other.pl loads other
> module like someother:submodule:subr and would like to set break point
> in subr which is called from exec other.pl.
system("$^X -d other.pl");
--
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/
------------------------------
Date: Wed, 7 Jul 2010 22:41:49 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl?
Message-Id: <slrni3a0ld.3kp.nospam-abuse@powdermilk.math.berkeley.edu>
On 2010-07-07, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> POSIX cares only about the behaviour of the unlink call, not the
> implementation. However, on most systems at least part of the
> implementation is filesystem specific and it has been common for Unix
> systems to provide both filesystems with POSIX semantics (UFS, FFS, ...)
> and without (full) POSIX semantics (NFS, ...). So you could never say
> "the unlink function on HP-UX 8.0 is POSIX-conforming", you could only
> say "the unlink function of HP-UX 8.0 on a UFS file system with default
> options is POSIX conforming, but the unlink function of HP-UX 8.0 on an
> NFS file system is not". So it makes sense to view this as a property of
> the file system code, not the OS as a whole. On modern systems this is
> even more pronounced because they support more file systems.
OK, lemme try to split this hair more precisely now. For me,
"properties of filesystem" is what is preserved when you carry a
DASD=disk to another computer (or boot to another OS).
Thanks for the nice discussion of details,
Ilya
------------------------------
Date: Wed, 7 Jul 2010 16:39:55 +0100
From: Nick Wedd <nick@maproom.co.uk>
Subject: Re: how to pass a function name to a function, and have it call it
Message-Id: <BtHD2KWL$JNMFAgz@maproom.demon.co.uk>
In message <5ln736t8j5kh76tsa3jbg5smm8ckki4fm4@4ax.com>, Jürgen Exner
<jurgenex@hotmail.com> writes
>Nick Wedd <nick@maproom.co.uk> wrote:
>[...]
>>Now I would like to generalise it, to work for subroutines other than
>>'arc'. I can promise that their first two arguments will be the 'from'
>>point and the 'to' point, I can't promise anything about the other
>>arguments. So I want to do something like
>>
>> sub polyanything {
>> my ( $displist, $from, $to, $functionname, @rest ) = @_;
>> foreach my $d ( @$displist ) {
>> CALL $functionname( add($from,$d), add($to,$d), @rest );
>> }
>> }
>>
>>but, how do I do CALL? I have found googling for "Perl function call"
>>unhelpful, as you might expect.
>
>While from a technical point of view this is possible, in general it is
>A Very Bad Idea(TM).
>A much, much better approach would be using references, dispatch tables,
>and if applicable even closures.
My thanks to everyone who answered.
Passing a reference to a function with \& , as recommended by Peter
Makholm and Sherm Pendley, is what I was looking for. I have
implemented it and it works.
I had not intended to use symbolic references. They seem to have
something in common with 'eval', so I realise that I would do best to
avoid them.
I have ordered myself a copy of Dominus' book 'Higher-Order Perl'. I
will learn from it what a dispatch table is. Maybe I will even get my
brain round closures at last.
Nick
--
Nick Wedd nick@maproom.co.uk
------------------------------
Date: Wed, 07 Jul 2010 11:54:50 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: how to pass a function name to a function, and have it call it
Message-Id: <87sk3vgud1.fsf@quad.sysarch.com>
>>>>> "NW" == Nick Wedd <nick@maproom.co.uk> writes:
NW> I had not intended to use symbolic references. They seem to have
NW> something in common with 'eval', so I realise that I would do best to
NW> avoid them.
symrefs aren't directly related to eval but they share the same evil
nature as they can be nasty and dangerous. the rule is use them only
when they are the only or very best solution. they should never be a
first resort if possible (which is what newbies tend to do)
NW> I have ordered myself a copy of Dominus' book 'Higher-Order Perl'.
NW> I will learn from it what a dispatch table is. Maybe I will even
NW> get my brain round closures at last.
dispatch tables have been covered in this newsgroup many many
times. google for that term and you will learn them quickly. they are a
very simple construct - basically a hash with names of ops for keys and
code refs as values. you get the code ref out when you have an op name,
and if it is there, call it. or handle an unknown name with a default
call or error.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Wed, 07 Jul 2010 11:43:16 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: how to pass a function name to a function, and have it call it
Message-Id: <87630rxmxn.fsf@lifelogs.com>
On Wed, 7 Jul 2010 16:39:55 +0100 Nick Wedd <nick@maproom.co.uk> wrote:
NW> I have ordered myself a copy of Dominus' book 'Higher-Order Perl'. I
NW> will learn from it what a dispatch table is. Maybe I will even get my
NW> brain round closures at last.
HOP is a complex book by any standard so I wouldn't recommend it to
learn about dispatch tables or closures (both are basic programming
concepts). You'll get lost quickly.
Ted
------------------------------
Date: Thu, 08 Jul 2010 11:24:31 -0700
From: sln@netherlands.com
Subject: Re: How to use $string=~s/(whatever)/${$i}/; with strict ref?
Message-Id: <3s4c36ho6vg864gh9sdll5h90qn27ct3pr@4ax.com>
On Fri, 2 Jul 2010 23:31:15 +0100, Ben Morrow <ben@morrow.me.uk> wrote:
>
>Quoth yjnnhauhht <yjnnhauhht@mailinator.com>:
>> On Jul 2, 3:390m, yjnnhauhht <yjnnhau...@mailinator.com> wrote:
>> > On Jul 2, 12:23!m, Big and Blue <N...@dsl.pipex.com> wrote:
>> > > On 07/01/10 17:29, Tad McClellan wrote:
>> >
>> > > > $string=~s/(test)/test/;
>> >
>> > > > I smell an XY-problem.
>> >
>> > > > What is it that you are actually trying to accomplish?
>> >
>> > > Is it, by chance:
>> >
>> > > my $i=1;
>> > > my $string="teststring";
>> > > $string=~s/(?<test>test)/$+{test}/;
>> > > print "$string\n";
>> >
>> > This doesn't solve my issue, cause I need to do the thing in a for
>> > loop where the $i is incremented.
>> > Thanks for your time though.
>>
>> Well what I really want to do is some kind of "highlighting grep -E"
>> which highlights the part of the match pattern that is inside ().
>> For example if I do mygrep "...\w*(test)..." file, I get the lines
>> matching the pattern and the word test is highlighted.
>> To do this I have to add a highligth/nohighligth control string before
>> and after each () group.
>> I though I will be able to do this in one regex, but failed and only
>> found a solution where I need to iterate on the () groups and do the
>> s/.../$i/ I ask you about.
>
>Well, now that you've *said* so...
>
> my $str = "1a:23b:4c";
>
> while ($str =~ /(\d+)(\w+)/g) {
> my $added = 0;
> for (1..$#+) {
> substr $str, $-[$_] + $added, 0, "[";
> $added++;
> substr $str, $+[$_] + $added, 0, "]";
> $added++;
> }
> pos($str) = $+[-1] + $added;
> }
>
>Ben
This approach is too simple. It won't handle nested groups;
/((\d+)(\w+))/ for example.
Then again, a more complex method that handles nesting
runs up against the indeterminate configuration;
'asdf' =~ /((X?))asdf/
'asdf' =~ /(X?)(Y?)asdf/
prodcing:
@- 0 0 0 0
@+ 4 0 0 4
The solution is to exclude empty capture groups.
I'd be curious if anyone else knows a simpler workable method other
than the below code (that works on nested groups).
-sln
---------------------------
use strict;
use warnings;
#
# This works for nested groups (but too complex)
#
my $str = "1aw23b:4c";
while ($str =~ /(\d+)[a-z]*(([a-z])(:?))/g)
{
my $newpos = pos($str);
my @B = @-;
my @E = @+;
my $numgrps = $#B;
for my $grp (1 .. $numgrps)
{
next if ($B[$grp] == $E[$grp]);
my $i;
##
my $curBpos = $B[$grp];
substr $str, $curBpos, 0, '[';
for $i ($grp .. $numgrps) {
++$B[$i] if ( $B[$i] >= $curBpos );
}
for $i ($grp .. $numgrps) {
++$E[$i] if ( $E[$i] >= $curBpos );
}
##
my $curEpos = $E[$grp];
substr $str, $curEpos, 0, ']';
for $i ($grp .. $numgrps) {
++$B[$i] if ( $B[$i] >= $curEpos );
}
for $i ($grp .. $numgrps) {
++$E[$i] if ( $E[$i] >= $curEpos );
}
$newpos += 2;
}
pos($str) = $newpos;
}
print $str,"\n";
#
# This does NOT work for nested groups (too simple)
#
$str = "1aw23b:4c";
while ($str =~ /(\d+)[a-z]*(([a-z])(:?))/g) {
my $added = 0;
for (1..$#+) {
next if ($-[$_] == $+[$_]);
substr $str, $-[$_] + $added, 0, "[";
$added++;
substr $str, $+[$_] + $added, 0, "]";
$added++;
}
pos($str) = $+[-1] + $added;
}
print $str,"\n";
__END__
[1]a[[w]][23][[b][:]][4][[c]]
[1]a[w[]][23][b[:][]][4][c[]]
------------------------------
Date: Wed, 7 Jul 2010 10:22:01 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: who stole my returned list?
Message-Id: <63a74604-9775-4cbc-8623-2648a39dcf14@u7g2000yqm.googlegroups.com>
I am back to my problem...
On Jun 24, 12:49=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:
> I'll run the same under an other perl...
I tried with perl 5.10.0 (until now, it was 5.8.8), and got a similar
behaviour, albeit as it seems, with destructors called later (?!).
In my case, this makes the trace simpler:
ClearCase::SyncTree::_lsco(/vobs/atcctest/ClearCase-SyncTree/blib/lib/
ClearCase/SyncTree.pm:214):
214: return sort keys %co;
DB<4> x %co
0 '/view/emagiro_86/vobs/atcctest/foo/d'
1 1
DB<5> t
Trace =3D on
DB<5> r
scalar context return from ClearCase::SyncTree::_lsco: undef
main::(blib/script/synctree:321): exit $rc unless $mod;
DB<5> x $mod
main::((eval 43)[/vobs/cello/cade_A_tools_perl/lib/5.10.0/perl5db.pl:
638]:2):
2: $mod;
0 undef
This is the return from the _lsco member function, which gets assigned
to $mod.
I would expect a defined value of 1.
Am I wrong?
Marc
------------------------------
Date: Wed, 7 Jul 2010 10:57:50 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: who stole my returned list?
Message-Id: <abb4b5b1-69da-44d5-a422-96cbcca19a57@k39g2000yqd.googlegroups.com>
On Jul 7, 6:22=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:
> Am I wrong?
Yes, but why?
I reproduced it:
$ cat foo
#!/usr/bin/perl -w
sub foo {
my %co =3D (a=3D>1, b=3D>2);
return sort keys %co;
}
my $mod =3D foo || foo || foo || foo;
print "$mod\n";
$ perl -d ./foo
Loading DB routines from perl5db.pl version 1.3
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(./foo:8): my $mod =3D foo || foo || foo || foo;
DB<1> c 5
main::foo(./foo:5): return sort keys %co;
DB<2> r
scalar context return from main::foo: undef
main::foo(./foo:4): my %co =3D (a=3D>1, b=3D>2);
DB<2> q
$
This works without 'sort'...
Marc
------------------------------
Date: Wed, 7 Jul 2010 11:11:16 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: who stole my returned list?
Message-Id: <bc8dedcc-89cc-4d05-a457-dae6e08aba49@j4g2000yqh.googlegroups.com>
On Jul 7, 6:57=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:
> This works without 'sort'...
or like this:
sub foo {
my %co =3D (a=3D>1, b=3D>2);
my @ret =3D sort keys %co;
return @ret;
}
Marc
------------------------------
Date: Thu, 8 Jul 2010 01:32:47 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: who stole my returned list?
Message-Id: <60834549-cadb-44f4-9843-d156e09e1102@j8g2000yqd.googlegroups.com>
On Jul 7, 7:11=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:
I was pointed the documentation (which I had failed to read well
enough--embarrassing as this is the first paragraph):
In list context, this sorts the LIST and returns the sorted list
value. In scalar context, the behaviour of "sort()" is undefined.
OK. Now I know that 'undefined' may mean 'stack corruption'.
Cave canem... er, caveat emptor, I meant.
The fix is thus:
return wantarray? sort keys %co : scalar keys %co;
Marc
------------------------------
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 3023
***************************************