[28435] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9799 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 3 18:05:58 2006

Date: Tue, 3 Oct 2006 15:05:06 -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           Tue, 3 Oct 2006     Volume: 10 Number: 9799

Today's topics:
    Re: catching "Use of uninitialized value" warnings <badarisj@gmail.com>
    Re: FAQ 4.68 How can I make the Perl equivalent of a C  <brian.d.foy@gmail.com>
        Locking issue with BerkeleyDB 0.30 after upgrade? <admin@asarian-host.net>
    Re: my vs our for class data <trwww@sbcglobal.net>
    Re: OS X and perldoc <justin.0610@purestblue.com>
    Re: OS X and perldoc <justin.0610@purestblue.com>
    Re: Perl Async .10 anno4000@radom.zrz.tu-berlin.de
    Re: perl flawed or my fault anno4000@radom.zrz.tu-berlin.de
    Re: perl flawed or my fault <someone@example.com>
    Re: perl flawed or my fault anno4000@radom.zrz.tu-berlin.de
    Re: perl flawed or my fault <someone@example.com>
    Re: perl flawed or my fault anno4000@radom.zrz.tu-berlin.de
    Re: perl flawed or my fault <someone@example.com>
    Re: perl flawed or my fault anno4000@radom.zrz.tu-berlin.de
    Re: Please help me pass an array from VBA to Perl and p david.f.jenkins@usa.net
    Re: problems with regex matching - invalid ranges, quan (reading news)
        Reducing dependencies when initializing Log4perl? <robb@acm.org>
    Re: this is annoying <bik.mido@tiscalinet.it>
    Re: this is annoying <mritty@gmail.com>
    Re: this is annoying anno4000@radom.zrz.tu-berlin.de
    Re: this is annoying <tadmc@augustmail.com>
    Re: this is annoying <tadmc@augustmail.com>
        Use of -i inplace option <source@netcom.com>
    Re: Use of -i inplace option <mritty@gmail.com>
    Re: Use of -i inplace option <source@netcom.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 3 Oct 2006 13:12:50 -0700
From: "badarisj@gmail.com" <badarisj@gmail.com>
Subject: Re: catching "Use of uninitialized value" warnings
Message-Id: <1159906370.818640.64740@h48g2000cwc.googlegroups.com>

hi tassilo,

thanks a lot. i didn't realize that all messages that the perl
interpreter
shows can be trapped using __WARN__ or __DIE__ sighandlers.
works well for what i want.

-badari


