[23686] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5893 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 4 14:06:10 2003

Date: Thu, 4 Dec 2003 11:05:07 -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, 4 Dec 2003     Volume: 10 Number: 5893

Today's topics:
    Re: Add File Names with Time Stamp <usenet@morrow.me.uk>
    Re: Can perl be used to test ISP upload speed? <usenet@morrow.me.uk>
    Re: Can you tell me how to change from regular Perl to  <Temp@NoSuchDomain.Info>
    Re: foreach counter <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: Generating Day of Week in Pure Perl <usenet@morrow.me.uk>
        How to open a file from the end and read the last 100 l (Rui Vilao)
    Re: How to open a file from the end and read the last 1 <uri@stemsystems.com>
        Idiom for array index that I'm foreach'ing over? (Tim Shoppa)
    Re: Idiom for array index that I'm foreach'ing over? (Lack Mr G M)
    Re: Idiom for array index that I'm foreach'ing over? (Anno Siegel)
    Re: In search of elegant code: is variable is within a  <drumspoorly@reachone.net>
    Re: Is perl 5.8 slower than 5.005_03? <thepoet_nospam@arcor.de>
    Re: My apologizes (Was: Descending sort) <colossus_NOSPAM_@freemail.it>
    Re: My apologizes (Was: Descending sort) <usenet@morrow.me.uk>
    Re: net::scp::expect error (Chandrashekar Tippur)
    Re: question about installation of GD::Text on cygwin ( (Upstart)
    Re: Win32::OLE and creation of pivot table in Excel <joeminga@yahoo.com>
    Re: Your code doesn't work <dover@nortelnetworks.com>
    Re: Your code doesn't work <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 4 Dec 2003 18:36:55 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Add File Names with Time Stamp
Message-Id: <bqnus7$sn2$1@wisteria.csv.warwick.ac.uk>


"Picker Leon" <Temp@NoSuchDomain.Info> wrote:
> >   my $ext = "";
> >   while(-e "$timestamp$ext.jpg") {
> >       $ext++;
> >       $ext = "A" if $ext == 1;
> >   }
> 
> what is te ext for? if you have ext as '', then $timestampe$ext is nothing
> but still  $timestamp.

Yes. That is the point.

> how can you ext++ a string?

Because Perl is cleverer (or mayber just DWIMer) than you think
:). Read the docs for '++' in perldoc perlop.

> if you ''++ do you get 1 or A or what?

1. Hence my changing it to an 'A', which is what I wanted to
get. 'A'++, however, is 'B'.

> can you show me some reference to read about -e? thank you.

perldoc -f -X

> my scripts work 100% fine with my 1000 files.

I'm sorry, I assumed that since you were asking for help the script
was not working as you wished it to. I might think more than twice
about answering, next time.

> Could you give some example in which why your changed code is better
> and mine is not working.

Take a directory containing two files with the same timestamp. Run
your script. Start again; run mine. Observe the difference.

Ben

-- 
"If a book is worth reading when you are six,                * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis


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

Date: Thu, 4 Dec 2003 18:39:43 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Can perl be used to test ISP upload speed?
Message-Id: <bqnv1f$sn2$2@wisteria.csv.warwick.ac.uk>


Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> [ Please do not top post! ]
> 
> Guy wrote:
> > Gunnar Hjalmarsson wrote:
> >> Guy wrote:
> >>> But I can't think of a way that perl could be used to test
> >>> upload speed.
> >> 
> >> Then you don't know much about Perl, do you?
> > 
> > I thought my previous postings already showed that :-)
> 
> Well, sorry for my sulky reply. I just thought that your original post
> was unnecessarily wordy. If I understand you right, you want to know:
> 
> "How can I have Perl measure the time it takes to run a certain
> operation?"

I would have said the OP would be better interpreted as "How can I
write a CGI that will time a file upload submitted to it?"; which I
don't *think* can be done...

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Thu, 04 Dec 2003 18:51:54 GMT
From: "Picker Leon" <Temp@NoSuchDomain.Info>
Subject: Re: Can you tell me how to change from regular Perl to Mod_perl
Message-Id: <enLzb.150080$Ec1.5961113@bgtnsc05-news.ops.worldnet.att.net>

