[19104] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1299 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 13 14:06:35 2001

Date: Fri, 13 Jul 2001 11:05:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <995047516-v10-i1299@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 13 Jul 2001     Volume: 10 Number: 1299

Today's topics:
        Accessing Outlook PST file info with perl <EvR@compuserve.com>
    Re: Active State <bart.lateur@skynet.be>
        arrays & textfile lines (Casey Chambliss)
    Re: arrays & textfile lines <rsherman@ce.gatech.edu>
    Re: C libraries usage in Perl <dan@tuatha.sidhe.org>
    Re: Check for Dups! <cpryce@pryce.net>
        Content types in a mail (=?ISO-8859-1?Q?Morten_Tanger=E5s?=)
    Re: Content types in a mail <barmar@genuity.net>
    Re: Content types in a mail (=?ISO-8859-1?Q?Morten_Tanger=E5s?=)
        Continuation Fields in format <jmd52@cornell.edu>
    Re: easy multi-file find & replace? (Craig Berry)
    Re: Efficiency hit of $1 in Regexps? ctcgag@hotmail.com
        equivalence of \@$arrayref and $arrayref <chris.wallaceREMOVE_ME@lshtm.ac.uk>
    Re: equivalence of \@$arrayref and $arrayref <news@simonflack.com>
    Re: equivalence of \@$arrayref and $arrayref (Ronald Blaschke)
    Re: equivalence of \@$arrayref and $arrayref (Rafael Garcia-Suarez)
    Re: equivalence of \@$arrayref and $arrayref <news@simonflack.com>
    Re: equivalence of \@$arrayref and $arrayref (Eric Bohlman)
    Re: equivalence of \@$arrayref and $arrayref <iltzu@sci.invalid>
    Re: equivalence of \@$arrayref and $arrayref nobull@mail.com
    Re: equivalence of \@$arrayref and $arrayref nobull@mail.com
    Re: Example needed for Win32::OLE and Excel <bart.lateur@skynet.be>
    Re: Example needed for Win32::OLE and Excel <swan@peak2peak.com>
    Re: Execution time for a script (Anno Siegel)
    Re: FAQ: Archives of comp.lang.perl.misc <newspost@coppit.org>
    Re: Finding size of HTML page via HTTP <laszlo.gerencser@portologic.com>
    Re: Finding size of HTML page via HTTP <tom.melly@ccl.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 13 Jul 2001 10:08:26 -0600
From: "Richard A. Evans" <EvR@compuserve.com>
Subject: Accessing Outlook PST file info with perl
Message-Id: <9in678$jsu$1@suaar1ac.prod.compuserve.com>

By reading the few pages of Perl documentation I could find referring to
Outlook, I know that I can use something like this:

  use strict;
  use Win32::OLE;
  use Win32::OLE::Const 'Microsoft Outlook';

  my $Outlook = Win32::OLE->new('Outlook.Application', 'Quit');
  my $ol = Win32::OLE::Const->Load($Outlook);

  my $namespace = $Outlook->GetNamespace("MAPI");
  my $Folder = $namespace->GetDefaultFolder(olFolderInbox);

