[29463] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 707 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 1 14:09:49 2007

Date: Wed, 1 Aug 2007 11: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           Wed, 1 Aug 2007     Volume: 11 Number: 707

Today's topics:
    Re: @arts anno4000@radom.zrz.tu-berlin.de
    Re: @arts <bik.mido@tiscalinet.it>
    Re: @arts <bik.mido@tiscalinet.it>
    Re: eval of Data::Dumper output not same as original da  himanshu.garg@gmail.com
    Re: eval of Data::Dumper output not same as original da <mritty@gmail.com>
    Re: How do you continue in a for loop? <bik.mido@tiscalinet.it>
    Re: How do you continue in a for loop? <jurgenex@hotmail.com>
    Re: How do you continue in a for loop? <yankeeinexile@gmail.com>
    Re: How do you continue in a for loop? <jurgenex@hotmail.com>
    Re: How do you continue in a for loop? <yankeeinexile@gmail.com>
    Re: How do you continue in a for loop? <bik.mido@tiscalinet.it>
    Re: How do you continue in a for loop? <azazel@azazel.net>
        IPC::open3: What goes wrong? <bew_ba@gmx.net>
    Re: IPC::open3: What goes wrong? <nobull67@gmail.com>
    Re: Object creation failure in perl <bik.mido@tiscalinet.it>
        Prototypes/Parameters to a Function/Sub-Routine <olson_ord@yahoo.it>
    Re: Prototypes/Parameters to a Function/Sub-Routine <mritty@gmail.com>
    Re: Prototypes/Parameters to a Function/Sub-Routine <klaus03@gmail.com>
    Re: Prototypes/Parameters to a Function/Sub-Routine <bik.mido@tiscalinet.it>
    Re: simple response not implemented <jgibson@mail.arc.nasa.gov>
    Re: threads and logfile rotation <ThomasKratz@REMOVEwebCAPS.de>
    Re: Variable declaration - C vs script style <brian.d.foy@gmail.com>
    Re: Variable dump <primzahl@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 1 Aug 2007 13:21:56 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: @arts
Message-Id: <5hbfnkF3kbia1U1@mid.dfncis.de>

Michele Dondi  <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On 1 Aug 2007 08:52:58 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
> 
> >> > Anno -- sigless since 1989
> [snip]
> >It's a signature in the everyday sense of the word, manually added
> >unless I forget (or put it twice).  It doesn't come from a .signature
> >file and, as you observed, it lacks the "-- " and thus isn't a Usenet
> >signature in the specialized sense of the word.
> 
> And what is the one directly above "-- \n" in (most of) my posts? Am I
> *sigful*?
> 
> 
> 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,

[.sig *not* snipped]

Sure, in every possible way.  The bit above "-- " is a signature in the
common sense of the word.  The part below has nothing to do with common
sense.

Anno


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

Date: Wed, 01 Aug 2007 16:11:11 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: @arts
Message-Id: <9251b3dcdv0h3317rppfakridkpu2tksi5@4ax.com>

On 1 Aug 2007 13:21:56 GMT, anno4000@radom.zrz.tu-berlin.de wrote:

>> 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,
>
>[.sig *not* snipped]
>
>Sure, in every possible way.  The bit above "-- " is a signature in the
>common sense of the word.  The part below has nothing to do with common
>sense.

Yep, it's a sorta zen thing. (I don't know what I'm saying, but it
generally fits well!)


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: Wed, 01 Aug 2007 14:16:05 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: @arts
Message-Id: <h9u0b3llhdhq30eqnqvu6ceita0l9pqg2r@4ax.com>

On Wed, 01 Aug 2007 02:05:55 GMT, Tad McClellan <tadmc@seesig.invalid>
wrote:

>> Alas, I doubt any of you will listen.
>
>
>That happens a lot to trolls. 
>
>Get used to it.

Well Tad, it does not happen that much. And however do I disagree with
the person you're replying to, he's not really a troll: I think the
correct description is a whiner.


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: Wed, 01 Aug 2007 13:29:00 -0000
From:  himanshu.garg@gmail.com
Subject: Re: eval of Data::Dumper output not same as original data structure
Message-Id: <1185974940.514812.249470@e16g2000pri.googlegroups.com>