> On Thu, 04 Dec 2003 05:30:47 +0000, Picker Leon wrote:
> > Do I just simple add a
> > use mod_perl;
> > then all my old perl program can work with mod_perl?
>
> No.  Please read the documentation on http://perl.apache.org/ before you
> continue asking.  There's even a document describing how to migrate from
> CGI to mod_perl on that site.
I still could not find it. There are 1.0 2.0 docutmens and tutorio but
nothing as you said.
I see a lot of handlers in mod_perl, but I just want a simple way to change
my current scripts to mod_perl for faster time. The less change the better.


>
> > I looked at perl.apache.org, but could not find any sample codes.
>
> That's bullshit, actually.  No more, no less.
>




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

Date: Thu, 4 Dec 2003 09:33:52 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: foreach counter
Message-Id: <06rnqb.4nc.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On 2003-12-04, Carsten Aulbert <carsten@welcomes-you.com> wrote:
>
> foreach (@array) {
>    print $_, "\t";
> }
>
> will print all occurences in @array (even though 'join' would probably be 
> faster), but I think what you want is changing the values in @array which 
> is only possible as you described in your first example or by using a hash 
> (AFAIK).

Check perldoc perlsyn: if any of the foreach list are lvalues, assigning
to $_ assigns to the original lvalue, so for example

foreach (@array) {
	$_ .= "\n";
}

will ''unchomp'' the values in @array.

- --keith

- -- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/z2/qhVcNCxZ5ID8RAuY+AJ0cS0n+HDdX4gTiHXwctRm7jZcy6ACgjevi
+o9fVpYi9AwcztT8zx/wj84=
=gArY
-----END PGP SIGNATURE-----


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

Date: Thu, 4 Dec 2003 18:42:39 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Generating Day of Week in Pure Perl
Message-Id: <bqnv6v$sn2$3@wisteria.csv.warwick.ac.uk>


Tore Aursand <tore@aursand.no> wrote:
> On Thu, 04 Dec 2003 08:24:52 +0000, Bart Lateur wrote:
> >>> I cannot use the POSIX package.
> 
> >> Why?
> 
> > For the same reason he can't use any other module. The ISP probably
> > deleted it and isn't willing to install it again.
> 
> Why would an ISP delete a module that comes with Perl?

A perhaps better question is 'Why would anyone *use* an ISP that
deleted a module that comes with Perl?' :).

Ben

-- 
  The cosmos, at best, is like a rubbish heap scattered at random.
                                                         - Heraclitus
  ben@morrow.me.uk


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

Date: 4 Dec 2003 10:04:41 -0800
From: rui.vilao@rocketmail.com (Rui Vilao)
Subject: How to open a file from the end and read the last 100 lines
Message-Id: <385a715f.0312041004.71e2d777@posting.google.com>

Greetings, 

I am writing some Perl script to check some patterns errors in an
alert log (Oracle alert log).  The file can't get quite large.
Therefore I would like write a Perl script that runs every day via at
and opens the file from the end to read the last 100 lines. How can I
do this?
Any help/suggestion is highly appreciated. 

Thanks in advance for your help, 

Kind Regards, 

Rui Vilao


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

Date: Thu, 04 Dec 2003 18:05:50 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How to open a file from the end and read the last 100 lines
Message-Id: <x7k75c1mrl.fsf@mail.sysarch.com>

>>>>> "RV" == Rui Vilao <rui.vilao@rocketmail.com> writes:

  RV> I am writing some Perl script to check some patterns errors in an
  RV> alert log (Oracle alert log).  The file can't get quite large.
  RV> Therefore I would like write a Perl script that runs every day via at
  RV> and opens the file from the end to read the last 100 lines. How can I
  RV> do this?

use File::ReadBackawards ;

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 4 Dec 2003 07:42:42 -0800
From: shoppa@trailing-edge.com (Tim Shoppa)
Subject: Idiom for array index that I'm foreach'ing over?
Message-Id: <bec993c8.0312040742.2940f2ce@posting.google.com>

OK, I'm a former (and current!) Fortran programmer.  But often I end up
with Perl data structures where I not only have to step through each element of
an array, but also must know the index into the array.

I end up writing code that looks like

for my $i (0..$#a) {
  my $e = $a[$i];
  # Do stuff with $i and $e here
}