I don't fully understand the last few statements, but this code seems to
start the process of accessing Outlook data.  (Printing the values obtained
didn't help me much either.)

Where can I find specific function references, etc. to actually get at the
information -- calendar, contacts, emails (including those in subfolders),
etc.  Basically I want to be able to read (and hopefully write) any
information in Outlook.

Note:  I am not trying to send or receive email.  I am trying to read from
(and hopefully write to) an Outlook PST file.

Any help will be appreciated.

Regards,

Rick Evans




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

Date: Fri, 13 Jul 2001 15:16:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Active State
Message-Id: <i64uktgqmmu4s39b5amickbh2n9jr7l1q8@4ax.com>

Adam Stewart wrote:

>Second, I
>tried using DOS before I actually asked this question, but it didn't work.
>The thing is I just forgot to restart my computer,  and when I tried it
>later it worked fine.

Oh, yeah. The "perl directory needs to be added to your PATH" trap.

-- 
	Bart.


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

Date: 13 Jul 2001 10:13:52 -0700
From: cchambli@lycos.com (Casey Chambliss)
Subject: arrays & textfile lines
Message-Id: <a15e3f18.0107130913.7a9debe4@posting.google.com>

Ok, I'm a perl newbie,  I want to put every 10th line of CONTENT.TXT
into the @CONTENT array.

How do I do this?  Do I use a loop?  If so, what is the proper syntax?
 Could you give me an example?  TIA


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

Date: Fri, 13 Jul 2001 13:54:51 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: arrays & textfile lines
Message-Id: <3B4EB75B.5090A5BF@ce.gatech.edu>

Casey Chambliss wrote:
> 
> Ok, I'm a perl newbie,  I want to put every 10th line of CONTENT.TXT
> into the @CONTENT array.
> 
> How do I do this?  Do I use a loop?  If so, what is the proper syntax?
>  Could you give me an example?  TIA


not sure if this is proper or recommended, but it does the job:


-----------------------------------
open FILE, "content.txt";

while (<FILE>) {

	if (($.%10) == 0){
		push @content, $_;
		}

}
-----------------------------------

-rob


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

Date: Fri, 13 Jul 2001 14:58:38 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: C libraries usage in Perl
Message-Id: <y0E37.158731$v5.12197668@news1.rdc1.ct.home.com>

David Coppit <newspost@coppit.org> wrote:
> [posted & mailed]

> Rob Kirby wrote:

>> So, here is my newbie question. I want to be able to integrate
>> calls to a vendor supplied API, which consists basically of one
>> C include file and the shared library. I'm sure there is a way
>> to do this, and I just need a push in the right direction.

> Welcome to Perl. :)

> Two ways:
> - Painful XS: "perldoc xstut" to get started

XS really, *really* isn't painful. The docs make it seem far harder
than it is. (Though I will grant that I'm not necessarily a
representative sample of folks that write XS code)

Inline's still really cool, though. ;)

					Dan


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

Date: Fri, 13 Jul 2001 11:15:03 -0500
From: cp <cpryce@pryce.net>
Subject: Re: Check for Dups!
Message-Id: <B77488B7.8738%cpryce@pryce.net>

in article ZXx37.54036$aE6.4616334@news1.cableinet.net, millside at
millettNOSPAM@lblueyonder.co.uk wrote on 07/13/2001 3:04 AM:

> I have a program which was written some time ago and error checking works
> just fine.
> However someone has submitted same email address (subscribed to my
> newsletter) about 60 times- presumably just for the fun of it!

> I would like to protect against multiple entries being written to my flat
> file in future and was wanting a sub routine to do it. The test code I have
> written below just throws up my errorpage no matter what email address was
> specified- legit or not!
> Could someone show me how to modify this please using seek as I don't think
> grep is appropriate here?

It is not. According to the docs, it is much less efficient than other
methods. I would review the FAQ on the subject. Type:

 perldoc perlfaq 

At the command line, and look for the FAQ 'How can I tell whether a list or
array contains a certain element?'

> Also is it necessary to lock file for appending?

Yes. Otherwise the file could be modified as you were checking it for
duplicates. Say, by some one with WAAAAY yoo much time on their hands
hitting the submit button several times in a row!

> 
> ########## SUBSCRIBE NEW EMAILS ##########
> ########## CHECK EXISTING EMAIL ADDRESSES FOR DUPLICATES BEFORE WRITING TO
> FILE ##########
> 
> &check_data;
# best to pass in the address
 check_data($email{'address'});
 
