[25835] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8072 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 12 06:05:29 2005

Date: Thu, 12 May 2005 03:05:05 -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, 12 May 2005     Volume: 10 Number: 8072

Today's topics:
        deamons and IPC <moritz.karbach@desy.de>
    Re: Games.pl again <hackeras@gmail.com>
    Re: Games.pl again <hackeras@gmail.com>
    Re: how to recursively search through files (not dirs)? (David Combs)
    Re: how to recursively search through files (not dirs)? (David Combs)
    Re: how to recursively search through files (not dirs)? <someone@example.com>
    Re: how to recursively search through files (not dirs)? <vdheuv@kabelfoon.nl>
    Re: Simple error using GD::Graph on Windows <pump_yo_brakes@hotgetridofthisbitmail.com>
        sub in a package with parameters <rbcs@gmx.net>
    Re: sub in a package with parameters <josef.moellers@fujitsu-siemens.com>
    Re: sub in a package with parameters <rbcs@gmx.net>
    Re: sub in a package with parameters (Anno Siegel)
    Re: sub in a package with parameters <joe@inwap.com>
        XS: SvUPGRADE and test for lvalue <w.n.humann.removethis@agilent.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 12 May 2005 11:00:44 +0200
From: Moritz Karbach <moritz.karbach@desy.de>
Subject: deamons and IPC
Message-Id: <d5v5vs$3c5v0$1@claire.desy.de>

Hi!

I'm very new to inter process communication, maybe you have some suggestions
or comments:

I'm trying to write a deamon which basically launches some programs
periodically, and I want to steer the deamon somehow. Eg like

 ./deamon.pl start
 ./deamon.pl stop
 ./deamon.pl something_interesting

How can I send such messages to my deamon? I came to the conclusion, that
sockets may be what I need. Maybe some of you have some very easy server
and client scripts, using tcp and localhost?

Thanks,

- Moritz


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

Date: Thu, 12 May 2005 10:32:37 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Games.pl again
Message-Id: <d5v0qi$2rl$1@nic.grnet.gr>

Tad McClellan wrote:

Tad i changes the code i posted to you with this one, which is even more 
straight forward that the other: Here it is:


#============LOADING THE .TXT TO THE DATABASE================

my ($gamename, $gamedesc, $gamecounter);
my $replace = $dbh->prepare( "REPLACE INTO games (gamename, gamedesc, 
gamecounter) VALUES (?, ?, ?)" );

open (FILE, "<../data/games/descriptions.txt") or die $!;

while (<FILE>) {
     chomp;
     $replace->execute( split(/\t/, $_, 2) , 0 ) or print $dbh->errstr;
}

close (FILE);


and i am getting the following error:

called with 1 bind variables when 3 are neededcalled with 1 bind 
variables when 3 are neededcalled with 1 bind variables when 3 are 
neededcalled with 1 bind variables when 3 are neededcalled with 1 bind 
variables when 3 are neededcalled with 1 bind variables when 3 are 
neededcalled with 1 bind variables when 3 are neededcalled with 1 bind 
variables when 3 are neededcalled with 1 bind variables when 3 are 
neededcalled with 1 bind variables when 3 are neededcalled with 1 bind 
variables when 3 are neededcalled with 1 bind variables when 3 are 
neededcalled with 1 bind variables when 3 are neededcalled with 1 bind 
variables when 3 are neededcalled with 1 bind variables when 3 are 
neededcalled with 1 bind variables when 3 are neededcalled with 1 bind 
variables when 3 are neededcalled with 1 bin

I cant understand it though.

-- 
"Of course I cant stop you. And that would really bum me out
if that were my job. But my job isnt to stop you, its to
make it as difficult as possible, for as many as possible,
for as long as possible ."


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

Date: Thu, 12 May 2005 11:50:15 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Games.pl again
Message-Id: <d5v5c4$88f$1@nic.grnet.gr>

i changed the connect method to:

my $dbh = DBI->connect('DBI:mysql:nikos_db', 'root', '*******', 
{RaiseError=>1});

instead of

my $dbh = DBI->connect('DBI:mysql:nikos_db', 'root', '*******') or 
{RaiseError=>1});


and now i am getting this error:

DBD::mysql::st execute failed: called with 1 bind variables when 3 are 
needed at C:\DOCUME~1\beatnik\LOCALS~1\Temp\dzprltmp.pl line 30, <FILE> 
line 2.