vparseval@gmail.com wrote:
> badarisj@gmail.com wrote:
>
> > now and then we see
> >    Use of uninitialized value in xxx
> > warning messages while running a perl program.
> >
> > is there a way to catch such warning messages that perl throws and
> > display
> > the stack that is leading to the warning message?
>
> For development purposes you can install a SIGWARN handler that will
> print a stacktrace when the warning message conforms to certain
> criteria:
>
>  #!/usr/bin/perl
>
>  use warnings;
>
>  $SIG{__WARN__} = sub {
>      if ($_[0] =~ /^Use of uninitialized value/) {
>          require Carp;
>          Carp::cluck();
>      } else {
>          warn @_;
>      }
>  };
>
>  sub foo {
>      print undef;
>  }
>
>  sub bla {
>      foo();
>  }
>
>  bla(42);
>  __END__
>   at cluck.pl line 6
>          main::__ANON__('Use of uninitialized value in print at
> cluck.pl line 13.\x{a}') called at cluck.pl line 13
>          main::foo() called at confess.pl line 17
>          main::bla(42) called at confess.pl line 20
> 
> Cheers,
> Tassilo



------------------------------

Date: Tue, 03 Oct 2006 15:50:47 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.68 How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?
Message-Id: <031020061550471668%brian.d.foy@gmail.com>

In article <021020061319477946%jgibson@mail.arc.nasa.gov>, Jim Gibson
<jgibson@mail.arc.nasa.gov> wrote:

> In article <79f7v3-9f2.ln1@blue.stonehenge.com>, PerlFAQ Server
> <brian@stonehenge.com> wrote:

> > 4.68: How can I make the Perl equivalent of a C structure/C++ class/hash or
> > array of hashes or arrays?

> "upcoming perlreftut"? It is alive and well in my Perl (5.8.6).

Will fix.

> Would there be any value in mentioning the Class::Struct module here? I
> have not used it and do not have an opinion. My uninformed opinion is
> that it is "training wheels" 

I haven't used it and have the same opinion, but I'll look at it and
see if it merits a mention.

Thanks,

-- 
Posted via a free Usenet account from http://www.teranews.com



------------------------------

Date: Tue, 3 Oct 2006 21:01:09 +0200
From: "Mark" <admin@asarian-host.net>
Subject: Locking issue with BerkeleyDB 0.30 after upgrade?
Message-Id: <mJidnY1pF7boLr_YRVnyuw@giganews.com>

Hello,

On FreeBSD 4.11, I've been using BerkeleyDB 4.2 for quite a while. Then I
upgraded the database, a few days back. But a few IPC Perl processes that
actually use it (BerkeleyDB-0.30) have become unstable. I've been
ktracing, setting log-points myself, but I keep getting core dumps at
places where they access BerkeleyDB. Sporadically, but often enough.

Naturally I compiled BerkeleyDB-0.30 against the correct libraries (in
config.in).

INCLUDE = /usr/local/include/db44
LIB = /usr/local/lib    # also tried /usr/local/lib/db44 directly
DBNAME = -ldb-4.4

# end of file config.in

I have done this upgrade-path for BerkeleyDB and Perl several times; from
1.85 -> 4.1 -> 4.2, and now -> 4.4.20. It has always worked well. Even now
it compiles just fine. It just isn't stable anymore. And, just to be
clear, of course I wiped the __* cache files that BerkeleyDB-0.30 uses,
after upgrading.

Upgrading to 4.5 made no difference. I even installed an entirely new Perl
(5.8.8) for the occasion. To no avail.

I really suspect it's a locking issue. My app is a socketmap daemon, for
sendmail, that does SPF queries and the like. So, concurrency is
definitely happening when processes are forking.

The one time I was actually able to log an error for a process, it said:
"Invalid locker id" when opening the BerkeleyDB environment. That in
itself may not necessarily mean anything (could just mean the env has
become corrupted in general). But the occurance of the core dumps seem
consistent with a locking issue (under heavy, concurrent load).

BerkeleyDB 0.30 (the Perl package) itself takes care of locking the shared
environment. Paul Marquess, the author of BerkeleyDB (the Perl package),
wrote me once in this very newsgroup:

"Apart from that you don't need to do anything -- Berkeley DB handles the
locking for you behind the scenes."

And it's certainly true for for 4.2: the 'tied' hashes can be accessed,
concurrently, between processes, even under the most stringent load.

Since an upgrade to 4.5 made no difference, I'm really thinking this is
just a matter of BerkeleyDB 0.30 (the Perl package) no longer doing the
locking properly. Or maybe there's something between BerkeleyDB 4.2 and
4.4 that has changed about the manner in which locks are done that
BerkeleyDB 0.30 is unaware of.

I wonder if this is perhaps a known issue, and if anything has any ideas
how to solve this. I'd hate to think I'm not able to upgrade my BerkeleyDB
anymore.

Thanks,

- Mark 




------------------------------

Date: Tue, 03 Oct 2006 18:40:34 GMT
From: "Todd W" <trwww@sbcglobal.net>
Subject: Re: my vs our for class data
Message-Id: <C8yUg.8160$GR.648@newssvr29.news.prodigy.net>


"John W. Krahn" <someone@example.com> wrote in message 
news:smrUg.38591$Lb5.20422@edtnps89...
> Ralph Moritz wrote:
>>
>> I know this probably belongs in perl.beginners, but my ISP doesn't
>> carry that group :( .
>
> perl.beginners is a mailing list so you are saying that your ISP doesn't 
> allow
> you to send or receive email?

Its a news group (on nntp.perl.org) and a mailing list... and has a browser 
based reader (http://www.nntp.perl.org/).

Ask has a connector on the server that posts emails to the news server and 
relays nntp items to the mailing lists.

Todd W.






------------------------------

Date: Tue, 03 Oct 2006 21:00:23 +0100
From: Justin C <justin.0610@purestblue.com>
Subject: Re: OS X and perldoc
Message-Id: <justin.0610-023D8B.21002303102006@stigmata>

In article <m2lknxbb2y.fsf@Sherm-Pendleys-Computer.local>,
 Sherm Pendley <sherm@Sherm-Pendleys-Computer.local> wrote:

> Justin C <justin.0610@purestblue.com> writes:
> 
> > I've recently bought a Mac, my first, and I'm still finding my way 
> > around it. I'm also still finding my way around Perl; while I don't have 
> > a lot of chance to use it I read a lot here and hope to pick things up. 
> > Quite often questions are posted and the OP is directed to perldoc and 
> > out of interest I follow. That was all well and good on my Linux box; 
> > it's not so good here. There was a recent reference to perldoc perlop, 
> > I've not read it all and I was interested in the answer to the OP's 
> > question. It seems that there is only a partial perldoc install on this 
> > machine, "perldoc -f" works, perldoc -m works, perldoc perldoc and 
> > perldoc perlop don't (I can't think of others to try ... not without 
> > perldoc perldoc anyway!).
> >
> > Where can I go for information on how to fix this install?
> 
> Many of Perl's pods are included in the 'DevDocumentation.pkg' sub-package
> of the Xcode install.

Thanks Sherm, and everyone else. I haven't got around to checking out 
the Xcode stuff yet; I was assuming that, as I had perl, I'd have the 
documentation if the install was OK.

There I go making assumptions again.

And I've just noticed this newsreader isn't appending my .sig. Oh the 
trial of a new OS!

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

open SIG "<.sig" or die ;
while (<SIG>) {
  print $_ . "\n" ;
}
close SIG ;

And what's more, the # is in an awkward place and so is the \, why 
didn't I just get another ThinkPad mumble mumble...


------------------------------

Date: Tue, 03 Oct 2006 21:01:17 +0100
From: Justin C <justin.0610@purestblue.com>
Subject: Re: OS X and perldoc
Message-Id: <justin.0610-38C251.21011703102006@stigmata>

In article <m2lknxbb2y.fsf@Sherm-Pendleys-Computer.local>,
 Sherm Pendley <sherm@Sherm-Pendleys-Computer.local> wrote:

> Justin C <justin.0610@purestblue.com> writes:
> 
> > I've recently bought a Mac, my first, and I'm still finding my way 
> > around it. I'm also still finding my way around Perl; while I don't have 
> > a lot of chance to use it I read a lot here and hope to pick things up. 
> > Quite often questions are posted and the OP is directed to perldoc and 
> > out of interest I follow. That was all well and good on my Linux box; 
> > it's not so good here. There was a recent reference to perldoc perlop, 
> > I've not read it all and I was interested in the answer to the OP's 
> > question. It seems that there is only a partial perldoc install on this 
> > machine, "perldoc -f" works, perldoc -m works, perldoc perldoc and 
> > perldoc perlop don't (I can't think of others to try ... not without 
> > perldoc perldoc anyway!).
> >
> > Where can I go for information on how to fix this install?
> 
> Many of Perl's pods are included in the 'DevDocumentation.pkg' sub-package
> of the Xcode install.

Thanks Sherm, and everyone else. I haven't got around to checking out 
the Xcode stuff yet; I was assuming that, as I had perl, I'd have the 
documentation if the install was OK.

There I go making assumptions again.

And I've just noticed this newsreader isn't appending my .sig. Oh the 
trial of a new OS!

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

open SIG "<.sig" or die ;
while (<SIG>) {
  print $_ . "\n" ;
}
close SIG ;

And what's more, the # is in an awkward place and so is the \, why 
didn't I just get another ThinkPad mumble mumble...


------------------------------

Date: 3 Oct 2006 21:27:33 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Perl Async .10
Message-Id: <4og2u5Fe9tcdU1@news.dfncis.de>

Sisyphus <sisyphus1@nomail.afraid.org> wrote in comp.lang.perl.misc:
> 
> "Todd English" <toddenglish@gmail.com> wrote in message
> .
> .
> >
> > The expected output would be 20 lines printed to the console saying the
> > following:
> > <some number>      I have returned
> > What happens instead is that some of lines fail to print the "I have
> > returned" part of the message.
> .
> .
> > ----------------sample code------------------
> > #!/usr/bin/perl -w
> >
> > use strict;
> > use Async;
> >
> > sub long_running_computation {
> >      system qq{find ./ -type f 2>&1 >/dev/null};
> >      return "I have returned";
> >   }
> >
> > my %proc_result;
> > my %build_result;
> >
> > for (my $counter=0; $counter < 20; $counter++)
> > {
> >     $proc_result{$counter} = Async->new( sub{
> > long_running_computation() } );
> > }
> >
> > while ( my ($name, $proc) = each %proc_result)
> > {
> >     $build_result{$name} = $proc->result('1');
> > }
> >
> > while (my($host_name, $result) = each %build_result)
> > {
> >     printf "%s\t%s\n", $host_name, $result;
> > }
> >
> 
> Is the problem dependent upon that system() command, or do you get the same
> problem even if you replace the system call with something else ?
>
> I replaced the system call with sleep(2) as I didn't want to mess around
> with system(). I get 20 lines of "<some number>    I have returned".

He said as much.  Sleep instead of find shows return values for
all processes.

I think it's a bug in Async.pm that has to do with buffering.
Async uses a buffer of size 8192.  If you make the output string
longer than that (printing only a bit of it), all processes will
return values.  If it is much shorter, (half that size or so) gaps
will start to appear.

Anno


------------------------------

Date: 3 Oct 2006 18:36:55 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: perl flawed or my fault
Message-Id: <4ofou7Fe3m1tU1@news.dfncis.de>

Eric Schwartz  <emschwar@pobox.com> wrote in comp.lang.perl.misc:
> "John W. Krahn" <someone@example.com> writes:

> > defined($something) ? ($note_whom = $something) : ($otherthing = 'singapore');
> 
> Or better yet, write it out:
> 
> if (defined($something)) {
>    $note_whome = $something;
> } else {
>    $otherthing = 'singapore';
> }
> 
> I always recommend against the ?: operator unless it's for something
> small and self-contained.  I avoid using it except for rvalues, unless
> not using it will make things unacceptably ugly.  Yes, this is a vague
> standard.  Here' an exampe of what is acceptable:
> 
> my $foo = $bar ? 0 : 1;
> 
> Here's something that isn't:
> 
> ($var == 'foo' and $bar < 6 or $x > $y) ? ($this = something($else,
> 'maybe') or die "um, I dunno") : call_cows($potatoes);

One point about ternary ?: is that it is an expression that has a
value, not primarily a means of flow control.  The value should be
the main point if the construct is used, not the side-effects of
the code in the branches.  In my view, small and self-contained
enters the image only in so far as it can be hard to find a readable
format for arbitrarily nested ?: with big complex branches.  If
such a format can be found, there is no limit to the complexity.

I am of a split mind about using ?: in lvalue context.  It *is*
kind of obscure, but there are situations that simply call for
it.  One is the loop of a binary search, for example

    while ( $low < $high - 1 ) {
        my $mid = ($low + $high)/2;
        $list->[ $mid] le $targ ? $low : $high = $mid;
    }

The if-else equivalent to ?: is four lines, even cuddling the else.
I can never bring myself to use it.

Anno


------------------------------

Date: Tue, 03 Oct 2006 19:02:57 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: perl flawed or my fault
Message-Id: <BtyUg.45901$bf5.30322@edtnps90>

Eric Schwartz wrote:
> "John W. Krahn" <someone@example.com> writes:
>>Because of precedence you have:
>>
>>(defined($something) ? $note_whom = $something : $otherthing) = 'singapore';
>>
>>You need to add parentheses:
>>
>>defined($something) ? ($note_whom = $something) : ($otherthing = 'singapore');
> 
> Or better yet, write it out:
> 
> if (defined($something)) {
>    $note_whome = $something;
> } else {
>    $otherthing = 'singapore';
> }

Or better yet, don't use "cuddled else".   :-)

perldoc perlstyle



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


------------------------------

Date: 3 Oct 2006 19:03:23 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: perl flawed or my fault
Message-Id: <4ofqfrFeajp4U2@news.dfncis.de>

 <anno4000@radom.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
> Eric Schwartz  <emschwar@pobox.com> wrote in comp.lang.perl.misc:
> > "John W. Krahn" <someone@example.com> writes:

[...]

>     while ( $low < $high - 1 ) {
>         my $mid = ($low + $high)/2;
>         $list->[ $mid] le $targ ? $low : $high = $mid;
>     }
> 
> The if-else equivalent to ?: is four lines, even cuddling the else.

Five!

> I can never bring myself to use it.


------------------------------

Date: Tue, 03 Oct 2006 19:20:18 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: perl flawed or my fault
Message-Id: <SJyUg.49711$E67.23424@clgrps13>

anno4000@radom.zrz.tu-berlin.de wrote:
> Eric Schwartz  <emschwar@pobox.com> wrote in comp.lang.perl.misc:
>>"John W. Krahn" <someone@example.com> writes:
> 
>>>defined($something) ? ($note_whom = $something) : ($otherthing = 'singapore');
>>Or better yet, write it out:
>>
>>if (defined($something)) {
>>   $note_whome = $something;
>>} else {
>>   $otherthing = 'singapore';
>>}
>>
>>I always recommend against the ?: operator unless it's for something
>>small and self-contained.  I avoid using it except for rvalues, unless
>>not using it will make things unacceptably ugly.  Yes, this is a vague
>>standard.  Here' an exampe of what is acceptable:
>>
>>my $foo = $bar ? 0 : 1;
>>
>>Here's something that isn't:
>>
>>($var == 'foo' and $bar < 6 or $x > $y) ? ($this = something($else,
>>'maybe') or die "um, I dunno") : call_cows($potatoes);
> 
> One point about ternary ?: is that it is an expression that has a
> value, not primarily a means of flow control.  The value should be
> the main point if the construct is used, not the side-effects of
> the code in the branches.  In my view, small and self-contained
> enters the image only in so far as it can be hard to find a readable
> format for arbitrarily nested ?: with big complex branches.  If
> such a format can be found, there is no limit to the complexity.
> 
> I am of a split mind about using ?: in lvalue context.  It *is*
> kind of obscure, but there are situations that simply call for
> it.  One is the loop of a binary search, for example
> 
>     while ( $low < $high - 1 ) {
>         my $mid = ($low + $high)/2;
>         $list->[ $mid] le $targ ? $low : $high = $mid;
>     }
> 
> The if-else equivalent to ?: is four lines, even cuddling the else.
> I can never bring myself to use it.

I assume that you meant to write:

        ( $list->[ $mid] le $targ ? $low : $high ) = $mid;

because your example never assigns a value to $low.



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


------------------------------

Date: 3 Oct 2006 19:30:44 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: perl flawed or my fault
Message-Id: <4ofs34Feajp4U3@news.dfncis.de>

John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de wrote:


> >     while ( $low < $high - 1 ) {
> >         my $mid = ($low + $high)/2;
> >         $list->[ $mid] le $targ ? $low : $high = $mid;
> >     }
> > 
> > The if-else equivalent to ?: is four lines, even cuddling the else.
> > I can never bring myself to use it.
> 
> I assume that you meant to write:
> 
>         ( $list->[ $mid] le $targ ? $low : $high ) = $mid;
> 
> because your example never assigns a value to $low.

Hmmm?

    perl -le '$_ ? $low : $high = 123 for 0, 1; print "$low $high"'

prints

    123 123

showing that both are set.

Anno


------------------------------

Date: Tue, 03 Oct 2006 19:56:56 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: perl flawed or my fault
Message-Id: <cgzUg.46105$bf5.33227@edtnps90>

anno4000@radom.zrz.tu-berlin.de wrote:
> John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
>>anno4000@radom.zrz.tu-berlin.de wrote:
> 
> 
>>>    while ( $low < $high - 1 ) {
>>>        my $mid = ($low + $high)/2;
>>>        $list->[ $mid] le $targ ? $low : $high = $mid;
>>>    }
>>>
>>>The if-else equivalent to ?: is four lines, even cuddling the else.
>>>I can never bring myself to use it.
>>I assume that you meant to write:
>>
>>        ( $list->[ $mid] le $targ ? $low : $high ) = $mid;
>>
>>because your example never assigns a value to $low.
> 
> Hmmm?
> 
>     perl -le '$_ ? $low : $high = 123 for 0, 1; print "$low $high"'
> 
> prints
> 
>     123 123
> 
> showing that both are set.

Yes, interesting, even though the Fine Manual states:

<QUOTE>
       The operator may be assigned to if both the 2nd and 3rd arguments are
       legal lvalues (meaning that you can assign to them):

           ($a_or_b ? $a : $b) = $c;

       Because this operator produces an assignable result, using assignments
       without parentheses will get you in trouble.
</QUOTE>



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


------------------------------

Date: 3 Oct 2006 20:15:25 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: perl flawed or my fault
Message-Id: <4ofumtFefp09U1@news.dfncis.de>

John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de wrote:
> > John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> >>anno4000@radom.zrz.tu-berlin.de wrote:
> > 
> > 
> >>>    while ( $low < $high - 1 ) {
> >>>        my $mid = ($low + $high)/2;
> >>>        $list->[ $mid] le $targ ? $low : $high = $mid;
> >>>    }
> >>>
> >>>The if-else equivalent to ?: is four lines, even cuddling the else.
> >>>I can never bring myself to use it.
> >>I assume that you meant to write:
> >>
> >>        ( $list->[ $mid] le $targ ? $low : $high ) = $mid;
> >>
> >>because your example never assigns a value to $low.
> > 
> > Hmmm?
> > 
> >     perl -le '$_ ? $low : $high = 123 for 0, 1; print "$low $high"'
> > 
> > prints
> > 
> >     123 123
> > 
> > showing that both are set.
> 
> Yes, interesting, even though the Fine Manual states:
> 
> <QUOTE>
>        The operator may be assigned to if both the 2nd and 3rd arguments are
>        legal lvalues (meaning that you can assign to them):
> 
>            ($a_or_b ? $a : $b) = $c;
> 
>        Because this operator produces an assignable result, using assignments
>        without parentheses will get you in trouble.
> </QUOTE>

The parentheses in the Fine Manual are bogus then.  It's the other
way 'round, you have precedence problems when you want assignments
in the branches of the expression

    $a_or_b ? $a = 123 : $b = 456;
is
    ($a_or_b ? $a = 123 : $b) = 456;

so the intended value of 123 for $a will be overwritten by 456 in
the "true" case.  At least the second assignment (to $b) needs
parens.  For symmetry I'd probably write

    $a_or_b ? ( $a = 123) : ( $b = 456);

if at all.  After all, it's a case where only the side-effects
count.

Anno


------------------------------

Date: 3 Oct 2006 13:37:19 -0700
From: david.f.jenkins@usa.net
Subject: Re: Please help me pass an array from VBA to Perl and populate it. Newbie at wits' end!
Message-Id: <1159907839.324949.141370@k70g2000cwa.googlegroups.com>

Hi, Michele, and thanks for the advice.

I can't execute an external program or shove files around, because of
performance implications, mostly.  I need a "sub" (but one written in
Perl) that I can call from VBA.

What did you find vague?  In VBA I want to have some container that can
hold a set of strings (a Collection, an Array - I'm not picky - I'll
use what's required) that I want to populate in a Perl method.  As a
template, I'm using the PerlCtrl sample program that provides a Regex
control.


Michele Dondi wrote:
> On 2 Oct 2006 18:49:12 -0700, david.f.jenkins@usa.net wrote:
>
> >I want to pass an empty container for a set of strings from VBA into
> >Perl, do some stuff in Perl, and populate the Collection with a set of
> >strings. I've stolen most of the PDK Perlctrl regex sample and made
> >some small mods to it to meet my requirements.
>
> Quite vague. Do you want some sort of IPC? I guess VBA does have a
> means to run an external program. Can it gather the program's output?
> If so, then just... do so! Or else, how 'bout using it to run perl,
> have it write its output into a file, and then read its contents?
>
> Or else I've completely misunderstood your question.
>
>
> Michele
> --
> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
> .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
> 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,



------------------------------

Date: Tue, 03 Oct 2006 20:15:07 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: problems with regex matching - invalid ranges, quantifier follows nothing, etc.
Message-Id: <fxzUg.2663$Lv3.616@newsread1.news.pas.earthlink.net>

On 10/03/2006 09:33 AM, Jack wrote:
> Hi folks,
> 
> I want to be able to test any string (yes any string with any
> combination of -, 0-9, +, -, [, and other non alphanumeric characters)
> against a set of target strings (and with these also, anything goes in
> these strings as well)..Here is an example of the code which as you can
> see pattern matches:
> while (<SOURCE2>) {
> @temparray2 = split(/$delimiter/, $_);
> for ($i=0;$i<=$#target;$i++)
> 	{
>     if ($target[$i] =~ m/$temparray2[0]/i) {  print " match "; }
>         }
> } #end while
> [...]

Perhaps you want quotemeta:
if ($target[$i] =~ m/\Q$temparray2[0]\E/i) { print " match "; }

Look at "perldoc perlre" and search for \Q. Also read "perldoc -f 
quotemeta."

Since you don't seem to need regular expressions, using the "index" 
function would be better. The index function returns -1 when it fails to 
match:

if (index($target[$i],$temparray2[0]) >= 0) { print " match "; }

I hope this helps.

WARNING: UNTESTED CODE

-- 
Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


------------------------------

Date: 3 Oct 2006 14:02:43 -0700
From: "robb@acm.org" <robb@acm.org>
Subject: Reducing dependencies when initializing Log4perl?
Message-Id: <1159909363.313900.142460@b28g2000cwb.googlegroups.com>

Hi,

My goal is to have zero dependencies in my source code to artifacts
such as configuration file locations or package names.  Usually, the
init code for Log4perl looks like this:

use Log::Log4perl;
Log::Log4perl->init("/path/to/log.conf");
my $logger = Log::Log4perl->get_logger("MyPackage::MySubPackage");

That's just way too much redundant information to put in the top of
each of my source files.

Does anyone have any other solutions?  In other words, I believe one
ought to be able to do this:

use MyLogWrapper;
my $logger = MyLogWrapper->get_logger();

Two things would happen here:
1. MyLogWrapper is the only class that knows where the config file is,
and
2. It is able to determine the class/package name for when it invokes
Log4perl->get_logger.

Another option occurred to me, though for #2: I've found that if
Log4perl->get_logger() is invoked without a param, it will determine
the package of the caller.  But if this invocation is in a helper class
like this, the helper class's info will be used, not the actual client.

Which made me wonder if late binding would work.  In this case, my
wrapper would be used like this:

use MyLogWrapper;
my $logger = MyLogWrapper->get_logger()();

Anyone following me?



------------------------------

Date: 3 Oct 2006 20:50:02 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: this is annoying
Message-Id: <r3c5i2hgrupb79ds1pocu4lfsk7sr06dvn@4ax.com>

On 3 Oct 2006 17:01:27 GMT, anno4000@radom.zrz.tu-berlin.de wrote:

>As Paul Lalli has noted in his excellent reply, the second argument
>of split() should be a string, not an array.  I'll assume $str instead
>of @$tx.

And I had thought that if e.g. $tx=['foo',2], then it would be awkward
but work. However a quick experiment seems to imply it doesn't...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: 3 Oct 2006 11:53:57 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: this is annoying
Message-Id: <1159901637.139095.221530@h48g2000cwc.googlegroups.com>

Michele Dondi wrote:
> On 3 Oct 2006 17:01:27 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>
> >As Paul Lalli has noted in his excellent reply, the second argument
> >of split() should be a string, not an array.  I'll assume $str instead
> >of @$tx.
>
> And I had thought that if e.g. $tx=['foo',2], then it would be awkward
> but work. However a quick experiment seems to imply it doesn't...

Nope.  split() is prototyped to take 1, 2, or 3 scalars.  Therefore, an
array passed as the EXPR is treated in scalar context:

perl -le'
my @letters = ("a".."z");
my @foo = split //, @letters;
print "@foo";
'       
2 6

Paul Lalli



------------------------------

Date: 3 Oct 2006 19:00:16 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: this is annoying
Message-Id: <4ofqa0Feajp4U1@news.dfncis.de>

Michele Dondi  <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On 3 Oct 2006 06:24:55 -0700, "Mr P" <MisterPerl@gmail.com> wrote:

> But you're aware that 
> 
> :     split /PATTERN/,EXPR,LIMIT
> :     split /PATTERN/,EXPR
> :     split /PATTERN/
> :     split   Splits the string EXPR into a list of strings and returns that
> 
> Aren't you? So unless @$tx contains an "EXPR,LIMIT" couple you're
> doing something strange.

That's a valiant attempt to justify MisterPerl's broken code, but even
that won't work.  The second argument of split() is evaluated in scalar
context.  An array in that position is equivalent to the number of its
elements.  It will split an unsigned integer, which will rarely make
sense.

Anno


------------------------------

Date: Tue, 3 Oct 2006 16:01:21 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: this is annoying
Message-Id: <slrnei5jt1.u73.tadmc@magna.augustmail.com>

Mr P <MisterPerl@gmail.com> wrote:

>   shift split /\s+/, @$tx;
> 
> Type of arg 1 to shift must be array (not split) at
> /production/fe/users/feot/acs/ACS_Spex.pm line 5, near "$tx )"


Are you going to continue to post this annually until you get an 
answer that you like?

   Message-ID: <1128446765.998511.294640@o13g2000cwo.googlegroups.com>


> Larry you almost always make things work as expected,

> Larry I've heard you say personally that your intended design on Perl
> was that "things would always always work as you'd expect".


Larry has not participated here for many years. He is not seeing
your sage advice.

Even if you repeat it here every 12 months, he still won't see it.

If you post your patch to p5p he might see it...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Tue, 3 Oct 2006 16:05:37 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: this is annoying
Message-Id: <slrnei5k51.u73.tadmc@magna.augustmail.com>

Paul Lalli <mritty@gmail.com> wrote:
> Mr P wrote:

>> Get your knives out Uri et al, but this is annoying, depsite your
>> defense that Perl design is "always right", and comp scientsts opposing
>> views are "always wrong". (I've read myriad responses to that effect).
> 
> Now what the hell is the point of this?  


MrP> There will probably be a plethora of criticisms about this response.
MrP> Don't be put off by them, there are a few folks here who really want to
MrP> assist others. Just figure out who they are and screen the rest. There
MrP> are some great people here but you need to pay attention to who are
MrP> here just to criticize. 

   in Message-ID: <1121696196.523965.221670@g14g2000cwa.googlegroups.com>

Which is exceedingly rich, considering the source...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Tue, 03 Oct 2006 18:13:55 GMT
From: David Harmon <source@netcom.com>
Subject: Use of -i inplace option
Message-Id: <4533a630.133636375@news.west.earthlink.net>

I try to modify a file in place with

  perl -i.bak myfunc.pl data.txt

but instead of modifying in place, I get output to the screen 
and a zero-length data.txt.  The original data.txt is renamed 
to data.txt.bak as expected.

What should my command line be?

I'm using perl v5.8.8 built for MSWin32-x86-multi-thread
Binary build 819 [267479] provided by ActiveState
Windows XP.

Simplified myfunc.pl is:
for (<>) {
    print;
}



------------------------------

Date: 3 Oct 2006 11:25:50 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Use of -i inplace option
Message-Id: <1159899950.291653.302070@k70g2000cwa.googlegroups.com>

David Harmon wrote:
> I try to modify a file in place with
>
>   perl -i.bak myfunc.pl data.txt
>
> but instead of modifying in place, I get output to the screen
> and a zero-length data.txt.  The original data.txt is renamed
> to data.txt.bak as expected.
>
> What should my command line be?
>
> I'm using perl v5.8.8 built for MSWin32-x86-multi-thread
> Binary build 819 [267479] provided by ActiveState
> Windows XP.
>
> Simplified myfunc.pl is:
> for (<>) {
>     print;
> }

It has nothing to do with your command line and everything to do with
your code.  The special magic of the $^I variable (or -i command line
switch) apply only to files read via the
while (<>) { }
construct.  Your for(<>) {} construct doesn't work with it.  My *guess*
as to the reason for this is that because for reads all lines from the
file at once, by the time it starts actually processing the file, the
magic of $^I has already been expended, and STDOUT has been reselected.
 That is, $^I only changes the default output filehandle while <ARGV>
is still being read.  As soon as it's exhausted, STDOUT becomes the
default filehandle again.  Because you didn't have any print lines
while the new file was select()'ed, no text was written to that file.

On a related note, NEVER use the for (<>) {} construct. Ever.  You are
attempting to process a file line-by-line, which is good, but you're
reading all the lines into memory at once, and keeping them there for
the duration of the loop.
for my $line (<$fh>) { }
is simply this in disguise:
my @all_lines = <$fh>;
for my $line (@all_lines) { }

Whereas the while(<>) {} construct reads one line, processes it,
discards it, and reads the next line.

Paul Lalli



------------------------------

Date: Tue, 03 Oct 2006 19:08:24 GMT
From: David Harmon <source@netcom.com>
Subject: Re: Use of -i inplace option
Message-Id: <4535b4ce.137378484@news.west.earthlink.net>

On 3 Oct 2006 11:25:50 -0700 in comp.lang.perl.misc, "Paul Lalli"
<mritty@gmail.com> wrote,
>It has nothing to do with your command line and everything to do with
>your code.  The special magic of the $^I variable (or -i command line
>switch) apply only to files read via the
>while (<>) { }

Thanks.



------------------------------

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:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#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 V10 Issue 9799
***************************************


home help back first fref pref prev next nref lref last post