> sub check_data{

# get the parameter passed in
 my $address = shift;

> open (EMAILS, "+< address.txt") or die ("Can't open $email: $!");

This isn't append mode, it's update mode. Try:

 open(EMAILS, "+>>address.txt") or die "can't open address file: $!";
 flock(EMAILS, 2) or die "No luck with lock: $!"; # test all system calls
 seek(EMAILS, 0, 0) or die "Can't rewind: $!"; # move to beginning of file.

> 
> @addresses=<EMAILS>;

 # remove the newlines
 chomp @addresses; 
> 
> @add = grep{ /$email{'address'}/i } @addresses;
see perlfaq4 for why you shouldn't do this

# First, make a hash:
 my %seen = map {$_=>1} @addresses;
 
# Or, make a hash slice:
 my %seen; 
 @seen{@addresses} = (1) x @addresses;

Note: search http://groups.google.com/groups?group=comp.lang.perl.misc for
the term hash slice, and see Uri's good examples.

> 
> if (@add) {
> $errormessage = ("The address you entered, <B>$email{'address'}</B> is
> already in our mailing list");
>       &errorpage;
>       exit;
> }

# next, check to see if your address is there..
 my $errormessage;
 if ($seen{$address}) {
    # $address exists
    $errormessage = "The address you entered, <B>$email{'address'}</B> is
                        already in our mailing list";
 } else { 
    # if we haven't seen $address, We have a winner!!!
    seek(EMAILS, 0, 2) or die "can't move to eof: $!";
    print EMAILS "$address\n"; # appends the address
 }

> 
> close (EMAILS); 
 # close releases the lock. Always test close!!
 close (EMAILS) or die "can't close: $!";

 # call error sub if an error exists...
 errorpage($errormessage) if $errormessage;

> exit;
> 
> } #end of sub check_data



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

Date: Fri, 13 Jul 2001 17:43:10 +0200
From: morten@tangeraas.com (=?ISO-8859-1?Q?Morten_Tanger=E5s?=)
Subject: Content types in a mail
Message-Id: <1ewhvre.wsurik1trl74cN%morten@tangeraas.com>

I am looking for some documentation about the content-type field in the
mail header, but I don't find any useful information.

What I would like, is a list of all different content types which may
occour in a mail header, and a description of each of them (what I can
expect in the body part when the content-type is this and that)!

In advance, thanks!

Regards,
Morten


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

Date: Fri, 13 Jul 2001 17:37:57 GMT
From: Barry Margolin <barmar@genuity.net>
Subject: Re: Content types in a mail
Message-Id: <VlG37.106$Zv6.1616@burlma1-snr2>

In article <1ewhvre.wsurik1trl74cN%morten@tangeraas.com>,
Morten Tangerås <morten@tangeraas.com> wrote:
>I am looking for some documentation about the content-type field in the
>mail header, but I don't find any useful information.
>
>What I would like, is a list of all different content types which may
>occour in a mail header, and a description of each of them (what I can
>expect in the body part when the content-type is this and that)!

IANA's registry of Media Types is what you want.

http://www.isi.edu/in-notes/iana/assignments/media-types/

-- 
Barry Margolin, barmar@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


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

Date: Fri, 13 Jul 2001 19:38:33 +0200
From: morten@tangeraas.com (=?ISO-8859-1?Q?Morten_Tanger=E5s?=)
Subject: Re: Content types in a mail
Message-Id: <1ewi17o.14vhkda5nq9o8N%morten@tangeraas.com>

Barry Margolin <barmar@genuity.net> wrote:


> IANA's registry of Media Types is what you want.
> 
> http://www.isi.edu/in-notes/iana/assignments/media-types/

Great! Thanks :)

Morten


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

Date: Fri, 13 Jul 2001 11:21:43 -0400
From: CIT <jmd52@cornell.edu>
Subject: Continuation Fields in format
Message-Id: <MPG.15b8dc0d7196f11f989684@newsstand.cit.cornell.edu>

Hi,