Pleas help out a bit i dont know whts this error mean or how to proceed 
any more.



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

Date: Thu, 12 May 2005 05:33:24 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: how to recursively search through files (not dirs)?
Message-Id: <d5upr4$qdf$1@reader1.panix.com>

In article <ysxge.36505$0X6.32934@edtnps90>,
John W. Krahn <krahnj@telus.net> wrote:
 ...
 ...
>
>This works for me:
>
>#!/usr/bin/perl
>use warnings;
>use strict;
>
>
>source( 'test1.source' );
>
>sub source {
>     local *ARGV;
>     @ARGV = shift;
>     my $level = 1 + shift;
>     while ( <> ) {
>         if ( /^source\s+(.+)/ ) {
>             source( $1, $level )
>             }
>         else {
>             print "$level: $_"
>             }
>         }
>     }
>
>__END__
>
>
>
>John

Thank you for the fresh (and clever) code:

381 ====> /me-FIRST-in-PATH-bin/perl-5.8.6/bin/perl5.8.6  -w  krahn--traverse-sources.pl
Use of uninitialized value in addition (+) at krahn--traverse-sources.pl line 12.
1: foo
2: this is test2.source, line ONE
3: this is test3.source, line ONE.
3: this is test3.source, line TWO.
2: this is test2.source, line THREE
2: this is test2.source, line FOUR
1: bar
1: bletch
382 ====> 

(again, here's the three "test.source" files:

==> test1.source <==
foo
source test2.source
bar
bletch

==> test2.source <==
this is test2.source, line ONE
source test3.source
this is test2.source, line THREE
this is test2.source, line FOUR

==> test3.source <==
this is test3.source, line ONE.
this is test3.source, line TWO.

)



ONE QUESTION: I see no explicit "open", so please
explain a bit of the magic involved.  Like, how
*does* the opening work -- and what makes it
get recursed-back-to the prior value on return?

Yes, that's confusing to me -- how does your glob-thing
get the file opened on "its" level, but with some other
file getting opened on *that* (next-lower) level.

How does it work?

Well, I do note that you don't use "my" for *ARGV, so it isn't lexical ...

Instead, you use "local", thus it's "dynamically" bound
(like in emacs-lisp and in old long-gone maclisp?) -- but
surprisingly after an "inner" (ie during recursive call)
assignment from shift, it gets magically restored on
return back to prior frame to the value it last had
there.

  (I suppose that caught-exceptions also watch for
  locals that need restoring, if the catching is done
  across sub-call stack-levels?

  Like, in a deeper recursion level you encounter
  a divide-by-zero, and what you want to do is
  abort out of that level (and file being read)
  and return one level up and keep reading from *that*
  level's file.)


  If so, how would you add it in -- is the *only* way to
  catch one via an dynamically-outer eval?)


Also, suppose you wanted to use "my" instead of "local" -- could
you do that with the glob-scheme, or would you want to use
some other method for opening files?  What would have to change
for it to work *that* way?



I think there's some neat stuff in what happens behind-the-scenes
in your solution -- I'd sure like to understand it better!


Thank you for the idea!

David




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

Date: Thu, 12 May 2005 05:59:24 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: how to recursively search through files (not dirs)?
Message-Id: <d5urbs$btm$1@reader1.panix.com>

In article <4282716c$0$75708$58c7af7e@news.kabelfoon.nl>,
Theo van den Heuvel <vdheuv@kabelfoon.nl> wrote:
>
>"David Combs" <dkcombs@panix.com> schreef in bericht 
>news:d5th6n$9hj$1@panix1.panix.com...
>> What I want to do traverse files that recursively
 ...
 ...
>>  my $fh = new FileHandle;
>>  die "Cannot open \"$fileName\"!" if (! fh->open( $fileName ));
>                                         ^

Thanks -- added the needed "$", as suggested, and it works!


(Amazing -- a missing $, and error-msgs that I couldn't
make much sense out of -- such a simple fix!)



Further, cperl-mode gives the same old msg when I
say "M-x cperl-indent-region" (and the procedure
has been regionized):   

    Scan error: unbalance parentheses, 1398, 1939