On Aug 1, 1:44 pm, Brian McCauley <nobul...@gmail.com> wrote:
> On Aug 1, 8:05 am, himanshu.g...@gmail.com wrote:
>
>
>
> >      Why aren't the outputs of the two print statements same. I want
> > to reconstruct %hash1 into %hash2.
>
> > ========================================
> > use strict;
> > use Data::Dumper;
>
> > my %hash1 = (key1 => 'value1', 'key2' => 'value2');
>
> > my %hash2 = eval Dumper(%hash1);
>
> > print Dumper(%hash1);
>
> > print Dumper(%hash2);
> > ========================================
>
> > I am trying to save the Dumper output to the database and later trying
> > to get the same data structure.
>
> You need to think of Dumper() as taking a single scalar argument
>
> my $hash1 = { key1 => 'value1', 'key2' => 'value2' };
>
> my $hash2 = do { no strict 'vars'; eval Dumper($hash1) };
>
> Note, this has the side effect of creating a package variable $VAR1.
>
> To serialise Perl hashes or arrays into human-readable database large
> (text) objects I use.
>
> [code snipped]
>
> If readability is not an issue consider also using BLOBs and Storable.
>
> Usual caveats about eval(STRING) apply: anyone who can write to the
> database can place arbitrary executable code in it. Use this technique
> only if you are satisfied that write access to the database is
> restricted to people who could edit your scripts anyhow.

Thanks for the reply. I will avoid Dumper if that is what is needed
and use XML::Simple instead since readability is not a concern.

Thank You,
HG



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

Date: Wed, 01 Aug 2007 06:49:06 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: eval of Data::Dumper output not same as original data structure
Message-Id: <1185976146.465708.139340@r34g2000hsd.googlegroups.com>

On Aug 1, 3:05 am, himanshu.g...@gmail.com wrote:
>      Why aren't the outputs of the two print statements same. I want
> to reconstruct %hash1 into %hash2.
>
> ========================================
> use strict;
> use Data::Dumper;
>
> my %hash1 = (key1 => 'value1', 'key2' => 'value2');
>
> my %hash2 = eval Dumper(%hash1);
>
> print Dumper(%hash1);
>
> print Dumper(%hash2);
> ========================================
>
> I am trying to save the Dumper output to the database and later trying
> to get the same data structure.

You're making several mistakes with the usage of Data::Dumper.

1) Dumper() takes a list of structures to dump.  You are passing it a
list of values (using a hash in a list context).  If you want to dump
just the single variable %hash1, you have to pass a reference to that
hash:
print Dumper(\%hash1);
2) Dumper() returns a string that starts with "$VAR1 = ".  If you are
trying to eval() that string, you are trying to execute code
containing the variable $VAR1.  When you use strict, you need to pre-
declare all your variables.  You are eval'ing code without checking
for an error.  If you had checked the value of $@, you'd see that the
eval failed because $VAR1 was not previously declared.
3) Because the string that Dumper() returns represents code that
assigns to a reference, if you eval that code, you are getting a
reference out of it.  You need to dereference that reference.

There are several solutions to your problem:
(1) Predeclare $VAR1
$ perl -le'
use strict;
use Data::Dumper;
my %hash1 = (key1 => "value1", key2 => "value2");
my $VAR1;
my %hash2 = %{ eval Dumper(\%hash1) };
print Dumper(\%hash1);
print Dumper(\%hash2);
'
$VAR1 = {
          'key2' => 'value2',
          'key1' => 'value1'
        };

$VAR1 = {
          'key2' => 'value2',
          'key1' => 'value1'
        };


(2) Use the Dump() method rather than the Dumper() function, which
lets you set the name you wish to use for the dumped variables:
$ perl -le'
use strict;
use Data::Dumper;
my %hash1 = (key1 => "value1", key2 => "value2");
my $hash2;
eval Data::Dumper->Dump([\%hash1], ["hash2"]);
print Dumper(\%hash1);
print Dumper($hash2);
'
$VAR1 = {
          'key2' => 'value2',
          'key1' => 'value1'
        };

$VAR1 = {
          'key2' => 'value2',
          'key1' => 'value1'
        };

(3) use the Storable module instead, which has (imho) a nicer
interface for this sort of thing, and is also a core module.
$ perl -le'
use strict;
use Storable qw/freeze thaw/;
my %hash1 = (key1 => "value1", key2 => "value2");
my %hash2 = %{ thaw(freeze(\%hash1)) };
use Data::Dumper;
print Dumper(\%hash1, \%hash2);
'
$VAR1 = {
          'key2' => 'value2',
          'key1' => 'value1'
        };