I have been trying to preserve the original user's input format on 
fields that are being written to a format.  For example, when a user has 
typed into a field some text followed by a blank line and then followed 
by more text.  In a filled continuation field (those starting with ~~^
<<<) in a format, the format removes all blank lines and breaks each 
line on word boundaries.  It also has been doing a little more in that 
it eliminates all carriage returns and replaces them with a space, even 
if the original line is not empty.  I have tried using @* or ^*, which 
does preserve the original formatting.  However, some lines exceed the 
page boundaries and the printer prints them on the next line.  
Unfortunately the Perl format only recognizes its own line breaks and I 
end up with the printer thinking it has printed 75 lines and the Perl 
format thinking it only printed 72 or some number lower than 75.  The 
printer makes a page break at 75 lines and then the Perl format makes a 
page break at what it thinks is 75 lines and I have three pages, the 
first being full, the second with only three lines or so, and the third 
with the remainder.

Does anyone know if there is any way to set the maximum number of 
characters on a line using the ^* field format so that the printer and 
the format can stay in sync?

Thanks,
Josh


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

Date: Fri, 13 Jul 2001 16:34:56 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: easy multi-file find & replace?
Message-Id: <tku8pg62fmur36@corp.supernews.com>

Ilya Zakharevich (nospam-abuse@ilyaz.org) wrote:
: [A complimentary Cc of this posting was sent to
: Craig Berry
: <cberry@cinenet.net>], who wrote in article <tks6o9spcjt176@corp.supernews.com>:
: > If you can identify the text files by pattern (say, they all end in
: > .html), this should do it from the shell:
: > 
: >   find public_html -name '*.html' -exec perl -pi -e 's/foobar/fubar/' {} \;
: 
:   pfind ./public_html '/\.html$/' '=~ s/foobar/fubar/g'

Where does one obtain pfind?  Don't see it on CPAN.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Brute force done fast enough looks slick."
   |             - William Purves


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

Date: 13 Jul 2001 17:14:01 GMT
From: ctcgag@hotmail.com
Subject: Re: Efficiency hit of $1 in Regexps?
Message-Id: <20010713131401.235$8M@newsreader.com>