where the 1398 is the char-position (goto-char)
is the left-paren just after the "if":


    if ( ( $line =~ /^source / ) && 
	 ( $line =~ /^source\s+([A-Za-z0-9._-]+)/ ) ) { # dive-in:
    #  CPERL-MODE won't bounce on either rparen   ^ ^ -- WHY?
            my $diveIntoFName = $1;

, with the 1939 char position being at EOF, ie here:


  } # dive-in.

} # end-while.

   print("----- EXITING processOneFile(\"$fileName\", $level\n\n");
} # end-sub processOneFile.


processOneFile("test1.source", 1);



 HERE <<-------------- actual end of file (well, of emacs buffer).

Any idea why cperl seems to be confused?



Thanks for the help!

David


Thanks so much!


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

Date: Thu, 12 May 2005 08:16:35 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: how to recursively search through files (not dirs)?
Message-Id: <DhEge.61677$tg1.11292@edtnps84>

David Combs wrote:
> In article <ysxge.36505$0X6.32934@edtnps90>,
> John W. Krahn <krahnj@telus.net> wrote:
> 
>>This works for me:
>>
>>#!/usr/bin/perl
>>use warnings;
>>use strict;
>>
>>
>>source( 'test1.source' );
>>
>>sub source {
>>    local *ARGV;
>>    @ARGV = shift;
>>    my $level = 1 + shift;
>>    while ( <> ) {
>>        if ( /^source\s+(.+)/ ) {
>>            source( $1, $level )
>>            }
>>        else {
>>            print "$level: $_"
>>            }
>>        }
>>    }
>>
>>__END__
> 
> Thank you for the fresh (and clever) code:
> 
> 381 ====> /me-FIRST-in-PATH-bin/perl-5.8.6/bin/perl5.8.6  -w  krahn--traverse-sources.pl
> Use of uninitialized value in addition (+) at krahn--traverse-sources.pl line 12.

You can remove that warning by changing the line:

     my $level = 1 + shift;

To:

     my $level = 1 + ( shift || 0 );

> 1: foo
> 2: this is test2.source, line ONE
> 3: this is test3.source, line ONE.
> 3: this is test3.source, line TWO.
> 2: this is test2.source, line THREE
> 2: this is test2.source, line FOUR
> 1: bar
> 1: bletch
> 382 ====> 
> 
> (again, here's the three "test.source" files:

[snip]

> ONE QUESTION: I see no explicit "open", so please
> explain a bit of the magic involved.  Like, how
> *does* the opening work -- and what makes it
> get recursed-back-to the prior value on return?

The magic works through the @ARGV array, the ARGV filehandle and the magical 
<> readline operator.  If there are file names in the @ARGV array and you use 
<> to read from, then each file is opened in turn and the current line of 
every file is assigned to $_ in turn.  The perlop.pod document contains more 
information in the "I/O Operators" section, also perlsyn.pod in the "Loop 
Control" section

perldoc perlop
perldoc perlsyn


> Yes, that's confusing to me -- how does your glob-thing
> get the file opened on "its" level, but with some other
> file getting opened on *that* (next-lower) level.
> 
> How does it work?
> 
> Well, I do note that you don't use "my" for *ARGV, so it isn't lexical ...

No, $ARGV, @ARGV and ARGV are special in perl.

perldoc perlvar



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 12 May 2005 11:46:41 +0200
From: "Theo  van den Heuvel" <vdheuv@kabelfoon.nl>
Subject: Re: how to recursively search through files (not dirs)?
Message-Id: <428325ff$0$66411$58c7af7e@news.kabelfoon.nl>


"David Combs" <dkcombs@panix.com> wrote: 
news:d5urbs$btm$1@reader1.panix.com...
> Further, cperl-mode gives the same old msg when I
> say "M-x cperl-indent-region" (and the procedure
> has been regionized):
>
>    Scan error: unbalance parentheses, 1398, 1939
>
> where the 1398 is the char-position (goto-char)
> is the left-paren just after the "if":
>
>
>    if ( ( $line =~ /^source / ) &&
> ( $line =~ /^source\s+([A-Za-z0-9._-]+)/ ) ) { # dive-in:
>    #  CPERL-MODE won't bounce on either rparen   ^ ^ -- WHY?
>            my $diveIntoFName = $1;
>
> , with the 1939 char position being at EOF, ie here:
>
>
>  } # dive-in.
>
> } # end-while.
>
>   print("----- EXITING processOneFile(\"$fileName\", $level\n\n");
> } # end-sub processOneFile.
>
>
> processOneFile("test1.source", 1);
>
>
>
> HERE <<-------------- actual end of file (well, of emacs buffer).
>
> Any idea why cperl seems to be confused?