$VAR2 = {
          'key2' => 'value2',
          'key1' => 'value1'
        };


Hope that helps,
Paul Lalli



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

Date: Wed, 01 Aug 2007 15:18:00 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How do you continue in a for loop?
Message-Id: <ck11b3t6ocmjsauq2qj97dohe045cdpmqj@4ax.com>

On Tue, 31 Jul 2007 18:35:29 +0000 (UTC), Azazel <azazel@azazel.net>
wrote:

>> "next".  For example:
>>
>>   for (my $i = 0; $i < 10; ++$i)
>>     {
>>     if ($i == 7)
>>        {
>>        next;
>>        }
>>     else
>>       {
>>       print $i, "\n";
>>       }
>>     }
>
>Or rather:
>
>for (my $i = 0; $i < 10; ++$i)
>  {
>  if ($i == 7)
>    {
>    next;
>    }
>
>  print $i, "\n";
>  }

Well said, in fact next, last and redo often make for more agile
syntax and exactly serve the purpose of avoiding the need for explicit
else's. Better yet, to further expand on the subject, such simple
cases can be cast in the form of a statement modifier:

  for (my $i = 0; $i < 10; ++$i) {
      next if $i == 7;
      print $i, "\n";
  }

Incidentally, a Perl-style C<for> is clearer and generally preferred:

  for my $i (0..9) {
      next if $i == 7;
      print $i, "\n";
  }

Well, and in this case the loop block is so small that one can safely
go with the topicalizer rather than with an explicit lexical variable:

  for (0..9) {
      next if $_ == 7;
      print $_, "\n";  # Grr! .say
  }

(Of course the example was just that: and example, and with bigger
blocks it is definitely better the other way round.)


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: Wed, 01 Aug 2007 13:56:16 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How do you continue in a for loop?
Message-Id: <4i0si.7408$oW3.2782@trndny08>

Michele Dondi wrote:
> Incidentally, a Perl-style C<for> is clearer and generally preferred:
>
>  for my $i (0..9) {
>      next if $i == 7;
>      print $i, "\n";
>  }

Maybe it is just me but I have never been comfortable with this style of 
programming. When I see a loop like that I assume that the loop will execute 
exactly 10 times just as specified in the loop condition. To me this "next" 
and "last" feels like cheating, like I wasn't smart enough to come up with 
the correct loop condition.
IMHO it also makes for harder to maintain code because when reading the code 
you need to revise your assumptions about how the loop is executed somewhere 
in the middle of the loop body.

In the case at hand what is wrong with a simple

    for my $i (0..6, 8..9) {
        print $i, "\n";
    }

jue




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

Date: 01 Aug 2007 09:27:57 -0500
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: How do you continue in a for loop?
Message-Id: <87ps278h3m.fsf@hummer.cluon.com>

"Jürgen Exner" <jurgenex@hotmail.com> writes:
> When I see a loop like that I assume that the loop will execute 
> exactly 10 times just as specified in the loop condition. 

Only because this is a trivailized example -- in "real" programming,
one does not iterate across a list just for the joy of doing something
"n" times - but there is some task you're completing...

 for my $bridesmade (@bridesmaids) { 
    # all bridesmaids need some stuff
    buy_gift_for($bridesmaid);
    dye_shoes_for($bridesmaid);

    next unless lives_in_other_city($bridesmaid);

    # but only the ones that are from another city need ... 

    rent_hotel_room_for($bridesmaid);
    book_travel_plans_for($bridesmaid);
 }

(Of course, this isn't a real example -- had it been realistic,
"spread_vicious_gossip_about($bridesmaid)" would have been at the top
of the list.)

> IMHO it also makes for harder to maintain code because when reading the code 
> you need to revise your assumptions about how the loop is executed somewhere 
> in the middle of the loop body.

One must strive to write code that is only as complex as it needs to
be...Often, a "next" or "last" inside the loop to handle exceptional
conditions is needed.  Other missions may require building a "better"
list to iterate across.  


-- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
place them into the correct order.


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

Date: Wed, 01 Aug 2007 14:35:14 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How do you continue in a for loop?
Message-Id: <CS0si.9651$9I3.5740@trndny06>