pt <mnemotronic@mind\no-spam/spring.com> wrote:
>
> WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in
> the program, it has to provide them for every pattern match. This may
> substantially slow your program. Perl uses the same mechanism to produce
> $1, $2, etc, so you also pay a price for each pattern that contains
> capturing parentheses.
>
>     It's that part that says " .... pay a price for each pattern that
> contains capturing ..." that has me confused.  Would 'capturing' which
> generates the $n variables be included in that??  Reading this leads me
> to believe (perhaps incorrectly) that the EFFECT of using $& $` and $'
> is the same as that of using $1, $2, etc ("perl uses the same
> mechanism...").

Every RE potentially sets $&, $`, and $', so once you use any of them,
it has to capture them for every RE.   (I guess they could decide to
only implement capturing for REs in the scope where $' is used.)

Only REs having capturing parentheses potentially set $n, so using $1 only
required Perl to implement capturing for those REs that have capturing
parentheses.


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
                    Usenet Newsgroup Service


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

Date: Fri, 13 Jul 2001 15:55:12 +0100
From: chris wallace <chris.wallaceREMOVE_ME@lshtm.ac.uk>
Subject: equivalence of \@$arrayref and $arrayref
Message-Id: <3B4F0BD0.17F78ACF@lshtm.ac.uk>

I have inherited some code that makes much use of references to
anonymous arrays.  These are sometimes then stored in another array,
using code like

  push @array, \@$array_ref;

(where $array_ref is a reference to an anonymous array).
In this situation, I would tend to use the following:

  push @array, $array_ref;

The first method takes longer than the second:

  use strict;
  use Benchmark;
  my $aref = [0, 3,  5003, 44];
  my @first;
  my @second;

  timethese(300000, {
		   'First' => sub { push @first, \@$aref; },
		   'Second'  => sub { push @second, $aref; },
	  	  });
produces:

Benchmark: timing 300000 iterations of First, Second...
     First:  0 wallclock secs ( 1.38 usr +  0.01 sys =  1.39 CPU) @  
215827.34/s (n=300000)
    Second:  1 wallclock secs ( 0.76 usr +  0.05 sys =  0.81 CPU) @  
370370.37/s (n=300000)


But my question is: is there any meaningful difference (or can anyone
see why the inherited code uses the first method)?


Many thanks, Chris.


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

Date: Fri, 13 Jul 2001 16:18:15 +0100
From: "Simon Flack" <news@simonflack.com>
Subject: Re: equivalence of \@$arrayref and $arrayref
Message-Id: <9in3v9$k3jrk$1@ID-83895.news.dfncis.de>

>   push @array, \@$array_ref;
vs..
>   push @array, $array_ref;

> But my question is: is there any meaningful difference (or can anyone
> see why the inherited code uses the first method)?

The first method de-references $array_ref and then pushes a reference to
that into @array.

As far as I can see, the purpose of this would be that any changes to the
references in @array will not change the data in the original $array_ref.
Whether or not this is desireable, I can't say.

The second method pushes the reference into @array. Changing the data in
array would change the original data.

Regards
Simon




"chris wallace" <chris.wallaceREMOVE_ME@lshtm.ac.uk> wrote in message
news:3B4F0BD0.17F78ACF@lshtm.ac.uk...
> I have inherited some code that makes much use of references to
> anonymous arrays.  These are sometimes then stored in another array,
> using code like
>
>   push @array, \@$array_ref;
>
> (where $array_ref is a reference to an anonymous array).
> In this situation, I would tend to use the following:
>
>   push @array, $array_ref;
>
> The first method takes longer than the second:
>
>   use strict;
>   use Benchmark;
>   my $aref = [0, 3,  5003, 44];
>   my @first;
>   my @second;
>
>   timethese(300000, {
>    'First' => sub { push @first, \@$aref; },
>    'Second'  => sub { push @second, $aref; },
>     });
> produces:
>
> Benchmark: timing 300000 iterations of First, Second...
>      First:  0 wallclock secs ( 1.38 usr +  0.01 sys =  1.39 CPU) @
> 215827.34/s (n=300000)
>     Second:  1 wallclock secs ( 0.76 usr +  0.05 sys =  0.81 CPU) @
> 370370.37/s (n=300000)
>
>
> But my question is: is there any meaningful difference (or can anyone
> see why the inherited code uses the first method)?
>
>
> Many thanks, Chris.




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

Date: 13 Jul 2001 15:32:49 GMT
From: TGVCDPVNTLMI@spammotel.com (Ronald Blaschke)
Subject: Re: equivalence of \@$arrayref and $arrayref
Message-Id: <9in4b0$k4dd2$1@ID-57488.news.dfncis.de>

As far as I know,
push @array, \@$array_ref;
will _not_ copy the array.  I guess you'd have to say
push @array, [@$array_ref];

In any case, be sure to check what is really desired.

Ron


On Fri, 13 Jul 2001 16:18:15 +0100, Simon Flack <news@simonflack.com> wrote:
> >   push @array, \@$array_ref;
> vs..
> >   push @array, $array_ref;
> 
> > But my question is: is there any meaningful difference (or can anyone
> > see why the inherited code uses the first method)?
> 
> The first method de-references $array_ref and then pushes a reference to
> that into @array.
> 
> As far as I can see, the purpose of this would be that any changes to the
> references in @array will not change the data in the original $array_ref.
> Whether or not this is desireable, I can't say.
> 
> The second method pushes the reference into @array. Changing the data in
> array would change the original data.
> 
> Regards
> Simon
-- 


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

Date: 13 Jul 2001 15:37:51 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: equivalence of \@$arrayref and $arrayref
Message-Id: <slrn9ku5fb.ire.rgarciasuarez@rafael.kazibao.net>

Simon Flack wrote in comp.lang.perl.misc:
} >   push @array, \@$array_ref;
} vs..
} >   push @array, $array_ref;
} 
} > But my question is: is there any meaningful difference (or can anyone
} > see why the inherited code uses the first method)?
} 
} The first method de-references $array_ref and then pushes a reference to
} that into @array.
} 
} As far as I can see, the purpose of this would be that any changes to the
} references in @array will not change the data in the original $array_ref.
} Whether or not this is desireable, I can't say.