No, 'fraid not. I'm a vim-user myself.

Theo van den Heuvel 




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

Date: Thu, 12 May 2005 10:51:46 +0930
From: Mr Hyde <pump_yo_brakes@hotgetridofthisbitmail.com>
Subject: Re: Simple error using GD::Graph on Windows
Message-Id: <lqb581ptahr5ofq1l6gfbk5ije28p12a95@4ax.com>

On Wed, 11 May 2005 14:42:02 +1000, "Sisyphus"
<sisyphus1@nomail.afraid.org> wrote:
>Odd. I would have thought that "/Perl/site/lib" was already in @INC - in
>which case the "use lib ..." line would achieve nothing.
>Run "perl -V". That will show you, at the end of the output, the directories
>that are in @INC. Any module in any of the specified directories *should* be
>found automatically.
>
>Cheers,
>Rob
>

Well, the output was 

  @INC:
    D:/Perl/lib
    D:/Perl/site/lib
    .

This is perl 5.8.6 from ActiveState. Guess it might be a bug.

Thanks for all your help anyway.


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

Date: Thu, 12 May 2005 10:07:31 +0200
From: Roman <rbcs@gmx.net>
Subject: sub in a package with parameters
Message-Id: <d5v2s0$m16$1@atlas.ip-plus.net>

Hello guys

I have this code:
_______________________________________________________________________
package RWToDatasotre;

use strict;
use Config::Simple;

sub ReadParameter {
   my($none, $file, $categorie, $parameter) = @_;

   my $cfg;
   my $param;
   my $returnparam;

   #Create instance on File with name
   $cfg = new Config::Simple("$file") or die Config::Simple->error();

   #Open File
   $cfg = new Config::Simple();
   $cfg->read("$file") or die $cfg->error();

   #Reading value in File
   $param = $cfg->param("$categorie.$parameter") or die $cfg->error();

   $returnparam = $param;
}
_______________________________________________________________________


I Call the sub ReadParameter like this!

_______________________________________________________________________
    my $testcategorie = "GeneralSection";
     my $testparameter = "Testparam";
     my $newtestparameter = "Just to say a hello! ;-)";

    my( $ReadConfigFile) = RWToDatasotre->ReadParameter(
$MainApplicationfile, $testcategorie, $testparameter);
_______________________________________________________________________


Why do I have to have to define one more parameter in the package then
defined in the streing where i call the string?

Thanks to help me

Roman


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

Date: Thu, 12 May 2005 10:13:44 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: sub in a package with parameters
Message-Id: <d5v32c$pod$1@nntp.fujitsu-siemens.com>

Roman wrote:
> Hello guys
>=20
> I have this code:
> _______________________________________________________________________=

> package RWToDatasotre;
>=20
> use strict;
> use Config::Simple;
>=20
> sub ReadParameter {
>   my($none, $file, $categorie, $parameter) =3D @_;
>=20
>   my $cfg;
>   my $param;
>   my $returnparam;
>=20
>   #Create instance on File with name
>   $cfg =3D new Config::Simple("$file") or die Config::Simple->error();
>=20
>   #Open File
>   $cfg =3D new Config::Simple();
>   $cfg->read("$file") or die $cfg->error();
>=20
>   #Reading value in File
>   $param =3D $cfg->param("$categorie.$parameter") or die $cfg->error();=

>=20
>   $returnparam =3D $param;
> }
> _______________________________________________________________________=

>=20
>=20
> I Call the sub ReadParameter like this!
>=20
> _______________________________________________________________________=

>    my $testcategorie =3D "GeneralSection";
>     my $testparameter =3D "Testparam";
>     my $newtestparameter =3D "Just to say a hello! ;-)";
>=20
>    my( $ReadConfigFile) =3D RWToDatasotre->ReadParameter(
> $MainApplicationfile, $testcategorie, $testparameter);
> _______________________________________________________________________=

>=20
>=20
> Why do I have to have to define one more parameter in the package then
> defined in the streing where i call the string?

Because perl treats this as an object reference and passes the object as =

the first argument.
BTW if you want to ignore the argument, you can replace $none by undef.


--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Thu, 12 May 2005 10:28:42 +0200
From: Roman <rbcs@gmx.net>
Subject: Re: sub in a package with parameters
Message-Id: <d5v43o$m3j$1@atlas.ip-plus.net>

Josef Moellers wrote:

