[26626] in Perl-Users-Digest
Perl-Users Digest, Issue: 8736 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 6 09:05:12 2005
Date: Tue, 6 Dec 2005 06:05:04 -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 Tue, 6 Dec 2005 Volume: 10 Number: 8736
Today's topics:
Re: @INC and win32 <1usa@llenroc.ude.invalid>
Re: @INC and win32 <1usa@llenroc.ude.invalid>
Slow insertion to hashes? <jindroush.nospam@seznam.cz>
Re: Slow insertion to hashes? <1usa@llenroc.ude.invalid>
Re: Slow insertion to hashes? <1usa@llenroc.ude.invalid>
Re: Win32::OLE::GetObj question <ftoewe@austin.rr.com>
Re: Win32::OLE::GetObj question <ftoewe@austin.rr.com>
Re: Win32::OLE::GetObj question <1usa@llenroc.ude.invalid>
Re: Win32::OLE::GetObj question <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 06 Dec 2005 11:09:30 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: @INC and win32
Message-Id: <Xns97243EABB1FD0asu1cornelledu@127.0.0.1>
Jeff Thies <jeff@spamalanadingong.com> wrote in news:SG9lf.10873$wf.5712
@newsread3.news.atl.earthlink.net:
> perl on win32 (web) never includes the current directory in the @INC
> search path.
What do you mean (web)?
With CGI scripts, there has never been any guarantee that the web server
will cd to the directory in which your script resides.
> I'd like to do this without having to write:
>
> use lib 'path to lib'; on every page.
What page? That is Perl code, and should be in your Perl script.
> Irritated by win32...
This has nothing to do with Win32.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 06 Dec 2005 11:11:22 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: @INC and win32
Message-Id: <Xns97243EFC79E38asu1cornelledu@127.0.0.1>
Jeff Thies <jeff@spamalanadingong.com> wrote in news:UIdlf.30$Dd2.3
@newsread3.news.atl.earthlink.net:
> <snip>
>
>> How would $ENV{DOCUMENT_ROOT} be Win32 specific?
>
> It's not. But it does not show up on win32 machines. Lots of missing
> stuff in %ENV.
That cannot be. It seems to me you have a web server configuration problem
(which is off-topic here).
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 06 Dec 2005 13:38:44 +0100
From: Jindroush <jindroush.nospam@seznam.cz>
Subject: Slow insertion to hashes?
Message-Id: <dn40on$2msq$1@news.vol.cz>
Hi,
I have to load a file. I 'index' the records in two hashes. At the
beginning I do:
my $fl = -s $in;
my $recs = int( $fl / 85 );
keys( %$hr1 ) = $recs;
keys( %$hr2 ) = $recs if defined $hr2;
then for each record:
$$hr1{ lc $fname } = \%H;
if( defined $hr2 )
{
$$hr2{ $H{ hdr } . $H{ ent } } = \%H;
}
In %H is my data stored. This works good up to cca 70000 records (file1
has about 91000 records, each record is about 85 chars, split in 6
strings). Then it is _DEAD SLOW_. I load three such files in 3 (6)
different hashes. The two other files are also _DEAD SLOW_. I have quite
fast computer and s**tloads of free ram. Running: v5.6.1 built for
MSWin32-x86-multi-thread (activestate) on WXP (no way to change the perl
version/os).
Why is it so slow? How can I make it faster?
Regards,
Jindroush
------------------------------
Date: Tue, 06 Dec 2005 12:51:01 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Slow insertion to hashes?
Message-Id: <Xns97244FE19C139asu1cornelledu@127.0.0.1>
Jindroush <jindroush.nospam@seznam.cz> wrote in news:dn40on$2msq$1@news.vol.cz:
> I have to load a file. I 'index' the records in two hashes. At the
> beginning I do:
> my $fl = -s $in;
> my $recs = int( $fl / 85 );
> keys( %$hr1 ) = $recs;
> keys( %$hr2 ) = $recs if defined $hr2;
>
> then for each record:
> $$hr1{ lc $fname } = \%H;
>
> if( defined $hr2 )
> {
> $$hr2{ $H{ hdr } . $H{ ent } } = \%H;
> }
Please post a short but complete script that still exhibits the
problem. As it is, there are two many unknowns in what you have
posted.
The posting guidelines for this group will show you how to put
together such a script.
> In %H is my data stored. This works good up to cca 70000 records
> (file1 has about 91000 records, each record is about 85 chars, split
> in 6 strings). Then it is _DEAD SLOW_. I load three such files in 3
> (6) different hashes. The two other files are also _DEAD SLOW_. I have
> quite fast computer and s**tloads of free ram. Running: v5.6.1 built
> for MSWin32-x86-multi-thread (activestate) on WXP (no way to change
> the perl version/os).
>
> Why is it so slow?
You might be iterating over files many times. You might be slurping
large amounts of data. There might be a memory leak. Or, the keys
you are using might be generating too many collusions
(see <URL:http://www.cs.rice.edu/~scrosby/hash/CrosbyWallach_UsenixSec2003/index.html>)
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 06 Dec 2005 12:57:26 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Slow insertion to hashes?
Message-Id: <Xns972450F837046asu1cornelledu@127.0.0.1>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
news:Xns97244FE19C139asu1cornelledu@127.0.0.1:
> ... the keys you are using might be generating too many
> collusions
Oh, a conspiracy theory ;-).
Please s/collusion/collision/
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 06 Dec 2005 13:18:30 GMT
From: "Fred Toewe" <ftoewe@austin.rr.com>
Subject: Re: Win32::OLE::GetObj question
Message-Id: <Gcglf.39685$Ox.2137@tornado.texas.rr.com>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
news:Xns9723D447CAB0Dasu1cornelledu@127.0.0.1...
> "Fred Toewe" <ftoewe@austin.rr.com> wrote in
> news:tp5lf.31503$%i.27544@tornado.texas.rr.com:
>
>> Dear List,
>>
>> Please excuse if this is a well known fact, but I need help. If it
>> is, please just give me a pointer to the location of the answer.
>>
>> I need to scrape data from an Excel file (that belongs to another
>> group and therefore can probably not be altered) and the darn thing is
>> setup to politely encourage 'ReadOnly access'. This causes a dialog
>> box to open asking whether to open as ReadOnly or not.
>>
>> My problem is this dialog box - it seems to have to be answered
>> manually rather than programmatically. Is there a way around this?
>>
>> I have tried setting ReadOnly = 1 in the argument list, but not
>> succeeded, so far. Perhaps I did it wrong. I'm using Activestate
>> Perl 5.8.7 with Win32:: OLE.
>
> You can access MS VBA editor from Tools -> Macro. Once in the editor,
> use View -> Object Browser to get information about objects, methods,
> and properties.
>
> Now, you can see:
>
> Function Open(Filename As String, [UpdateLinks], [ReadOnly], [Format],
> [Password], [WriteResPassword], [IgnoreReadOnlyRecommended], [Origin],
> [Delimiter], [Editable], [Notify], [Converter], [AddToMru], [Local],
> [CorruptLoad]) As Workbook
> Member of Excel.Workbooks
>
> So,
>
> $excel->Workbooks->Open('filename', undef, 1);
>
> should work.
>
> If you have problems, please post a short but complete script still
> exhibiting the problem.
>
> Sinan
>
> --
> A. Sinan Unur <1usa@llenroc.ude.invalid>
> (reverse each component and remove .invalid for email address)
>
> comp.lang.perl.misc guidelines on the WWW:
> http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
>
Sinan,
Thanks for answering...
The Excel feature that is giving me trouble is the 'ReadOnly Recommend' bit
in the security tab of the options dialog is set because of the way the
owner uses it (Many people have to access the same file).
My code is at work, so will have to go with my lousy memory. It is truly a
one liner...
In perl:
use strict;
use warnings;
use Win32::OLE;
my $book = Win32::OLE->GetObject ("filename", {ReadOnly => 1});
The above does not prevent the dialog from opening and it still elicits a
warning that the second argument should be a 'Destroy' function.
I've also tried, based on your example:
my $book = Win32::OLE->GetObject ("filename", undef,1);
...and...
my $excel->Workbooks->Open('filename', undef, 1);
which both give full blown usage errors.
Thanks for trying... and cheers,
Fred
------------------------------
Date: Tue, 06 Dec 2005 13:51:21 GMT
From: "Fred Toewe" <ftoewe@austin.rr.com>
Subject: Re: Win32::OLE::GetObj question
Message-Id: <tHglf.31963$%i.18953@tornado.texas.rr.com>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
news:Xns9723D447CAB0Dasu1cornelledu@127.0.0.1...
> "Fred Toewe" <ftoewe@austin.rr.com> wrote in
> news:tp5lf.31503$%i.27544@tornado.texas.rr.com:
>
>> Dear List,
>>
>> Please excuse if this is a well known fact, but I need help. If it
>> is, please just give me a pointer to the location of the answer.
>>
>> I need to scrape data from an Excel file (that belongs to another
>> group and therefore can probably not be altered) and the darn thing is
>> setup to politely encourage 'ReadOnly access'. This causes a dialog
>> box to open asking whether to open as ReadOnly or not.
>>
>> My problem is this dialog box - it seems to have to be answered
>> manually rather than programmatically. Is there a way around this?
>>
>> I have tried setting ReadOnly = 1 in the argument list, but not
>> succeeded, so far. Perhaps I did it wrong. I'm using Activestate
>> Perl 5.8.7 with Win32:: OLE.
>
> You can access MS VBA editor from Tools -> Macro. Once in the editor,
> use View -> Object Browser to get information about objects, methods,
> and properties.
>
> Now, you can see:
>
> Function Open(Filename As String, [UpdateLinks], [ReadOnly], [Format],
> [Password], [WriteResPassword], [IgnoreReadOnlyRecommended], [Origin],
> [Delimiter], [Editable], [Notify], [Converter], [AddToMru], [Local],
> [CorruptLoad]) As Workbook
> Member of Excel.Workbooks
>
> So,
>
> $excel->Workbooks->Open('filename', undef, 1);
>
> should work.
>
> If you have problems, please post a short but complete script still
> exhibiting the problem.
>
> Sinan
>
> --
> A. Sinan Unur <1usa@llenroc.ude.invalid>
> (reverse each component and remove .invalid for email address)
>
> comp.lang.perl.misc guidelines on the WWW:
> http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
>
Sinar,
I'm re-replying to your answer as I played with your idea further and got:
use strict;
use warnings;
use Win32::OLE;
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
my $Book = $Excel->Workbooks->Open("filename", undef, 1);
which WORKS!
Thanks a million.
Fred
------------------------------
Date: Tue, 06 Dec 2005 13:55:05 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Win32::OLE::GetObj question
Message-Id: <Xns97245ABE22494asu1cornelledu@127.0.0.1>
"Fred Toewe" <ftoewe@austin.rr.com> wrote in
news:Gcglf.39685$Ox.2137@tornado.texas.rr.com:
>
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
> news:Xns9723D447CAB0Dasu1cornelledu@127.0.0.1...
>> "Fred Toewe" <ftoewe@austin.rr.com> wrote in
>> news:tp5lf.31503$%i.27544@tornado.texas.rr.com:
...
>>> I need to scrape data from an Excel file (that belongs to another
>>> group and therefore can probably not be altered) and the darn thing
>>> is setup to politely encourage 'ReadOnly access'. This causes a
>>> dialog box to open asking whether to open as ReadOnly or not.
>>>
>>> My problem is this dialog box - it seems to have to be answered
>>> manually rather than programmatically.
...
>> $excel->Workbooks->Open('filename', undef, 1);
>>
>> should work.
>>
>> If you have problems, please post a short but complete script still
>> exhibiting the problem.
...
> Thanks for answering...
You are welcome, but please do not quote signatures.
> The Excel feature that is giving me trouble is the 'ReadOnly
> Recommend' bit
I understand that.
> use strict;
> use warnings;
> use Win32::OLE;
>
> my $book = Win32::OLE->GetObject ("filename", {ReadOnly => 1});
>
> The above does not prevent the dialog from opening and it still
> elicits a warning that the second argument should be a 'Destroy'
> function.
Of course not. The second argument to the GetObject method is a
destructor. I do not understand your infatuation with this method given
that it does not allow you to specify any options (and is documented
that way).
> I've also tried, based on your example:
> my $book = Win32::OLE->GetObject ("filename", undef,1);
> ...and...
> my $excel->Workbooks->Open('filename', undef, 1);
Both the Win32::OLE documentation, and my previous posts related to
Win32::OLE, give ways of first getting an application object, then
calling methods on that object. In all honesty, I would have expected
you to do a little work, and search the archives of this newsgroup for
Win32::OLE usage examples to see how that is done.
See, for example,
http://groups.google.com/group/comp.lang.perl.misc/msg/cddb05950f619e22
First, get a valid application object in $excel, and call methods on it.
Here is something that works on my system with a workbook with the read
only recommended bit set:
#!/usr/bin/perl
use strict;
use warnings;
use File::Spec::Functions qw(canonpath catfile);
use FindBin qw( $Bin );
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;
my $Excel;
eval {
$Excel = Win32::OLE->GetActiveObject('Excel.Application')
};
die "Excel not installed" if $@;
unless (defined $Excel) {
$Excel = Win32::OLE->new('Excel.Application', sub { $_[0]->Quit })
or die "Cannot start Excel";
}
$Excel->{Visible} = 1;
my $Book = $Excel->Workbooks->Open(
canonpath(catfile $Bin, 'Book1.xls'),
undef,
1,
);
sleep 5;
__END__
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 06 Dec 2005 13:58:36 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Win32::OLE::GetObj question
Message-Id: <Xns97245B56EFD80asu1cornelledu@127.0.0.1>
"Fred Toewe" <ftoewe@austin.rr.com> wrote in
news:tHglf.31963$%i.18953@tornado.texas.rr.com:
>
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
> news:Xns9723D447CAB0Dasu1cornelledu@127.0.0.1...
>> "Fred Toewe" <ftoewe@austin.rr.com> wrote in
>> news:tp5lf.31503$%i.27544@tornado.texas.rr.com:
>>
...
>>> My problem is this dialog box - it seems to have to be answered
>>> manually rather than programmatically. Is there a way around this?
...
>> $excel->Workbooks->Open('filename', undef, 1);
>>
...
> Sinar,
Just for the record, the correct spelling of my name is Sinan.
> I'm re-replying to your answer
Well, I replied to your previous reply ...
> use strict;
> use warnings;
> use Win32::OLE;
>
> my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
> || Win32::OLE->new('Excel.Application', 'Quit');
> my $Book = $Excel->Workbooks->Open("filename", undef, 1);
>
> which WORKS!
Yes it does. This is what I was hoping you would have tried, and my
response to your other post is probably going to sound too harsh.
Apologies.
> Thanks a million.
You are welcome.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
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 8736
***************************************