No : no copy of the anonymous array (the one which is referenced by
$array_ref) is made. The following program demonstrates this :

#!/usr/local/bin/perl -l
$array_ref = [ 1, 2, 3 ];
push @array, \@$array_ref;
print "@{$array[0]} / @$array_ref";
${$array[0]}[0] = 4;
print "@{$array[0]} / @$array_ref";
__END__

This program outputs :

1 2 3 / 1 2 3
4 2 3 / 4 2 3

The difference between the two methods is that \@$array_ref checks at
runtime whether $array_ref is actually a reference to an array (or a
blessed array).

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Fri, 13 Jul 2001 16:34:57 +0100
From: "Simon Flack" <news@simonflack.com>
Subject: Re: equivalence of \@$arrayref and $arrayref
Message-Id: <9in4u3$k00ll$1@ID-83895.news.dfncis.de>

> As far as I know,
> push @array, \@$array_ref;
> will _not_ copy the array.  I guess you'd have to say
> push @array, [@$array_ref];

Yep, you're right.

Just tested it.

Simon


"Ronald Blaschke" <TGVCDPVNTLMI@spammotel.com> wrote in message
news:9in4b0$k4dd2$1@ID-57488.news.dfncis.de...
> As far as I know,
> push @array, \@$array_ref;
> will _not_ copy the array.  I guess you'd have to say
> push @array, [@$array_ref];
>
> In any case, be sure to check what is really desired.
>
> Ron
>
>
> On Fri, 13 Jul 2001 16:18:15 +0100, Simon Flack <news@simonflack.com>
wrote:
> > >   push @array, \@$array_ref;
> > vs..
> > >   push @array, $array_ref;
> >
> > > But my question is: is there any meaningful difference (or can anyone
> > > see why the inherited code uses the first method)?
> >
> > The first method de-references $array_ref and then pushes a reference to
> > that into @array.
> >
> > As far as I can see, the purpose of this would be that any changes to
the
> > references in @array will not change the data in the original
$array_ref.
> > Whether or not this is desireable, I can't say.
> >
> > The second method pushes the reference into @array. Changing the data in
> > array would change the original data.
> >
> > Regards
> > Simon
> --




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

Date: 13 Jul 2001 15:59:42 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: equivalence of \@$arrayref and $arrayref
Message-Id: <9in5te$633$1@bob.news.rcn.net>

Simon Flack <news@simonflack.com> wrote:
>>   push @array, \@$array_ref;
> vs..
>>   push @array, $array_ref;

>> But my question is: is there any meaningful difference (or can anyone
>> see why the inherited code uses the first method)?

> The first method de-references $array_ref and then pushes a reference to
> that into @array.

> As far as I can see, the purpose of this would be that any changes to the
  ^^^^^^^^^^^^^^^^^^^
> references in @array will not change the data in the original $array_ref.
> Whether or not this is desireable, I can't say.

I think you need a new prescription :)  As a quick test shows, the first 
method does *not* make a copy of the original data; in fact if you 
stringify the two references, they have identical values.

> The second method pushes the reference into @array. Changing the data in
> array would change the original data.

As would happen in the first method.  If you really need to make a 
separate copy, you'd need to use

push @array, [@$array_ref];

My guess as to the origin of the redundant syntax in the original code is 
that it was originally written to work with arrays, then with array 
references, and layers of modification accumulated.




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

Date: 13 Jul 2001 16:20:33 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: equivalence of \@$arrayref and $arrayref
Message-Id: <995040509.9351@itz.pp.sci.fi>

In article <9in3v9$k3jrk$1@ID-83895.news.dfncis.de>, Simon Flack wrote:
>>   push @array, \@$array_ref;
>vs..
>>   push @array, $array_ref;
>
>> But my question is: is there any meaningful difference (or can anyone
>> see why the inherited code uses the first method)?
>
>The first method de-references $array_ref and then pushes a reference to
>that into @array.
>
>As far as I can see, the purpose of this would be that any changes to the
>references in @array will not change the data in the original $array_ref.
>Whether or not this is desireable, I can't say.