That's a bit ugly, I have a numeric loop, an extra variable, that funny
(0..$#a) construct, etc.  And if I have to "last" to bail out of the loop
I've lost my index and the array element that I bailed out at.

I'd rather write something like

for (@a) {
  # Do stuff with $_ and some magical variable telling me the index
}

in the same way that I can 

while (<>) {
  # Do stuff with $_ and the line number $. here
}

Is there some magical variable like $. for array loops?  Any better
idioms than what I'm currently doing?

Tim.


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

Date: Thu, 04 Dec 2003 17:09:27 GMT
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <2003Dec4.170927@ukwit01>

In article <bec993c8.0312040742.2940f2ce@posting.google.com>, shoppa@trailing-edge.com (Tim Shoppa) writes:
|>
|> OK, I'm a former (and current!) Fortran programmer.

   Ah, yes.  Real FORTRAN programmer can write FORTRAN in any language :-).

|>                                                       But often I end up
|> with Perl data structures where I not only have to step through each element of
|> an array, but also must know the index into the array.
|> 
|> I end up writing code that looks like
|> 
|> for my $i (0..$#a) {
|>   my $e = $a[$i];
|>   # Do stuff with $i and $e here
|> }
|> 
|> That's a bit ugly, I have a numeric loop, an extra variable, that funny
|> (0..$#a) construct, etc.  And if I have to "last" to bail out of the loop
|> I've lost my index and the array element that I bailed out at.

   So:

 my $i;
 for ($i = 0; $i < @a; $i++) {
    my $e = $a[$i];
# Do stuff with $i and $e here
    last if ($e > 20_000);  # eg: exit statement
 }

   And now, after the loop, $i is still set to the value causing the exit

|> Is there some magical variable like $. for array loops?  Any better
|> idioms than what I'm currently doing?

   Well, possibly better is:

 my $exiter;             # So it is undef
 for (my $i = 0; $i < @a; $i++) {
    my $e = $a[$i];
# Do stuff with $i and $e here
    if ($e > 20_000) {   # eg: exit statement
       $exiter = $i;
       last;
    }
 }

   And now, after the loop, $exiter is set to the value causing the exit
unless you reached the end of the array, in which case it is still
undefined. 


-- 
--------- Gordon Lack --------------- gml4410@ggr.co.uk  ------------
This message *may* reflect my personal opinion.  It is *not* intended
to reflect those of my employer, or anyone else.


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

Date: 4 Dec 2003 17:56:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <bqnsfo$ogu$1@mamenchi.zrz.TU-Berlin.DE>

Tim Shoppa <shoppa@trailing-edge.com> wrote in comp.lang.perl.misc:
> OK, I'm a former (and current!) Fortran programmer.  But often I end up
> with Perl data structures where I not only have to step through each element of
> an array, but also must know the index into the array.
> 
> I end up writing code that looks like
> 
> for my $i (0..$#a) {
>   my $e = $a[$i];
>   # Do stuff with $i and $e here
> }
> 
> That's a bit ugly, I have a numeric loop, an extra variable, that funny
> (0..$#a) construct, etc.  And if I have to "last" to bail out of the loop
> I've lost my index and the array element that I bailed out at.
> 
> I'd rather write something like
> 
> for (@a) {
>   # Do stuff with $_ and some magical variable telling me the index
> }
> 
> in the same way that I can 
> 
> while (<>) {
>   # Do stuff with $_ and the line number $. here
> }
> 
> Is there some magical variable like $. for array loops?  Any better
> idioms than what I'm currently doing?

Not really.  The variable you want has been proposed before, right down
to the name (re-use the deprecated $#), but it isn't implemented.

A single variable would be somewhat incomplete.  With nested for-loops
you'd also want a way to access the indices of enclosing loops.

If you want to keep the last index accessed, a while-loop is easier
to handle than a for-loop, because it doesn't take privacy of the
loop variable so serious:


    my $i = 0;
    while ( $i < @array ) {
        # do something with $array[ $i];
        last if bored();
        $i ++;                                            # hi Abigail
    }
    # use $i, it has the last value from the loop

But that's hardly an idiom, it's just a straight-forward way to do
something like that.

It may suffice to know what is left over from the array (the elements that
have *not* been processed).  If so, this is a bit more perlish:

    while ( @array ) {
        my $element = shift @array;
        # do something with $element
        last if bored();
    }
    # now @array is what the loop left over

If you happen to know the original number of elements in @array,
"$original_length - @array" is the last index used.

I say this is "more perlish" because it uses the array as a unit.  In
Fortran, an array is just a declaration, the only things you can actually
do something with are array elements, and the only way to access them is
through an index.

Perl can manipulate arrays as a whole, and doing that makes better
use of its high-level features.  Once you get accustomed to this style,
you'll find that you rarely want to loop over an index.  You loop over
array elements directly, and in fact map and grep do much of the looping.

If you actually need random access to elements, more often than not
the right data structure is a hash and not an array (even if the indices
happen to be numbers).  With hashes, indexed access, and hence loops
over hash keys, are more frequent than with arrays, though "each" and
"values" offer alternatives.

Anno


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

Date: Thu, 04 Dec 2003 07:34:49 -0800
From: Steve May <drumspoorly@reachone.net>
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <vsukta7bd8t38a@corp.supernews.com>

Matt Garrish wrote:
> "Jeff 'japhy' Pinyan" <pinyaj@rpi.edu> wrote in message
> news:Pine.SGI.3.96.1031203214500.1075836A-100000@vcmr-64.server.rpi.edu...
> 
>>On Wed, 3 Dec 2003, J. Gleixner wrote:
>>
>>
>>>sub is_between {
>>>my ($v, $l, $h) = @_;
>>>$l < $v && $v < $h;
>>>}
>>>
>>>if (is_between($foo, 1, 10)) {
>>
>>That seems to be a horrible way to send the arguments to the function.  If
>>the function's name is "between", I'd expect to send LOW, VAL, HIGH.
>>
> 
> 
> You should have read the documentation first...
> 
> Matt
> 
> 
  First smile of the day....

thanks,
s.



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

Date: Thu, 4 Dec 2003 15:48:07 +0100
From: "Christian Winter" <thepoet_nospam@arcor.de>
Subject: Re: Is perl 5.8 slower than 5.005_03?
Message-Id: <3fcf4929$0$20242$9b4e6d93@newsread2.arcor-online.net>

"Jon Reed" <jreed@ptc.com> wrote:
> I noticed that our website seemed slower with this new configuration. 
> Using Apache Benchmark confirmed that it was slower.  Next step was to
> eliminate the webserver, so executing a simple perl script 1000 times
> direct from the command line took about 30 seconds with perl 5.8. 
> Then I copied the perl 5.005_03 binary over from a very similar
> machine (that has not been rebuilt yet) and it takes 16 seconds for
> the same test!!

Was Perl built using usemymalloc=n (see output of "perl -V")?
This is known to slow down performance on Win32 systems, so maybe
it's similar on solaris.

-Christian



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

Date: Thu, 04 Dec 2003 15:08:19 +0100
From: Colossus <colossus_NOSPAM_@freemail.it>
Subject: Re: My apologizes (Was: Descending sort)
Message-Id: <bqnf1m$24gk31$1@ID-154800.news.uni-berlin.de>

Helgi Briem wrote:

> It's pretty late for that after having insulted almost
> everyone who might have a shot at solving your
> problem. 

My grandmother was used to tell me:
later is better than ever.
I had the humbleness to apologize, many others have not.

>Most of them have already killfiled you
> and will never see anything you post, ever again.

Who cares ? The world is a wheel who keeps turning. People
joines and leaves frequently the newsgroups. If I will post
again on this newsgroup others will surely reply me. Maybe you will
reply me one day...
-- 
Bye,
Colossus



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

Date: Thu, 4 Dec 2003 19:04:58 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: My apologizes (Was: Descending sort)
Message-Id: <bqo0gq$sn2$5@wisteria.csv.warwick.ac.uk>


Colossus <colossus_NOSPAM_@freemail.it> wrote:
> Helgi Briem wrote:
> > It's pretty late for that after having insulted almost
> > everyone who might have a shot at solving your
> > problem. 
> 
> My grandmother was used to tell me:
> later is better than ever.

ITYM never?

> I had the humbleness to apologize, many others have not.

Noone but you was in a position of needing to apologise, by the rules
of social interaction generally accepted in clpmisc. In case you are
unfamiliar with these, they include 'If you ask a stupid/unclear
question you must expect harsh words in response; you must not take
these to heart.'.

They also include 'Moralising is in general only acceptable from
regulars who have proved they have something of worth to contribute to
the group.'. (I realise I may be putting myself on the line here, but
I'll risk that... :) 

> >Most of them have already killfiled you
> > and will never see anything you post, ever again.
> 
> Who cares ? The world is a wheel who keeps turning. People
> joines and leaves frequently the newsgroups.

Useful, helpful and knowledgable people join relatively infrequently and
leave even less so.

> If I will post again on this newsgroup others will surely reply
> me.

These hypothetical 'others' are unlikely to be in a position to give
you as much useful help as Anno and the other regulars.

> Bye,

Bye...

Ben

[Good sigmonster! Here, have a cookie...]

-- 
       .  |  .
    \           /           The clueometer is reading zero.
  .               .
 __ <-----@       __                                           ben@morrow.me.uk


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

Date: 4 Dec 2003 09:40:28 -0800
From: ctippur@msn.com (Chandrashekar Tippur)
Subject: Re: net::scp::expect error
Message-Id: <629c1390.0312040940.281d8a89@posting.google.com>

Daniel,

SSH version is Secure Shell 3.2.5 and the OS is SunOS 2.8.

- Shekar

djberg96@hotmail.com (Daniel Berger) wrote in message news:<6e613a32.0312022134.54262725@posting.google.com>...
> ctippur@msn.com (Chandrashekar Tippur) wrote in message news:<629c1390.0312012051.69ccbe27@posting.google.com>...
> > All,
> > 
> > I am having some trouble with the module net::scp::expect. I am able
> > to scp manually.
> > 
> > The error that I am getting is:
> > 
> >  Error - last line returned was: pp                                   
> > |    3B |    3B/s | TOC: 0 at
> > /tmp/.itverify-1038/perl/lib/perl5/site_perl/5.6.1/Expect.pm line 733
> > 
> > 
> > Here is the snippet of code:
> > 
> >         $scpe = Net::SCP::Expect->new(host=>"$Host", user=>"$Login",
> > password=>"$Passwd", port=>"$sshport", protocol=>2, auto_yes=>1) ||
> > die "Incorrect Login or password\n";
> >         $scpe->scp("$line",'$remotepwd') || die "Hello";
> > 
> > Please help.
> > 
> > Thanks,
> > Shekar
> 
> Hi Shekar,
> 
> I need some more info:
> 
> What platform?
> Which version of ssh?
> 
> Also, try passing 'verbose => 1' and see if that gives you any more
> detail.  It looks like it's picking up some unexpected text at some
> point.  The verbose option should help me nail it down.
> 
> Regards,
> 
> Daniel Berger


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

Date: 4 Dec 2003 08:21:32 -0800
From: stimonyhall@netscape.net (Upstart)
Subject: Re: question about installation of GD::Text on cygwin (could be a Makefile q)
Message-Id: <79516caa.0312040821.1e9944e2@posting.google.com>

Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnbsq4d3.5j7.mgjv@verbruggen.comdyn.com.au>...
 
> Just for the heck of it, could you do something like:
> 
> $ cd /tmp
> $ h2xs -ACXn Foo
> Writing Foo/Foo.pm
> Writing Foo/Makefile.PL
> Writing Foo/README
> Writing Foo/test.pl
> Writing Foo/MANIFEST
> $ cd Foo
> [edit Makefile.PL and put "use GD;" near the top]
> $ perl Makefile.PL

This breaks!

$ h2xs -ACXn Foo
Defaulting to backwards compatibility with perl 5.8.2
If you intend this module to be compatible with earlier perl versions,
please
specify a minimum perl version with the -b option.

Writing Foo/lib/Foo.pm
Writing Foo/Makefile.PL
Writing Foo/README
Writing Foo/t/Foo.t
Writing Foo/MANIFEST

$ cat Makefile.PL 
use 5.008002;
use ExtUtils::MakeMaker;
use GD;  # jim add
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
    NAME              => 'Foo',
    VERSION_FROM      => 'lib/Foo.pm', # finds $VERSION
    PREREQ_PM         => {}, # e.g., Module::Name => 1.1
    ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
      (ABSTRACT_FROM  => 'lib/Foo.pm', # retrieve abstract from module
       AUTHOR         => 'Foo <foo@familiehaase.de>') : ()),
);

$ perl Makefile.PL 
Checking if your kit is complete...
Looks good

$

Silent failure to create a Makefile.

> If that breaks, then the problem is somewhere in the interaction
> between GD and MakeMaker, and that's probably worth a bug report to
> either P5P of Lincoln Stein.

What would be the most effective way to proceed? It is a bummer the
way this thing is not throwing some kind of error message. Is there a
debug switch somewhere?

Is there anybody out there who has my combination of a platform (win
2000, perl 5.8.2, cygwin) that has got this to work recently?

JIM


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

Date: Thu, 4 Dec 2003 10:28:52 -0500
From: "Domenico Discepola" <joeminga@yahoo.com>
Subject: Re: Win32::OLE and creation of pivot table in Excel
Message-Id: <osIzb.114594$PD3.5801343@nnrp1.uunet.ca>

"Domenico Discepola" <joeminga@yahoo.com> wrote in message
news:sRnzb.114158$PD3.5796620@nnrp1.uunet.ca...
>As I am new to
> Win32::OLE, I don't know how to "translate" the following VB Script
> (generated from a macro I recorded in Excel) into a "Win32::OLE" / perl
> version of those methods:



"Ben Liddicott" <ben.liddicott@comodogroup.com> wrote in message
news:bql555$vcc$1@kylie.comodogroup.com...
>>Hi Domenico,
>>
>>The ActiveState documentation has some pretty good examples, under "Using
OLE with Perl", which is in the table of contents >>under "ActivePerl
FAQ/Windows Specific".

>>Try also
>>   perldoc Win32::OLE

Thank you for your replies.  Unfortunately, I don't think I'm understanding
the documentation on Win32::OLE.  I've tried Activestate's, Roth's Book and
Microsoft MSDN.  My overall goal is to create an Excel worksheet with a
customized pivot table.  My code works except when I try to customize the
pivot table:

my $class = "Excel.Application";
my $file = "c:\\temp\\p2.xls";
my @arr01 = ( ["a", "b", "c"], [1, 2, 3] );  #simulate data
my $r = my $c = 0;

unlink( $file ) if ( -e $file ); #delete file if exists

 #Create application class called "$excel"
 my $excel = Win32::OLE->GetActiveObject( $class );

 if ( ! $excel ) {
  $excel = new Win32::OLE( $class, \&QuitApp ) || die "Could not create COM
${class} object\n";
 }

 $excel->{Visible} = 1;
 $excel->{SheetsInNewWorkbook} = 1;

 #create a new workbook
 my $workbook = $excel->Workbooks->Add();

 #create a new worksheet
 my $worksheet = $workbook->WorkSheets(1);
 $worksheet->{Name} = "gah";

#populate the 1st worksheet with data from the array
foreach ( @arr01 ) {
   for ( $c = 0; $c<3; $c++ ) {
      $worksheet->Cells($r+1, $c+1)->{Value} = $arr01[$r][$c];
   }
   $r++;
}

 #Create the pivot table - hard coded references for now
$workbook->PivotTableWizard( {
     SourceType => 1,
     SourceData => 'gah!R1C1:R2C3',
     TableDestination => "",
     TableName => "PivotTable1",
     HasAutoFormat => 1
     });

#######################################
# PROBLEM HERE
#I want to assign cell "a1" as the pivot table's row field
#  since creating the pivot table automatically created a new worksheet, you
must
#  reference the new worksheet
#Sample VBScript code taken from MSDN website:
#   Worksheets("sheet3").PivotTables(1).PivotFields("year").Orientation =
xlRowField

$workbook->WorkSheets(2)->PivotTables(1)->PivotFields(1)->( {Orientation =>
1});
#######################################3

 $workbook->SaveAs( $file );
 $workbook->Close();
exit 0;

The error message I get is:
OLE exception from "Microsoft Excel":
Unable to get the PivotTables property of the Worksheet class
Win32::OLE(0.1603) error 0x800a03ec

I assume that this means that there's some kind of problem with the
PivotTables property.  I checked the Excel object model
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaxl10/ht
ml/xltocObjectModelApplication.asp) and found that the PivotTables property
does belong to the worksheet class.

Any help would be appreciated.




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

Date: Thu, 04 Dec 2003 10:06:27 -0600
From: Robert Dover <dover@nortelnetworks.com>
Subject: Re: Your code doesn't work
Message-Id: <bqnlvh$ej7$1@zcars0v6.ca.nortel.com>

Colossus wrote:

> ...I will get counsel elsewhere,
> 
> Thank you,

No, thank you...



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

Date: Thu, 4 Dec 2003 18:49:37 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Your code doesn't work
Message-Id: <bqnvk1$sn2$4@wisteria.csv.warwick.ac.uk>


Colossus <colossus_NOSPAM_@freemail.it> wrote:
> > Then maybe programming isn't for you?
> 
> Ah ah ah ah ah ! That is very funny ! Programming must
> be difficult otherwise it is not programming ? Ah ah ah ah ah !

No. Programming *is* difficult. 

Particularly so if you do not have the right sort of mathematical/
logical intuition (though this is by no means to say that people who
do not cannot make perfectly good programmers: merely that they will
find it harder and less fun).

Ben

-- 
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t    # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.


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

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.  

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


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