> Roman wrote:
> 
>> Hello guys
>>
>> I have this code:
>> _______________________________________________________________________
>> package RWToDatasotre;
>>
>> use strict;
>> use Config::Simple;
>>
>> sub ReadParameter {
>>   my($none, $file, $categorie, $parameter) = @_;
>>
>>   my $cfg;
>>   my $param;
>>   my $returnparam;
>>
>>   #Create instance on File with name
>>   $cfg = new Config::Simple("$file") or die Config::Simple->error();
>>
>>   #Open File
>>   $cfg = new Config::Simple();
>>   $cfg->read("$file") or die $cfg->error();
>>
>>   #Reading value in File
>>   $param = $cfg->param("$categorie.$parameter") or die $cfg->error();
>>
>>   $returnparam = $param;
>> }
>> _______________________________________________________________________
>>
>>
>> I Call the sub ReadParameter like this!
>>
>> _______________________________________________________________________
>>    my $testcategorie = "GeneralSection";
>>     my $testparameter = "Testparam";
>>     my $newtestparameter = "Just to say a hello! ;-)";
>>
>>    my( $ReadConfigFile) = RWToDatasotre->ReadParameter(
>> $MainApplicationfile, $testcategorie, $testparameter);
>> _______________________________________________________________________
>>
>>
>> Why do I have to have to define one more parameter in the package then
>> defined in the streing where i call the string?
> 
> 
> Because perl treats this as an object reference and passes the object as 
> the first argument.
> BTW if you want to ignore the argument, you can replace $none by undef.
> 
>
Thanks Josef


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

Date: 12 May 2005 08:33:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sub in a package with parameters
Message-Id: <d5v4bu$2jr$1@mamenchi.zrz.TU-Berlin.DE>

Roman  <rbcs@gmx.net> wrote in comp.lang.perl.misc:
> Hello guys
> 
> I have this code:
> _______________________________________________________________________
> package RWToDatasotre;
> 
> use strict;
> use Config::Simple;
> 
> sub ReadParameter {
>    my($none, $file, $categorie, $parameter) = @_;

[...]

> }
> _______________________________________________________________________
> 
> 
> I Call the sub ReadParameter like this!
> 
> _______________________________________________________________________
>     my $testcategorie = "GeneralSection";
>      my $testparameter = "Testparam";
>      my $newtestparameter = "Just to say a hello! ;-)";
> 
>     my( $ReadConfigFile) = RWToDatasotre->ReadParameter(
> $MainApplicationfile, $testcategorie, $testparameter);
> _______________________________________________________________________
> 
> 
> Why do I have to have to define one more parameter in the package then
> defined in the streing where i call the string?

That's how method calls work.  The first element of @_ is whatever the
method was called through (an object or, in your case, a class name).
The following elements are the arguments that were given inside the
parentheses in the method call.  Read "perldoc perlobj", paying special
attention to the section "A Method is Simply a Subroutine".

Anno


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

Date: Thu, 12 May 2005 02:40:18 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: sub in a package with parameters
Message-Id: <CeWdnaI_uYUFuR7fRVn-gQ@comcast.com>

Roman wrote:

> sub ReadParameter {
>   my($none, $file, $categorie, $parameter) = @_;

I would write that as

   my $self = shift;
   my($file,$category,$parameter) = @_;

so that the object-oriented interface is explicit.
	-Joe


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

Date: Thu, 12 May 2005 11:05:23 +0200
From: Wolfram Humann <w.n.humann.removethis@agilent.com>
Subject: XS: SvUPGRADE and test for lvalue
Message-Id: <42831c53$0$10500$9b4e6d93@newsread4.arcor-online.net>

This XS code can be found in many CPAN modules (e.g. Zlib.xs):

if (!SvUPGRADE(buf, SVt_PV))
     croak("cannot use buf argument as lvalue");

It is used before sending "SV * buf" to a C function that will fill buf 
with some string. I wanted to use the same in my code but just could not 
get it to "carp" even if I passed numeric or string constants to buf. 
When I say

if (SvREADONLY(buf))
     croak("cannot use buf argument as lvalue");

instead (and "SvUPGRADE" separately), the test works as expected. I 
looked at sv_upgrade in sv.c and found two "return TRUE;" statements but 
no way for the function to return FALSE.

Did sv_upgrade change at some point, so that the test used above does 
not work anymore? Any insights?

Wolfram


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

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 8072
***************************************


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