That may well be the intention.  Unfortunately, of course, it doesn't
work that way.  The statements are in fact functionally identical, as
you can see by running the following code:

  #!/usr/bin/perl -l   
  $array_ref = \@array;
  print $array_ref;
  print \@$array_ref;

which will print:

  ARRAY(0x34e78)
  ARRAY(0x34e78)

(Oh, wait.  There _is_ a difference.  The second version will always
produce a hard array reference, dying if $array_ref is already a hard
reference to something other than an array.  But since $array_ref is
supposed to contain an arrayref anyway, it doesn't actually matter.)

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: 13 Jul 2001 17:41:36 +0100
From: nobull@mail.com
Subject: Re: equivalence of \@$arrayref and $arrayref
Message-Id: <u9ofqo7pdr.fsf@wcl-l.bham.ac.uk>

chris wallace <chris.wallaceREMOVE_ME@lshtm.ac.uk> writes:

> I have inherited some code that makes much use of references to
> anonymous arrays.  These are sometimes then stored in another array,
> using code like
> 
>   push @array, \@$array_ref;
> 
> (where $array_ref is a reference to an anonymous array).
> In this situation, I would tend to use the following:
> 
>   push @array, $array_ref;
> 
> But my question is: is there any meaningful difference (or can anyone
> see why the inherited code uses the first method)?

I'm fairly confident that there is no difference _if_ $array_ref is
already known to be a hard reference to an array.

There are however servral reasons why you might legitimately do
\@$array_ref:

$array_ref could be undef and the program is to replace undef with a
reference to an empty array.  IMHO the more readable (albeit possibly
slower) idiom for this would be:

   push @array, ( $array_ref ||= [] ); 

$array_ref could be a reference to an non-array thingy blessed into a
package that overloads @{}.  Personally I'd consider this a bad thing
to do as one is clearly obtaining a reference to something which one
in not meant to.

Under "no strict qw(refs)" $array_ref could be a symbolic reference
that wants converting to a real reference.

Under "use strict qw(refs)" this could be acting an assertion so that
an exception will be thrown if $array_ref is not an array reference
(or an undef, or an object with @{} overloaded).

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 13 Jul 2001 17:44:08 +0100
From: nobull@mail.com
Subject: Re: equivalence of \@$arrayref and $arrayref
Message-Id: <u9k81c7p9j.fsf@wcl-l.bham.ac.uk>

"Simon Flack" <news@simonflack.com> writes:

> >   push @array, \@$array_ref;
> vs..
> >   push @array, $array_ref;
> 
> > But my question is: is there any meaningful difference (or can anyone
> > see why the inherited code uses the first method)?
> 
> The first method de-references $array_ref and then pushes a reference to
> that into @array.
> 
> As far as I can see, the purpose of this would be that any changes to the
> references in @array will not change the data in the original $array_ref.

Bzzzt... you are thinking of 

   push @array, [ @$array_ref ];

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 13 Jul 2001 15:00:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Example needed for Win32::OLE and Excel
Message-Id: <im2ukt8lst1cn58oc6aqg6ihkrfhpeg9v6@4ax.com>

Ross wrote:

>I've been spending the morning reading FAQ's
>but haven't found a example where a existing
>excel file is openned and the row column contents
>of the spread sheet are read by the Perl program.

You haven't? Hmmm...

Here it is:

<http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/faq/Windows/ActivePerl-Winfaq12.html#extract_cells>

As for the entire contents: change the settings for the range. You can
get the  number of rows and columns using

	$worksheet->UsedRange->Rows->Count
and
	$worksheet->UsedRange->Columns->Count

respectively. You can use the row count directly, but you'll have to
convert the column count to one or two letters ('A' .. 'Z', 'AA' ..
'AZ', 'BA' .. 'BZ', etc)

-- 
	Bart.


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

Date: Fri, 13 Jul 2001 15:18:46 GMT
From: "Ross" <swan@peak2peak.com>
Subject: Re: Example needed for Win32::OLE and Excel
Message-Id: <3b4f1976$1@news.peakpeak.com>

Thanks, As is almost always the case as soon as I ask for help
I get my code working. I'm new to the Win32::OLE environment
this is very interesting stuff. At first I keep wondering where the
method(?) calls were documented but I see they come from the
application opened.
--Ross
"Bart Lateur" <bart.lateur@skynet.be> wrote in message news:im2ukt8lst1cn58oc6aqg6ihkrfhpeg9v6@4ax.com...
Ross wrote:

>I've been spending the morning reading FAQ's
>but haven't found a example where a existing
>excel file is openned and the row column contents
>of the spread sheet are read by the Perl program.

You haven't? Hmmm...

Here it is:

<http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/faq/Windows/ActivePerl-Winfaq12.html#extract_cells>

As for the entire contents: change the settings for the range. You can
get the  number of rows and columns using

$worksheet->UsedRange->Rows->Count
and
$worksheet->UsedRange->Columns->Count

respectively. You can use the row count directly, but you'll have to
convert the column count to one or two letters ('A' .. 'Z', 'AA' ..
'AZ', 'BA' .. 'BZ', etc)

--
Bart.




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

Date: 13 Jul 2001 14:07:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Execution time for a script
Message-Id: <9imvae$9h8$1@mamenchi.zrz.TU-Berlin.DE>

According to Andrew Isherwood <andy_isherwood@hotmail.com>:
> Could someone please tell me the easiest way of getting the execution
> time for a script. I'd like to assign this to a variable.

perldoc -f times

time() only gives you the elapsed time, and only to a resolution
of one second.  times() gives you the CPU time used, which is often
a better measure of performance, though you can use time() in conjunction.

Also consider the Benchmark module, which does all that for you.

Anno


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

Date: Fri, 13 Jul 2001 10:16:36 -0500
From: David Coppit <newspost@coppit.org>
Subject: Re: FAQ: Archives of comp.lang.perl.misc
Message-Id: <3B4F10D4.4050003@coppit.org>

PerlFAQ Server wrote:

>     Have you tried Deja or AltaVista? Those are the best archives. Just look
>     up "*perl*" as a newsgroup.
> 
>         http://www.deja.com/dnquery.xp?QRY=&DBS=2&ST=PS&defaultOp=AND&LNG=ALL&format=terse&showsort=date&maxhits=25&subjects=&groups=*perl*&authors=&fromdate=&todate=

This should be updated to:

   http://groups.google.com/groups?as_ugroup=*perl*

David



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

Date: Fri, 13 Jul 2001 13:36:04 GMT
From: Laszlo Gerencser <laszlo.gerencser@portologic.com>
Subject: Re: Finding size of HTML page via HTTP
Message-Id: <3B4EF97D.34040453@portologic.com>

> jeremyalansmith wrote:
> >
> > I'm writing a small browser, and wondered how to find out the size of the
> > HTML page, so I can make enough memory available to load it into memory

By the way: making enough memory? In perl? You don't have enough?
You want to *allocate* memory? How? Why?
You are working on some kind of embedded system?

You should post more info, because I don't understand your problem, I'm
afraid.
I think that your case is not a trivial one, if you need to care about
memory.
So please, give us more details.

--
Laszlo Gerencser
PortoLogic Ltd.


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

Date: Fri, 13 Jul 2001 16:16:59 +0100
From: "Tom Melly" <tom.melly@ccl.com>
Subject: Re: Finding size of HTML page via HTTP
Message-Id: <3b4f10eb$0$3757$ed9e5944@reading.news.pipex.net>

"Laszlo Gerencser" <laszlo.gerencser@portologic.com> wrote in message
news:3B4EF97D.34040453@portologic.com...
>
> You should post more info, because I don't understand your problem, I'm
> afraid.
> I think that your case is not a trivial one, if you need to care about
> memory.
> So please, give us more details.

My bet is that the browser is written in another lang. and he's just interested
in using Perl to fetch the page.... but what do I know?




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

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


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