Lawrence Statton wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> writes:
>> When I see a loop like that I assume that the loop will execute
>> exactly 10 times just as specified in the loop condition.
>
> Only because this is a trivailized example -- in "real" programming,
> one does not iterate across a list just for the joy of doing something
> "n" times - but there is some task you're completing...
>
> for my $bridesmade (@bridesmaids) {
>    # all bridesmaids need some stuff
>    buy_gift_for($bridesmaid);
>    dye_shoes_for($bridesmaid);
>    next unless lives_in_other_city($bridesmaid);
>    # but only the ones that are from another city need ...
>    rent_hotel_room_for($bridesmaid);
>    book_travel_plans_for($bridesmaid);
> }

To _ME_ it seems more logical and easier to write

 for my $bridesmade (@bridesmaids) {
    # all bridesmaids need some stuff
    buy_gift_for($bridesmaid);
    dye_shoes_for($bridesmaid);

    if (lives_in_other_city($bridesmaid)) {
        # but only the ones that are from another city need ...
        rent_hotel_room_for($bridesmaid);
        book_travel_plans_for($bridesmaid);
    }
 }

>> IMHO it also makes for harder to maintain code because when reading
>> the code you need to revise your assumptions about how the loop is
>> executed somewhere in the middle of the loop body.
>
> One must strive to write code that is only as complex as it needs to
> be...Often, a "next" or "last" inside the loop to handle exceptional
> conditions is needed.

For exceptional circumstances I actually agree. It doesn't do well to 
clutter the main flow of your code with exceptions that occur once in a 
million.

jue 




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

Date: 01 Aug 2007 09:39:26 -0500
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: How do you continue in a for loop?
Message-Id: <87lkcv8gkh.fsf@hummer.cluon.com>

"Jürgen Exner" <jurgenex@hotmail.com> writes:
> 
> For exceptional circumstances I actually agree. It doesn't do well to 
> clutter the main flow of your code with exceptions that occur once in a 
> million.
> 

Yeah -- I like your bridesmaid code better, too ... I'm still trying
to think of a good example before breakfast.  I need caffeine and
sugar and lipids to write ...


-- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
place them into the correct order.


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

Date: Wed, 01 Aug 2007 16:26:16 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How do you continue in a for loop?
Message-Id: <5a51b3tet5ip1hkulcvf52dr6ca1bbfcvl@4ax.com>

On Wed, 01 Aug 2007 13:56:16 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:

>>  for my $i (0..9) {
>>      next if $i == 7;
>>      print $i, "\n";
>>  }
>
>Maybe it is just me but I have never been comfortable with this style of 
>programming. When I see a loop like that I assume that the loop will execute 

Well *of course* it's just you. Just as obviously some will agree with
you and some will disagree.

>exactly 10 times just as specified in the loop condition. To me this "next" 
>and "last" feels like cheating, like I wasn't smart enough to come up with 
>the correct loop condition.

This example is actually artificial and one doesn't need C<next> at
all:

  $_ != 7 and print for 0..9;  # assuming $\="\n";

But then you may like this one even the less.
>IMHO it also makes for harder to maintain code because when reading the code 
>you need to revise your assumptions about how the loop is executed somewhere 
>in the middle of the loop body.

To put it briefly there are situations in which one kind of approach
is preferred and situations in which the other one is.
(Un?)fortunately the distinction is blurred.

>In the case at hand what is wrong with a simple
>
>    for my $i (0..6, 8..9) {
>        print $i, "\n";
>    }

