[28559] in Perl-Users-Digest
Perl-Users Digest, Issue: 9923 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 2 18:06:03 2006
Date: Thu, 2 Nov 2006 15:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 2 Nov 2006 Volume: 10 Number: 9923
Today's topics:
Re: Abysmal performance of Net::SFTP (and I have GMP & <sisyphus1@nomail.afraid.org>
Re: accessing main:: vars in required file <stephen.odonnell@gmail.com>
Re: Masking/Hiding a password in Perl Source <nospam@example.com>
Re: Masking/Hiding a password in Perl Source <puckdropper@yahoo.com>
Re: Masking/Hiding a password in Perl Source cartercc@gmail.com
Re: Masking/Hiding a password in Perl Source <veatchla@yahoo.com>
Sorting and Writing Effecient Code <bradbrockman@yahoo.com>
Re: Sorting and Writing Effecient Code xhoster@gmail.com
Re: Sorting and Writing Effecient Code <bradbrockman@yahoo.com>
Re: Sorting and Writing Effecient Code <someone@example.com>
Re: Sorting and Writing Effecient Code <wahab@chemie.uni-halle.de>
Re: Sorting and Writing Effecient Code <someone@example.com>
Re: Sorting and Writing Effecient Code <wahab@chemie.uni-halle.de>
Re: Sorting and Writing Effecient Code xhoster@gmail.com
trying to use Games::Go::SGF <spam.meplease@ntlworld.com>
WIN32::OLE excel date <caradomski@hotmail.com>
Wrapper application s1037989@gmail.com
Re: Wrapper application <bik.mido@tiscalinet.it>
Re: Wrapper application s1037989@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 3 Nov 2006 09:27:32 +1100
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Abysmal performance of Net::SFTP (and I have GMP & Pari)
Message-Id: <454a71f4$0$16913$afc38c87@news.optusnet.com.au>
"Ben Morrow" <benmorrow@tiscali.co.uk> wrote in message
news:3skp14-5jh.ln1@osiris.mauzo.dyndns.org...
>
> Quoth "Sisyphus" <sisyphus1@nomail.afraid.org>:
> >
> > <usenet@DavidFilmer.com> wrote in message
> > news:1162432420.105832.200020@m7g2000cwm.googlegroups.com...
> > .
> > .
> > >> To check that's *not* the case I would rename Math/BigInt.pm to
> > > > (eg) Math/BigInt_hide.pm, re-run the script and see if performance
> > improves.
> >
> > > I tried your suggestion and the test program blew up with:
> > >
> > > Can't locate Math/BigInt.pm in @INC ... Crypt/DH.pm line 6
> > >
> >
> > Same culprit as last time.
>
> This I would not expect to work, as Math::BigInt loads the various
> libraries for you.
Doh ... you're right. Crypt/DH.pm will inevitably try to load Math::BigInt -
which doesn't necessarily mean that the slow Math::BigInt pure perl routines
will be used.
> You could try moving Math::BigInt::Calc out of the
> way, though.
Much smarter idea .... might actually test out what I was intending to test
:-)
The absence of Math::BigInt::Calc in the op's listing of %INC would suggest
that the slow Math::BigInt pure perl routines are *not* to blame in this
instance, after all.
Cheers,
Rob
------------------------------
Date: 2 Nov 2006 14:03:52 -0800
From: "Stephen O'D" <stephen.odonnell@gmail.com>
Subject: Re: accessing main:: vars in required file
Message-Id: <1162505031.973068.44560@m73g2000cwd.googlegroups.com>
On Nov 2, 5:48 pm, "Brian McCauley" <nobul...@gmail.com> wrote:
> On Nov 2, 4:39 pm, "Stephen O'D" <stephen.odonn...@gmail.com> wrote:
>
> > Guys,
>
> > I am trying to create a program that requires a file, and the required
> > file needs to be able to see variables from the main program (perl
> > 5.6.1):
>
> > my %config;my() declares a variable as _lexically_ scoped. That means it's only
> visible in code that is _lexically_ part of the remainder of enclosing
> block, it's not visible to code elsewhere that's called via subroutine
> calls or do/require. (A lexical variable _is_ (sometimes) visible to
> code that's eval()ed even though you'd think it shouldn't be).
>
> See "coping with scoping" or the FAQ "What's the difference between
> dynamic and lexical (static) scoping? Between local() and my()?"
Of course - I finally figured out that declaring the variables as our()
get me what I needed. I thought (wrongly) that if I required a file
that wasnt a module that it would be in the same lexial scope.
I know what I am doing is really 'good practice' - i am trying to
achive something similar to MJD's dispatch tables described in Higher
Order Perl - i think I need to go back and re-read it ...
Thanks.
------------------------------
Date: Thu, 02 Nov 2006 11:55:41 -0800
From: "Chris G." <nospam@example.com>
Subject: Re: Masking/Hiding a password in Perl Source
Message-Id: <454a4d53$0$97264$892e7fe2@authen.yellow.readfreenews.net>
These are good suggestions. A little more information may help. The
whole point of the protecting the password within the source code is to
quiet the nay-sayers in my department who will scream bloody-murder
because anyone can read the password. Never mind that the connections
we make are using telnet, which is unsecure by default. I was
considering even a simple ROT13 call to jumble it.
I am not opposed to reading an encrypted string from a file and
decrypting it. I'm just trying to satisfy people on a more political
level than a technical level, if that makes sense.
Thanks for the suggestions and keep them coming!
Chris G.
Ted Zlatanov wrote:
> On 2 Nov 2006, nospam@example.com wrote:
>
>> I have written a Perl script that connects to various networking devices
>> and downloads their configurations to a TFTP server. This is working
>> great and I want to enhance its security by masking the password
>> somehow. Currently, I hardcode a variable to the password.
>>
>> $password = 'mypassword';
>>
>> In the interest of security, I want to find a way to mask this. I'm not
>> sure how to go about it though. I don't want to have a plain-text
>> password on the system anywhere.
>
> This is actually a hard problem to solve in the general sense. It's
> not really a Perl problem either, usually the OS has to manage
> permissions.
>
> The plain-text password will be in memory eventually (when you want to
> use it), so this will simply delay but not impede the attacker who has
> obtained root access.
>
> If the attacker will not have root access, put the password file in a
> file that only root can read, and then you can allow access to it
> appropriately.
>
> You may want to look into public/private keys as well. It depends on
> your existing security infrastructure what you want to do.
>
> Finally, you could make those devices provide their configurations
> with a less privileged (non-admin) account, so you don't have the
> admin password out there.
>
> Ted
------------------------------
Date: 02 Nov 2006 20:10:45 GMT
From: Puckdropper <puckdropper@yahoo.com>
Subject: Re: Masking/Hiding a password in Perl Source
Message-Id: <454a50c5$0$97229$892e7fe2@authen.yellow.readfreenews.net>
"Chris G." <nospam@example.com> wrote in
news:454a4d53$0$97264$892e7fe2@authen.yellow.readfreenews.net:
> These are good suggestions. A little more information may help. The
> whole point of the protecting the password within the source code is
> to quiet the nay-sayers in my department who will scream bloody-murder
> because anyone can read the password. Never mind that the connections
> we make are using telnet, which is unsecure by default. I was
> considering even a simple ROT13 call to jumble it.
>
> I am not opposed to reading an encrypted string from a file and
> decrypting it. I'm just trying to satisfy people on a more political
> level than a technical level, if that makes sense.
>
> Thanks for the suggestions and keep them coming!
>
> Chris G.
>
>
*snip*
I asked a similar question about securing a database password several
months ago on another site. To sum up the result, the best suggestion I
got was to simply move the password to another file and read it in. You
can encrypt it if you want, but if they have access to your source code,
they have access to your decryption algorithm.
Puckdropper
--
Wise is the man who attempts to answer his question before asking it.
To email me directly, send a message to puckdropper (at) fastmail.fm
------------------------------
Date: 2 Nov 2006 12:52:21 -0800
From: cartercc@gmail.com
Subject: Re: Masking/Hiding a password in Perl Source
Message-Id: <1162500741.437938.58320@b28g2000cwb.googlegroups.com>
Chris G. wrote:
> I have written a Perl script that connects to various networking devices
> and downloads their configurations to a TFTP server. This is working
> great and I want to enhance its security by masking the password
> somehow. Currently, I hardcode a variable to the password.
We have a number of scripts that run queries on a remote database
server. These run in Perl, Java, and Visual Basic. We initialize these
scripts with configuration files to set up a VPN, a login session to
run the query, and an FTP session to retrieve the data. The
configuration files all look like this:
filetype::VPN
username::username
password::password
hostname::123.45.67.89
The best that we can do is save the config files as the name of the
user of the app and make them readable only, like this r-------- (or
400). This only defers the problem to someone obtaining the user's
password (or root).
At some point, your remote machine will expect a 'real' username and
password, and while you can tunnel the connection, I don't think
there's any way to encrypt it on your local machine and have it
unencrypted on the other end.
CC
------------------------------
Date: Thu, 02 Nov 2006 15:04:58 -0600
From: l v <veatchla@yahoo.com>
Subject: Re: Masking/Hiding a password in Perl Source
Message-Id: <12kknbiqt6v4u18@news.supernews.com>
Chris G. wrote:
> These are good suggestions. A little more information may help. The
> whole point of the protecting the password within the source code is to
> quiet the nay-sayers in my department who will scream bloody-murder
> because anyone can read the password. Never mind that the connections
> we make are using telnet, which is unsecure by default. I was
> considering even a simple ROT13 call to jumble it.
>
> I am not opposed to reading an encrypted string from a file and
> decrypting it. I'm just trying to satisfy people on a more political
> level than a technical level, if that makes sense.
>
> Thanks for the suggestions and keep them coming!
>
> Chris G.
>
>
> Ted Zlatanov wrote:
>> On 2 Nov 2006, nospam@example.com wrote:
>>
>>> I have written a Perl script that connects to various networking devices
>>> and downloads their configurations to a TFTP server. This is working
>>> great and I want to enhance its security by masking the password
>>> somehow. Currently, I hardcode a variable to the password.
>>>
>>> $password = 'mypassword';
>>>
>>> In the interest of security, I want to find a way to mask this. I'm not
>>> sure how to go about it though. I don't want to have a plain-text
>>> password on the system anywhere.
>> This is actually a hard problem to solve in the general sense. It's
>> not really a Perl problem either, usually the OS has to manage
>> permissions.
>>
>> The plain-text password will be in memory eventually (when you want to
>> use it), so this will simply delay but not impede the attacker who has
>> obtained root access.
>>
>> If the attacker will not have root access, put the password file in a
>> file that only root can read, and then you can allow access to it
>> appropriately.
>>
>> You may want to look into public/private keys as well. It depends on
>> your existing security infrastructure what you want to do.
>>
>> Finally, you could make those devices provide their configurations
>> with a less privileged (non-admin) account, so you don't have the
>> admin password out there.
>>
>> Ted
You could also reverse() the password making it harder to read to the
casual reader. Then you might be able to say "no. The password is not
in the script. :)" Don't actually smile when you say that either! And
do not use variable names like $password to advertise what the variable
holds.
$password = 'drowssapym';
.... 100 lines down ....
$loginPasswd = reverse($password);
#now telnet to server.
I also heard one developer which stored passwords in 1 character arrays
in his c++ programs. The purpose was to make it so the password was not
readable in the compiled programs. I thought it was good enough to keep
in the back of my head. For example:
@passwd = qw(m y p a s s w o r d);
--
Len
------------------------------
Date: 2 Nov 2006 11:36:22 -0800
From: "banker123" <bradbrockman@yahoo.com>
Subject: Sorting and Writing Effecient Code
Message-Id: <1162496181.904342.295090@m7g2000cwm.googlegroups.com>
I have the code below that opens a directory, determines the current
date and extracts the file names that start with the current date, then
loops through the contents of those files to extract data in a scalar
context.
Question
1. How do I sort the variables in a scalar context not an array?
Should I be reading the variables I have extracted into an array?
2. This program executes every 15 seconds to output the contents of
the directory. The output is used to control work flow and meet crucial
deadlines. Is this effeciently written? Any suggestions?
My first "production" perl program, after reading and learning perl for
about a month.
#Open directory
my $dir="G:/Formware/files/";
opendir DH, $dir or die "Cannot open$!";
#Get system date in the format mmddyy
@months = qw(01 02 03 04 05 06 07 08 09 10 11 12);
@days = qw(01 02 03 04 05 06 07 08 09 10..31);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek,
$dayOfYear, $daylightSavings) = localtime();
$dayOfMonth=sprintf("%02d", $dayOfMonth);
$date = "$months[$month]$dayOfMonth06";
#Read each file beginning with system date from directory
@files=grep(/^$date/,readdir(DH));
closedir (DH);
foreach $file (@files) {
open (data, "$dir$file") or die "Cannot open file: $!";
while ( <data> ) {
if ( /JOBNAME/ ) {
$job = substr($_,8,8);
chomp($job);
}
elsif ( /\.TIF\s{12}/ ) {
my $box = substr($_,73,6);
printf "$box $job $file\n";
last;
}
}}
------------------------------
Date: 02 Nov 2006 20:09:24 GMT
From: xhoster@gmail.com
Subject: Re: Sorting and Writing Effecient Code
Message-Id: <20061102150944.615$LM@newsreader.com>
"banker123" <bradbrockman@yahoo.com> wrote:
> I have the code below that opens a directory, determines the current
> date and extracts the file names that start with the current date, then
> loops through the contents of those files to extract data in a scalar
> context.
You seem to be mis-using the term "scalar context", in a way that
renders your question meaningless.
>
> Question
> 1. How do I sort the variables in a scalar context not an array?
> Should I be reading the variables I have extracted into an array?
If you want to sort them, then you need to store them. Either an array,
or maybe a hash.
> 2. This program executes every 15 seconds to output the contents of
> the directory. The output is used to control work flow and meet crucial
> deadlines. Is this effeciently written? Any suggestions?
You don't seem to be using strict. You should. As long as the program
does whatever it needs to do fast enough so that it is not the bottleneck,
it is hard to see how its efficiency would matter.
>
> My first "production" perl program, after reading and learning perl for
> about a month.
>
> #Open directory
> my $dir="G:/Formware/files/";
> opendir DH, $dir or die "Cannot open$!";
You should probably use a lexical dir handle.
opendir my $dh, $dir or die $!;
> #Read each file beginning with system date from directory
> @files=grep(/^$date/,readdir(DH));
If the list can be big, you may not want to read everything into memory
at once.
while (defined (my $file=readdir($dh))) {
next unless $file =~ /^$date/;
Every time you execute this script, it reprocesses the same files it
already processed the last time. That is the fundamental inefficiency,
but how to fix it depends on external factors.
By the way, there was no indication anywhere in your code about what it is
you want to sort, or how you want it sorted.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 2 Nov 2006 12:46:32 -0800
From: "banker123" <bradbrockman@yahoo.com>
Subject: Re: Sorting and Writing Effecient Code
Message-Id: <1162500392.050646.323210@e3g2000cwe.googlegroups.com>
> > Question
> > 1. How do I sort the variables in a scalar context not an array?
> > Should I be reading the variables I have extracted into an array?
>
> If you want to sort them, then you need to store them. Either an array,
> or maybe a hash.
How do I store the variables into an array, push or pop command, does
this have much overhead? I woul like the saort to point to a sort
order file that containas priorites. Example:
Variables
Box 1
Box 2
Box 3
Prioroties table
Box 3
Box 1
Box 2
Sorted Array
Box 3
Box 1
Box 2
> Every time you execute this script, it reprocesses the same files it
> already processed the last time. That is the fundamental inefficiency,
> but how to fix it depends on external factors.
Understood this is running real-time therefore the re-processing is
acceptable.
------------------------------
Date: Thu, 02 Nov 2006 21:24:27 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Sorting and Writing Effecient Code
Message-Id: <fmt2h.78602$E67.4393@clgrps13>
banker123 wrote:
> I have the code below that opens a directory, determines the current
> date and extracts the file names that start with the current date, then
> loops through the contents of those files to extract data in a scalar
> context.
>
> Question
> 1. How do I sort the variables in a scalar context not an array?
> Should I be reading the variables I have extracted into an array?
>
> 2. This program executes every 15 seconds to output the contents of
> the directory. The output is used to control work flow and meet crucial
> deadlines. Is this effeciently written? Any suggestions?
>
> My first "production" perl program, after reading and learning perl for
> about a month.
>
> #Open directory
> my $dir="G:/Formware/files/";
> opendir DH, $dir or die "Cannot open$!";
>
> #Get system date in the format mmddyy
> @months = qw(01 02 03 04 05 06 07 08 09 10 11 12);
> @days = qw(01 02 03 04 05 06 07 08 09 10..31);
You don't need those two arrays.
> ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek,
> $dayOfYear, $daylightSavings) = localtime();
> $dayOfMonth=sprintf("%02d", $dayOfMonth);
> $date = "$months[$month]$dayOfMonth06";
That won't work because the variable $dayOfMonth06 doesn't contain any data.
You probably want:
my ( $day, $month, $year ) = ( localtime )[ 3, 4, 5 ];
my $date = sprintf '%02d%02d%02d', $month + 1, $day, $year % 100;
> #Read each file beginning with system date from directory
> @files=grep(/^$date/,readdir(DH));
> closedir (DH);
>
>
> foreach $file (@files) {
> open (data, "$dir$file") or die "Cannot open file: $!";
> while ( <data> ) {
> if ( /JOBNAME/ ) {
> $job = substr($_,8,8);
> chomp($job);
Do you really need to use chomp?
> }
> elsif ( /\.TIF\s{12}/ ) {
> my $box = substr($_,73,6);
> printf "$box $job $file\n";
> last;
> }
> }}
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: Thu, 02 Nov 2006 22:07:06 +0100
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Sorting and Writing Effecient Code
Message-Id: <eidohf$phc$1@mlucom4.urz.uni-halle.de>
Thus spoke banker123 (on 2006-11-02 20:36):
> 2. This program executes every 15 seconds to output the contents of
> the directory. The output is used to control work flow and meet crucial
> deadlines. Is this effeciently written? Any suggestions?
>
> My first "production" perl program, after reading and learning perl for
> about a month.
This is really good for a "first time program" ;-)
I don't know your files, but I straightened the
program a bit (all programmers do so with other
peoples code ;-), maybe it won't work (in the third
part) because I had to guess what your data is like.
...
# date stuff
my ($d, $m, $y) = (localtime)[3..5];
my $date = sprintf "%02d"x3, $m+1, $d, $y-100;
# directory stuff
my $dir = shift or die "no dir given";
opendir(DH, $dir) || die "$dir: $!";
my @files = grep /^$date/, readdir(DH);
closedir DH;
# file stuff
foreach my $fname (@files) {
open(my $fh, "$dir$fname") or die "$fname: $!";
my ($job, $box);
while( <$fh> ) {
# extract something
($job) = /.{8}(.{8})/ if /JOBNAME/;
# extract something else
($box) = /.{73}(.{6})/
and printf "$box $job %s $fname\n", ' 'x20
and last if /\.TIF\s{12}/
}
close $fh;
}
Don't forget to close your files, otherwise
your program will fail sensational ...
Regards
Mirco
------------------------------
Date: Thu, 02 Nov 2006 21:51:26 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Sorting and Writing Effecient Code
Message-Id: <yLt2h.37850$H7.30647@edtnps82>
Mirco Wahab wrote:
> Thus spoke banker123 (on 2006-11-02 20:36):
>
>>2. This program executes every 15 seconds to output the contents of
>>the directory. The output is used to control work flow and meet crucial
>>deadlines. Is this effeciently written? Any suggestions?
>>
>>My first "production" perl program, after reading and learning perl for
>>about a month.
>
> This is really good for a "first time program" ;-)
>
> I don't know your files, but I straightened the
> program a bit (all programmers do so with other
> peoples code ;-), maybe it won't work (in the third
> part) because I had to guess what your data is like.
>
> ...
> # date stuff
> my ($d, $m, $y) = (localtime)[3..5];
> my $date = sprintf "%02d"x3, $m+1, $d, $y-100;
^^^^^^
Subtracting 100 from $y will only work for 21st century dates.
$ perl -le'print( ( 1999 - 1900 ) - 100 )'
-1
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: Thu, 02 Nov 2006 22:25:41 +0100
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Sorting and Writing Effecient Code
Message-Id: <eidpkb$prr$1@mlucom4.urz.uni-halle.de>
Thus spoke banker123 (on 2006-11-02 21:46):
> How do I store the variables into an array, push or pop command, does
> this have much overhead?
push @array,... and generic array access is
very very fast in Perl, at least compared
to Ruby and Python. Once I tried to beat
the perl array handling by a "clever sequence"
of pack/unpack/substr on a scalar, which failed
(... to be faster than perl's arrays).
> I woul like the saort to point to a sort
> order file that containas priorites. Example:
> Variables
> Box 1
> Box 2
> Box 3
>
> Prioroties table
> Box 3
> Box 1
> Box 2
>
> Sorted Array
> Box 3
> Box 1
> Box 2
So you need to sort your array by an order
given by an "external index". This is somehow
standard and can be found eg. in 'perlfaq 4'
%priority = (
'Box 1' => 2,
'Box 2' => 3,
'Box 3' => 1,
);
@sorted = sort { $priority{$b} <=> $priority{$a} } @unsorted;
Regards
Mirco
------------------------------
Date: 02 Nov 2006 22:42:58 GMT
From: xhoster@gmail.com
Subject: Re: Sorting and Writing Effecient Code
Message-Id: <20061102174319.822$6E@newsreader.com>
"banker123" <bradbrockman@yahoo.com> wrote:
> > > Question
> > > 1. How do I sort the variables in a scalar context not an array?
> > > Should I be reading the variables I have extracted into an array?
> >
> > If you want to sort them, then you need to store them. Either an
> > array, or maybe a hash.
>
> How do I store the variables into an array, push or pop command, does
> this have much overhead?
Perl's "push" has about as low overhead as you can have and still be using
Perl. If you need lower overhead than push, you are probably using the
wrong language in the first place.
> I woul like the saort to point to a sort
> order file that containas priorites. Example:
>
> Variables
> Box 1
> Box 2
> Box 3
>
> Prioroties table
> Box 3
> Box 1
> Box 2
>
> Sorted Array
> Box 3
> Box 1
> Box 2
From this example it isn't all that clear what you mean. "Sorted Array"
happens to be an exact copy of "Prioroties table" in this case, but
presumably that is just an accident? I'm guessing you want to keep the
things in priority table's order, but include them only if they also appear
in "Variables". In that case, you would store the "Variables" in a hash.
Then you would loop through priority table, printing out only those things
which appear in the hash.
> > Every time you execute this script, it reprocesses the same files it
> > already processed the last time. That is the fundamental inefficiency,
> > but how to fix it depends on external factors.
>
> Understood this is running real-time therefore the re-processing is
> acceptable.
I'm not sure I follow that. The more real-time your process is, the less
acceptable it is to not be efficient. Do you mean that some other process
is deleting files, so that large numbers of them won't accumulate?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 2 Nov 2006 12:18:33 -0800
From: "doolittle" <spam.meplease@ntlworld.com>
Subject: trying to use Games::Go::SGF
Message-Id: <1162498713.542753.301230@i42g2000cwa.googlegroups.com>
Hi,
My code stops (with Can't call method "move" on unblessed reference)
when i try to access the methods of a variation object. The first (non
variation) move is shown OK ('2:pd' in the output), and when i do
'print Dumper($var);', that kinda looks like its the right sort of
thing, but i can't do anything with it.
Code:
use strict;
use warnings;
use Games::Go::SGF;
use Data::Dumper;
my $sgf = new
Games::Go::SGF('(;GM[1]FF[4]SZ[19];B[pd](;W[pp])(;W[cf]))');
print Dumper($sgf);
my $move_no = 1;
while (my $walker = $sgf->move($move_no++)) {
if (ref($walker) eq 'Games::Go::SGF::Node'){
print "$move_no: ".$walker->move,"\n";
}
if (ref($walker) eq 'Games::Go::SGF::Variation'){
my $var = $walker->variation(0);
print Dumper($var);
my $varwalker = $var->move(1); # fails here
print '1: '.$varwalker->move,"\n";
}
}
This prints out:
Can't call method "move" on unblessed reference at go2.pl line 19.
(in cleanup) Can't use string ("Games::Go::SGF::Node::DESTROY") as a
subroutine ref while "strict refs" in use at
C:/Perl/site/lib/Games/Go/SGF.pm line 83.
$VAR1 = bless( [
bless( {
'next' => bless( {
'next' => bless( [
[
bless( {
'next' => undef,
'W' => 'pp',
'moves_to_first_variation' => 0
}, 'Games::Go::SGF::Node' ),
{
'next' => undef
}
],
[
bless( {
'next' => undef,
'W' => 'cf',
'moves_to_first_variation' => 0
}, 'Games::Go::SGF::Node' ),
{
'next' => undef
}
]
],
'Games::Go::SGF::Variation' ),
'B' => 'pd'
}, 'Games::Go::SGF::Node' ),
'FF' => '4',
'moves_to_first_variation' => 2,
'GM' => '1',
'SZ' => '19'
}, 'Games::Go::SGF::Node' ),
$VAR1->[0]{'next'},
$VAR1->[0]{'next'}{'next'},
{
'next' => undef
}
], 'Games::Go::SGF' );
2: pd
$VAR1 = [
bless( {
'next' => undef,
'W' => 'pp',
'moves_to_first_variation' => 0
}, 'Games::Go::SGF::Node' ),
{
'next' => undef
}
];
------------------------------
Date: 2 Nov 2006 13:54:49 -0800
From: "caradomski@hotmail.com" <caradomski@hotmail.com>
Subject: WIN32::OLE excel date
Message-Id: <1162504488.843114.326130@i42g2000cwa.googlegroups.com>
I need help retrieving the date from excel using the Win32::OLE pm.
here is my program...
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on
errors...
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit'); # get already
active Excel
# application or
open new
my $Book = $Excel->Workbooks->Open("C:\\TMP\\test1.xls"); # open Excel
file
my $Sheet = $Book->Worksheets(1); # select
worksheet number 1
my $array = $Sheet->Range("A1:D5")->{'Value'}; # get the
contents
$Book->Close;
foreach my $ref_array (@$array) { # loop through
the array
# referenced by
$array
foreach my $scalar (@$ref_array) {
print "$scalar\t";
}
print "\n";
}
When ever the program prints a date from the excel file I get the
following results...
Win32::OLE::Variant=SCALAR(0x19f7b1c)
how do I get the program to print out 10/1/2006 ?
Please help!!!
------------------------------
Date: 2 Nov 2006 11:20:36 -0800
From: s1037989@gmail.com
Subject: Wrapper application
Message-Id: <1162495236.199017.189080@h54g2000cwb.googlegroups.com>
I want to write a Perl program that is a wrapper for another program.
The Perl program will stay running indefinitely and therefore I would
like the underlying program to stay running indefinitely as well. How
can I have my Perl program launch the other program and continuously
feed it data via stdout to the sub's stdin and read the sub's stdout on
my Perl's stdin without the sub exiting after each request?
Speaking less generically, for prototyping purposes, I want to expand
the capabilities of squidGuard using Perl. Therefore, the
redirector_program in squid will be my Perl program which I would like
to just be a wrapper around squidGuard. But I don't want to have to
relaunch squidGuard for EVERY request.
------------------------------
Date: Thu, 02 Nov 2006 20:37:05 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Wrapper application
Message-Id: <v1ikk29grts46p7r1sv93nks6a5bbhmkg9@4ax.com>
On 2 Nov 2006 11:20:36 -0800, s1037989@gmail.com wrote:
>I want to write a Perl program that is a wrapper for another program.
>The Perl program will stay running indefinitely and therefore I would
>like the underlying program to stay running indefinitely as well. How
>can I have my Perl program launch the other program and continuously
>feed it data via stdout to the sub's stdin and read the sub's stdout on
>my Perl's stdin without the sub exiting after each request?
IIUC you want IPC::Open2. But then I hope that when you write 'sub'
you mean the wrapped program. And of course you wouldn't be reading
its STDOUT from your script's STDIN, but from another handle. However
how could that possibly be a problem for you?
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: 2 Nov 2006 12:26:50 -0800
From: s1037989@gmail.com
Subject: Re: Wrapper application
Message-Id: <1162499210.375969.88510@h48g2000cwc.googlegroups.com>
Michele Dondi wrote:
> On 2 Nov 2006 11:20:36 -0800, s1037989@gmail.com wrote:
>
> >I want to write a Perl program that is a wrapper for another program.
> >The Perl program will stay running indefinitely and therefore I would
> >like the underlying program to stay running indefinitely as well. How
> >can I have my Perl program launch the other program and continuously
> >feed it data via stdout to the sub's stdin and read the sub's stdout on
> >my Perl's stdin without the sub exiting after each request?
>
> IIUC you want IPC::Open2. But then I hope that when you write 'sub'
> you mean the wrapped program. And of course you wouldn't be reading
> its STDOUT from your script's STDIN, but from another handle. However
> how could that possibly be a problem for you?
Thank you, Michele! That is EXACTLY what I needed!
For those who might stumble across this thread:
(Please ignore the uselessness and redunancy... This is a work in
progress and I just wanted to provide a real-life, working example for
the benfit of others. Again, this code base can be used to extend the
functionality of squidGuard -- not recommended outside of prototyping.)
use URI::Split qw(uri_split uri_join);
use IPC::Open2;
our $request;
our $response;
my $pid = open2(\*CHLD_OUT, \*CHLD_IN, '/usr/bin/squidGuard', '-c',
'/etc/squid/squidGuard.conf');
while ( chomp($request = <STDIN>) ) {
print CHLD_IN "$request\n";
chomp($response = <CHLD_OUT>);
$response = $request unless $response;
my ($uri, $dummy, $ident, $method) = split /\s+/, $response;
my ($scheme, $rfqdn, $path, $query, $frag) = uri_split($uri);
my $newuri = uri_join($scheme, $rfqdn, $path, undef, undef);
my ($cip, $lfqdn) = split /\//, $dummy;
my ($domain, $uid) = $ident =~ /%5c/ ? split /%5c/, $ident :
(undef, $ident);
($ident) = defined $domain ? "$domain\\$uid" : $uid;
$response = "$newuri $cip/$lfqdn $ident $method";
message(0, $request eq $response ? "+++ OK: $request" : "---
ERR: $response");
print $request eq $response ? "\n": "$response\n";
}
> 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: 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 9923
***************************************