Nothing's wrong, but then what if the "seven" condition is to change?
You would have to change in two places, albeit contiguous. Of course
you could do something like the following instead:

    for my $i (0..$n-1, $n+1..9) {

But then if not except for matters of performance, I would rather do

    for my $i (grep $_ != $n, 0..9) {

which is IMHO clearer. And we could discuss so on for hours. Just
stories of ordinary TMTOTDIness...


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: Wed, 1 Aug 2007 15:53:31 +0000 (UTC)
From: Azazel <azazel@azazel.net>
Subject: Re: How do you continue in a for loop?
Message-Id: <slrnfb1b3v.8un.azazel@kadath.azazel.net>

On 2007-07-31, usenet@DavidFilmer.com <usenet@DavidFilmer.com> wrote:
> On Jul 31, 11:45 am, Paul Lalli <mri...@gmail.com> wrote:
>> C++ 'continue' ==> Perl 'next'
>> C++ 'break' ==> Perl 'last'
>
> And as a matter of Perlish style:
>
> C++ 'for (my $i = 0; $i < 10; ++$i)' => Perl 'foreach my $i( 0..9 )'

Fair point.  I was up to my eye-balls in C when I wrote that.

Az.


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

Date: Wed, 01 Aug 2007 10:05:18 -0700
From:  bernd <bew_ba@gmx.net>
Subject: IPC::open3: What goes wrong?
Message-Id: <1185987918.217020.91590@57g2000hsv.googlegroups.com>

Hello netties,

I try to run a simple UNIX-command using IPC::open and want to get the
command line's STDOUT, STDERR and the return code of the command using
the following:

cat script.pl
#!/usr/bin/perl
#
use IPC::Open3;
open3 (\*WRT, \*OUT, \*ERR, "ls -ly ; echo $?") or print "Could not
run unix-cmd\n";
@OUT = <OUT> ;
@ERR = <ERR>;
print "### OUT ###\n";
foreach ( @OUT ) { print "$_\n" } ;
print "### ERR ###\n" ;
foreach ( @ERR ) { print "$_\n" }

script.pl
### OUT ###
0

### ERR ###
ls: illegal option -- y

Usage: ls [-aAbcCdDfFgilLmnopqrRstux1] [file ... | directory ...]

On the command line "ls -ly" has the return code 2, run from within
perl I get 0.

What goes wrong?

Cheers


Bernd



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

Date: Wed, 01 Aug 2007 17:19:39 -0000
From:  Brian McCauley <nobull67@gmail.com>
Subject: Re: IPC::open3: What goes wrong?
Message-Id: <1185988779.214125.117380@k79g2000hse.googlegroups.com>

On Aug 1, 6:05 pm, bernd <bew...@gmx.net> wrote:
>
> open3 (\*WRT, \*OUT, \*ERR, "ls -ly ; echo $?")

> On the command line "ls -ly" has the return code 2, run from within
> perl I get 0.
>
> What goes wrong?

You have the wrong type of quotes in Perl.

The Unix command you are actually executing is

ls -ly ; echo 0



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

Date: Wed, 01 Aug 2007 15:29:25 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Object creation failure in perl
Message-Id: <ji21b3lkht3fcd2l880ttgrjogr1v0ggfi@4ax.com>

On Wed, 01 Aug 2007 01:48:11 -0700, ramesh.thangamani@gmail.com wrote:

>my $obj = MyModule->new() or die "Failed to create object of type
>MyModule $!" in my code. Strangely enough sometimes the object

As a side note, most likely $! is not what you want: I'm not saying it
isn't. I'm saying it is improbable to be.


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: Wed, 01 Aug 2007 08:41:36 -0700
From:  "O. Olson" <olson_ord@yahoo.it>
Subject: Prototypes/Parameters to a Function/Sub-Routine
Message-Id: <1185982896.959476.45460@b79g2000hse.googlegroups.com>

Hi,
	I would like to know if it is possible to enforce the number and type
of the parameters in a function prototype. Assuming that a person does
not circumvent the prototypes using &.

I have tried the following that tries to say that the function
printScalar () should only accept a single Parameter. This does not
work i.e. does not compile.

# This function would print the time variable passed
sub printScalar(my $num)
{
	print "$num";
}


I have looked at perlsub at http://perldoc.perl.org/perlsub.html - and
I am not sure if the answer to my Question is NO.

This would be of more importance when I am working with Objects i.e.
to ensure that the reference passed, is an object of a certain class.

Thanks a lot.
O.O.



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

Date: Wed, 01 Aug 2007 09:49:14 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Prototypes/Parameters to a Function/Sub-Routine
Message-Id: <1185986954.417186.97810@19g2000hsx.googlegroups.com>

On Aug 1, 11:41 am, "O. Olson" <olson_...@yahoo.it> wrote:
>         I would like to know if it is possible to enforce the number and type
> of the parameters in a function prototype. Assuming that a person does
> not circumvent the prototypes using &.

That is supposed to be the idea behind subroutine prototypes, yes.
But they don't work correctly.

> I have tried the following that tries to say that the function
> printScalar () should only accept a single Parameter. This does not
> work i.e. does not compile.
>
> # This function would print the time variable passed
> sub printScalar(my $num)

What part of perlsub gave you the idea that was valid syntax?

> {
>         print "$num";

perldoc -q quoting

> }
>
> I have looked at perlsub athttp://perldoc.perl.org/perlsub.html- and
> I am not sure if the answer to my Question is NO.
>
> This would be of more importance when I am working with Objects i.e.
> to ensure that the reference passed, is an object of a certain class.

What you are trying to do is:

sub printScalar($) {
   my $num = shift;
   print $num;
}

Doing that, when someone calls your subroutine with something other
than one scalar value, they will get a syntax error:

$ perl -le'
sub printScalar($) {
   my $num = shift;
   print $num;
}
printScalar(10, 20);
'
Too many arguments for main::printScalar at -e line 6, near "20)"
Execution of -e aborted due to compilation errors.


However, as I said, prototypes do NOT work correctly.  For example,
you would probably expect this to give a similar error, wouldn't you?
$ perl -le'
sub printScalar($) {
   my $num = shift;
   print $num;
}
my @nums = (10, 20);
printScalar(@nums);
'

But instead, this program executes just fine, and displays the number
"2".  Why?  Because you told the subroutine to take a scalar
argument.  The user passed an array.  So Perl "helpfully" took that
array, and evaluated it in scalar context, and an array in scalar
context gives its size.

Similarly, you'd probably expect this to return an error that a list
is required:

$ perl -le'
sub printArray(@) {
   my @nums = @_;
   print for @nums;
}
printArray();
'

But this program executes just fine.  Because an "empty" list is still
a list.  We could go on and on.  Say you want a subroutine to take two
scalars:
sub printBoth($$);
but if a user calls it like so:
my @mixmax = (5, 10);
printBoth(@minmax);
Perl will throw an error, even though the array does indeed contain
two scalars.


End result, you can't enforce this type of checking at compile time.
You have to do it manually at runtime.

sub printObject {
   @_ == 1 or
      croak "Invalid number of arguments passed to printObject";
   my $obj = shift;
   ref $obj or
      croak "Argument to printObject is not a reference";
   UNIVERSAL::isa($obj, "MyClass") or
      croak "Argument to printObject is not a MyClass";
   #etc . . .
}

Paul Lalli



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

Date: Wed, 01 Aug 2007 09:57:43 -0700
From:  Klaus <klaus03@gmail.com>
Subject: Re: Prototypes/Parameters to a Function/Sub-Routine
Message-Id: <1185987463.035863.68350@k79g2000hse.googlegroups.com>

On Aug 1, 5:41 pm, "O. Olson" <olson_...@yahoo.it> wrote:
> Hi,
>         I would like to know if it is possible to enforce the number and type
> of the parameters in a function prototype. Assuming that a person does
> not circumvent the prototypes using &.
>
> I have tried the following that tries to say that the function
> printScalar () should only accept a single Parameter. This does not
> work i.e. does not compile.
>
> # This function would print the time variable passed
> sub printScalar(my $num)
> {
>         print "$num";
>
> }
>
> I have looked at perlsub athttp://perldoc.perl.org/perlsub.html- and
> I am not sure if the answer to my Question is NO.

Looking at the article "Far More Than Everything You've Ever Wanted to
Know about Prototypes in Perl" by Tom Christiansen:
http://library.n0i.net/programming/perl/articles/fm_prototypes/
I would say the answer to your question is probably no.

> This would be of more importance when I am working with Objects i.e.
> to ensure that the reference passed, is an object of a certain class.

You can test the package name of an object, see perldoc -f ref

--
Klaus



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

Date: Wed, 01 Aug 2007 19:26:30 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Prototypes/Parameters to a Function/Sub-Routine
Message-Id: <k7c1b3hpdb2dn14ght2mnl4j4911rvuakt@4ax.com>

On Wed, 01 Aug 2007 08:41:36 -0700, "O. Olson" <olson_ord@yahoo.it>
wrote:

>	I would like to know if it is possible to enforce the number and type
>of the parameters in a function prototype. Assuming that a person does

No. Perl 5 does not have a type system. Perl 6 will, but it will still
be optional.

>I have tried the following that tries to say that the function
>printScalar () should only accept a single Parameter. This does not
>work i.e. does not compile.
>
># This function would print the time variable passed
>sub printScalar(my $num)

In fact that's not a valid syntax. You want

  sub printScalar ($) { ... }

instead.

>This would be of more importance when I am working with Objects i.e.
>to ensure that the reference passed, is an object of a certain class.

You're out of luck! Prototypes do not work at all when subs are called
as methods. Still talking 'bout Perl 5, of course...


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: Wed, 01 Aug 2007 10:33:50 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: simple response not implemented
Message-Id: <010820071033503261%jgibson@mail.arc.nasa.gov>

In article <QQZri.4298$vi3.1006@newsfe2-gui.ntli.net>, Nospam
<nospam@home.com> wrote:

> I am getting this error trying to use a proxy with lwp::debug
> 
> LWP::UserAgent::request: Simple response: Not Implemented
> 
> What does this mean?  How can it be fixed?

It means that the server has returned a 501 status code for your
request, indicating that it is not prepared to handle your request as
sent. Check the request and the server and modify either accordingly.
Send a request that the server recognizes.

Note: I ascertained the above by inspecting the source code for
LWP::UserAgent, LWP::Debug, and HTTP::Status, and googling for 'HTTP
status codes'. You can do the same, I am sure.

Good luck.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Wed, 01 Aug 2007 16:58:07 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: threads and logfile rotation
Message-Id: <46b09f7e$0$2640$bb690d87@news.main-rheiner.de>

zentara wrote:
> I wouldn't give up too quickly on letting the threads close and
> rename the file.
> 
> First, all threads share the same filehandles thru the filenos. 

[snipped outline for shared writing to logfile]

Heureka!

My problem was not getting the logging sorted out. I didn't think that 
you could close the filehandle from each thread. But one is actually 
required to, before the file is free to rename. I should have tried it 
before.

Thanks for your input!
Thomas

Here a small example that works as intended:

use strict;
use warnings;

use threads;
use Thread::Queue;

use IO::File;

my $q = Thread::Queue->new();

sub worker {
     my $fh;
     while (1) {
         my $fno = $q->dequeue();
         if ( $fno ) {
             print "worker: opening fileno:$fno\n";
             $fh = IO::File->new_from_fd($fno, '>') or die $!;
             $fh->autoflush(1);
             print $fh "worker was here\n";
         } else {
             $fh->close();
         }
     }
}

threads->new(\&worker)->detach();

my $fname = 'test.log';
my $fh;

$fh = IO::File->new($fname, '>') or die $!;
$fh->autoflush(1);
print $fh "main was here\n";
$q->enqueue($fh->fileno());
sleep 1;

$q->enqueue(0);
sleep 1;
$fh->close();
rename($fname, "$fname.1") or die $!;

$fh = IO::File->new($fname, '>') or die $!;
$fh->autoflush(1);
print $fh "main was here\n";
$q->enqueue($fh->fileno());
sleep 1;


-- 
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-


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

Date: Tue, 31 Jul 2007 13:19:19 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: Variable declaration - C vs script style
Message-Id: <310720071319194254%brian.d.foy@gmail.com>

In article <1185883270.375241.4660@o61g2000hsh.googlegroups.com>,
markoa <marko.anastasov@gmail.com> wrote:

> I've been wondering whether there are any differences in performance
> when declaring variables within loops
> comparing to all forward declarations. 

If that issue is a perfomance problem for you, then you're script is
already really, really fast or Perl is the wrong tool for you
(seriously). Don't even worry about it. 

You should, however, limit variables just to the scope where you
actaully need them. :)

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



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

Date: Wed, 01 Aug 2007 10:33:38 -0700
From:  Reto <primzahl@gmail.com>
Subject: Re: Variable dump
Message-Id: <1185989618.200212.161300@57g2000hsv.googlegroups.com>

I'm sure there is way. You could take a look at Data::Dumper.

# -- example
$d = Data::Dumper->new(@data);
print $d->Dump;

Additionally, I suggest to see this page which might help to solve
your problem by another approach:

http://www.infocopter.com/perl/monitored-variables.html

--reto


On 29 Jul., 14:08, Bill H <b...@ts1000.us> wrote:
> Is there a way in perl to dump all the variables used and their
> current values to a file without printing everyone of them
> individually?
>
> Bill H




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

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 V11 Issue 707
**************************************


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