[23264] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5484 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 10 21:11:02 2003

Date: Wed, 10 Sep 2003 18:10:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 10 Sep 2003     Volume: 10 Number: 5484

Today's topics:
        Number of elements in an array (Graham)
    Re: Number of elements in an array <r_reidy@comcast.net>
    Re: Number of elements in an array <cs@edu.edu>
    Re: Parsing to insert single quotes (Jay Tilton)
        Redemption, SafeMailItem and ActivePerl (Brian Rankin)
        seeking Win32::OLE example (Greg Bacon)
    Re: Speeding up LWP::Simple <abigail@abigail.nl>
    Re: Splitting and keeping the delimiter <usenet@dwall.fastmail.fm>
    Re: Standards in Artificial Intelligence <abigail@abigail.nl>
    Re: URL detection follow-up <ducott@hotmail.com>
    Re: URL detection follow-up <no@email.com>
    Re: URL detection follow-up <ducott@hotmail.com>
    Re: URL detection follow-up <no@email.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 10 Sep 2003 15:52:33 -0700
From: GrahamWilsonCA@yahoo.ca (Graham)
Subject: Number of elements in an array
Message-Id: <eda30d78.0309101452.46255c15@posting.google.com>

I hope the subject isn't too misleading... I am trying to find the
number of elements of each "data" array in the following:

--
use Data::Dumper;

@data = (1.0,2.0,3.0);
@test=(
        {"id"=>"aaa", "units"=>"kW/m^2/st", "data"=>[@data]},
      );      

@data = (2.0,4.0,6.0);
push @test, {"id"=>"bbb", "units"=>"rad", "data"=>[@data]};

print Dumper @test;
print scalar($test[0]{"data"}), "\n";
--

All I can get is an address like ARRAY(0x64a0)?  Surely it cannot be
that difficult to find out that there are 3 elements in each data
array ;)

Thanks.


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

Date: Wed, 10 Sep 2003 16:58:01 -0600
From: Ron Reidy <r_reidy@comcast.net>
Subject: Re: Number of elements in an array
Message-Id: <3F5FAC79.9040301@comcast.net>

Here  is my output:

   DB<3> x @test
0  HASH(0x8393598)
    'data' => ARRAY(0x83882f8)
       0  1
       1  2
       2  3
    'id' => 'aaa'
    'units' => 'kW/m2/st'
1  HASH(0x824bef8)
    'data' => ARRAY(0x82a0a60)
       0  2
       1  4
       2  6
    'id' => 'bbb'
    'units' => 'rad'

As you see, data is an array ref...so you should say 'print scalar 
@{$test[0]{data}' and you will see what you are hoping to.

Graham wrote:
> I hope the subject isn't too misleading... I am trying to find the
> number of elements of each "data" array in the following:
> 
> --
> use Data::Dumper;
> 
> @data = (1.0,2.0,3.0);
> @test=(
>         {"id"=>"aaa", "units"=>"kW/m^2/st", "data"=>[@data]},
>       );      
> 
> @data = (2.0,4.0,6.0);
> push @test, {"id"=>"bbb", "units"=>"rad", "data"=>[@data]};
> 
> print Dumper @test;
> print scalar($test[0]{"data"}), "\n";
> --
> 
> All I can get is an address like ARRAY(0x64a0)?  Surely it cannot be
> that difficult to find out that there are 3 elements in each data
> array ;)
> 
> Thanks.


-- 
Ron Reidy
Oracle DBA



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

Date: Wed, 10 Sep 2003 16:35:31 -0700
From: Chief Squawtendrawpet <cs@edu.edu>
Subject: Re: Number of elements in an array
Message-Id: <3F5FB543.DD50ABDD@edu.edu>

Graham wrote:
> All I can get is an address like ARRAY(0x64a0)?  Surely it cannot be
> that difficult to find out that there are 3 elements in each data
> array ;)

Based on your last two posts, I think you'd save yourself some grief
by spending just a few minutes brushing up on Perl references. I'd
start with 'perlreftut'.

Chief S.


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

Date: Wed, 10 Sep 2003 22:33:01 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Parsing to insert single quotes
Message-Id: <3f5fa62d.690040316@news.erols.com>

Eric <nospam@xx.com> wrote:

: BTW, I've been studying your code

Briefly recapping that,

      printf FILE "(%d,'%s',%f,'%s')%s\n",
        $. ,
        split(/,/) ,
        eof(INFILE) ? ';' : ',';

: and am simply baffled on how you get
: auto-incrementing of the 1st field.

That's the $. variable, which keeps a count of the number of records
(lines) read from a filehandle.  As long as one line read corresponds to
one line written, $. can be used to enumerate the lines being output.
See "perldoc perlvar" for gory details.

: also stumped as to exactly HOW the parsing of the 3 fields occurs to
: include leaving the white spaces between multi-word city names.  Is that
: the split function?

Yup.  "split(/,/)" bursts the value in $_ (the implied second argument
to the split function) into a list of "whatever is not a comma" values.
Presence of whitespace in a field is irrelevant, since whitespace is not
a comma.  See "perldoc -f split" for more info on split() and its
capabilities.



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

Date: 10 Sep 2003 17:26:36 -0700
From: brankin@enbonline.net (Brian Rankin)
Subject: Redemption, SafeMailItem and ActivePerl
Message-Id: <fc0674ce.0309101626.12d76dd1@posting.google.com>

Trying to import an RFC822 message into a PST message store results in
the error "Can't modify non-lvalue subroutine call" when I set the
Redemption item equal to the new message item.  My code (the line
where the error occurs is tagged):

	## redemption testing
	Win32::OLE::CreateObject("Redemption.SafeMailItem",
$RedemptionSession);
	$MAPISession->Logon("tester1",undef,"False",undef);
	$cnt = $MAPISession->Infostores->Count;
	STORES: for ($i = 1; $i<$cnt + 1; $i++) {
		$pststore = $MAPISession->Infostores($i);
		$namer = $pststore->Name;
		print "$namer\n";
		if ($namer eq "Personal Folders") { last STORES; }
	}
	$pstinbox = $pststore->RootFolder->Folders->Item("DEFAULT");
	$newmsg = $pstinbox->messages->Add;
	$newmsg->update;
ERROR:	$RedemptionSession->Item = $newmsg;
	$RedemptionSession->Import("c:\pstconverter\tester.eml",olRFC822);
	$RedemptionSession->save;

As far as I can tell, the $RedemptionSession object is fine...any
suggestions appreciated.

Regards, Brian


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

Date: Wed, 10 Sep 2003 23:34:09 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: seeking Win32::OLE example
Message-Id: <vlvd7hrntqeke0@corp.supernews.com>

I was trying to put together a quick hack to extract review comments
(using the Comments property) from a Word document to jump start
compiling review minutes, but I found the MSDN Word object model
documentation surprisingly opaque.  For example, the docs didn't say
which property held the comment tag (e.g., [b1]), and the empirical
measure of iterating over the keys didn't bear fruit.

I played with the code in <36182bc8.8113706@news2.ibm.net> and found
that it made a difference whether I called Documents->Open or
GetActiveObject -- although the two seem equivalent in the docs.

Can people recommend a good resource?  I read Jan's TPJ article and
the various pods, but I was frustrated with my low progress.

Thanks,
Greg
-- 
Even the most mighty government, operating with the utmost severity,
cannot succeed in endeavors that are contrary to what has been called
"economic law."
    -- Ludwig von Mises


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

Date: 10 Sep 2003 23:17:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Speeding up LWP::Simple
Message-Id: <slrnblvc83.787.abigail@alexandra.abigail.nl>

John Bokma (postmaster@castleamber.com) wrote on MMMDCLXII September
MCMXCIII in <URL:news:1063219488.463658@halkan.kabelfoon.nl>:
{}  2mb wrote:
{}  
{} > David,
{} > Why not just use one of the commercially available email harvesting
{} > packages. Most are available for 19.99. If you are going to spam, it is bet
{} > to get your list built and operational as soon as possible, before more
{} > legislation goes into effect.
{}  
{}  Why is David named a spammer without any proof? Just for harvesting 
{}  30,000,000 webpages? There are so many legal things to use it for like 
{}  text analyses, language analyses, making an estimate of size, analyzing 
{}  HTML tag use, analysing use of scripting, stylesheets etc.


My first impression was that he wanted to create a search engine.
Spamming never crossed my mind. (Now, had he said 30,000,000 email
addresses....)


Abigail
-- 
# Count the number of lines; code doesn't match \w. Linux specific.
()=<>;$!=$=;($:,$,,$;,$")=$!=~/.(.)..(.)(.)..(.)/;
$;++;$*++;$;++;$*++;$;++;`$:$,$;$" $. >&$*`; 


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

Date: Thu, 11 Sep 2003 00:46:51 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Splitting and keeping the delimiter
Message-Id: <Xns93F2D364476B8dkwwashere@216.168.3.30>

Sandman <mr@sandman.net> wrote:

> Hello! I have a string like this:
> 
>     12.00 Simpsons 12.30 Seinfeld 13.00 Movie: Dante's Peak
> 
> And I want to split that in seperate "programs" that I'd like to deal with 
> individually. So, I want this in an array like this:
> 
>     "12.00 Simpsons",
>     "12.30 Seindfeld"
>     "13.00 Movie: Dante's Peak"


You have workable solutions from several responses.  Just one comment:  use 
split() when you know what to throw away, a regex when you know what to keep.  
(I believe I'm quoting someone, but can't remember whom.)

-- 
David Wall


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

Date: 10 Sep 2003 23:19:59 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Standards in Artificial Intelligence
Message-Id: <slrnblvccv.787.abigail@alexandra.abigail.nl>

John J. Trammell (trammell+usenet@hypersloth.invalid) wrote on MMMDCLXII
September MCMXCIII in <URL:news:slrnbluqac.2f7.trammell+usenet@hypersloth.el-swifto.com.invalid>:
}}  On 10 Sep 2003 10:22:11 -0800, Arthur T. Murray mega-crossposted:
}} > A webpage of proposed Standards in Artificial Intelligence is at 
}} > http://mentifex.virtualentity.com/standard.html -- updated today.
}} > 
}}  
}}  A killfile for excessive crossposters and other undesirables is
}}  at /home/trammell/.slrn/score -- updated about 15 seconds ago.


I've had the following section in my slrn score file for many years
already:

% Crosspostings.
% Not more than 3 groups. Kill crossposts to alt.perl, or scn.
[*]
Score:: -9999
  Newsgroups: .*,.*,
  Newsgroups: alt\.perl
  Newsgroups: soc\.culture\.netherlands



Abigail
-- 
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s};;;
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};                # Perl 5.6.0 broke this...
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))


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

Date: Wed, 10 Sep 2003 22:17:25 GMT
From: "\"Dandy\" Randy" <ducott@hotmail.com>
Subject: Re: URL detection follow-up
Message-Id: <VpN7b.927838$ro6.18582021@news2.calgary.shaw.ca>

Awesome ... works great ... now ... can you formulate a replacement command
that will take an email address and add the <a href="mailto: commands so
that email addresses will also become linked? You've been agreat help!

Randy

"Brian Wakem" <no@email.com> wrote in message
news:bjo6ce$lfb7n$1@ID-112158.news.uni-berlin.de...
>
> ""Dandy" Randy" <ducott@hotmail.com> wrote in message
> news:sMM7b.935815$3C2.21317890@news3.calgary.shaw.ca...
> > Hi,
> >
> > As per my previous posts, I am searching for a way to open a text file
> that
> > contains a few paragraphs of text, locate web URL's and replace them
with
> > the needed html tags such as <a href & </a> etc. Most of the responses
> > suggested using a perl module ... URI::Find and similair methods.
> > Unfortunately, the hosting company I run my scripts from does not have
> this
> > module installed, and they are not prepared to install it just for my
> needs.
> > I also cannot change hosting companies.
> >
> > So ... is there ANY other way my goal can be accomplished giving I
cannot
> > use URI::Find? Here is an example of theoretical code:
> >
> > #!/usr/bin/perl
> >
> > # get text file data
> > open (TEXT, "<data/data.txt") or die "Can't open file: $!";
> >   @data=<TEXT>;
> > close(TEXT);
> >
> > # find web URL's and replace occurances with needed HTML tags
> > scan @list > replace;
> >
> > # write the changed data back to the text file
> > open (TEXT, ">data/data.txt") or die "Can't open file: $!";
> >   print  DATA @text;
> > close(TEXT);
> >
> > Please, it is very important to me to find this solution, if you have
any
> > ideas, post back. Working code examples are very welcomed. Thanx
everyone!
>
>
> If they are all like http://www.domain.com/dir/file.html then you could do
> something like -
>
>
> foreach(@data) {
> s!(http://.*?)(?:\s|$)!<a href="$1">$1</a>!gi;
> }
>
> Not perfect, but it'll get you started.
>
> -- 
> Brian Wakem
>
>




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

Date: Wed, 10 Sep 2003 23:26:07 +0100
From: "Brian Wakem" <no@email.com>
Subject: Re: URL detection follow-up
Message-Id: <bjo8e0$kjksb$1@ID-112158.news.uni-berlin.de>


""Dandy" Randy" <ducott@hotmail.com> wrote in message
news:VpN7b.927838$ro6.18582021@news2.calgary.shaw.ca...
> Awesome ... works great ... now ... can you formulate a replacement
command
> that will take an email address and add the <a href="mailto: commands so
> that email addresses will also become linked? You've been agreat help!
>
> Randy
>

Nice example of top posting.

To match email addresses perfectly every time is probably impossible, but a
simple and effective way of matching 99%+ would be:-

foreach(@data) {
s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a>!g;
}

-- 
Brian Wakem




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

Date: Wed, 10 Sep 2003 22:33:14 GMT
From: "\"Dandy\" Randy" <ducott@hotmail.com>
Subject: Re: URL detection follow-up
Message-Id: <KEN7b.125548$la.2773409@news1.calgary.shaw.ca>

"Brian Wakem" wrote:

> To match email addresses perfectly every time is probably impossible, but
a
> simple and effective way of matching 99%+ would be:-
>
> foreach(@data) {
> s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a>!g;
> }

Brian, thankx again, that one worked too. Here is what i'm now using that
seems to work correctly:

$contents=~ s/http:\/\///g;
$contents=~ s!(www.*?)(?:\s|$)!<a href="http://$1">$1</a> !gi;
$contents=~ s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a> !g;

The first code eliminates the http:// in case the text contained a full url,
then adjusted your code to start looking for www. You also may notice a
deliberate space after the </a> tags ... this was needed as your code seemed
to kill the trailing space. Owe you one.

Randy

P.S. Sorry about the last top post.




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

Date: Wed, 10 Sep 2003 23:45:11 +0100
From: "Brian Wakem" <no@email.com>
Subject: Re: URL detection follow-up
Message-Id: <bjo9ho$l3eft$1@ID-112158.news.uni-berlin.de>


""Dandy" Randy" <ducott@hotmail.com> wrote in message
news:KEN7b.125548$la.2773409@news1.calgary.shaw.ca...
> "Brian Wakem" wrote:
>
> > To match email addresses perfectly every time is probably impossible,
but
> a
> > simple and effective way of matching 99%+ would be:-
> >
> > foreach(@data) {
> > s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a>!g;
> > }
>
> Brian, thankx again, that one worked too. Here is what i'm now using that
> seems to work correctly:
>
> $contents=~ s/http:\/\///g;
> $contents=~ s!(www.*?)(?:\s|$)!<a href="http://$1">$1</a> !gi;
> $contents=~ s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a> !g;
>
> The first code eliminates the http:// in case the text contained a full
url,
> then adjusted your code to start looking for www. You also may notice a
> deliberate space after the </a> tags ... this was needed as your code
seemed
> to kill the trailing space. Owe you one.


Yes it would have swallowed the space.

s!(http://.*?)(\s|$)!<a href="$1">$1</a>$2!gi;

Instead should sort that out.

I'm glad they worked for you, but it's important to understand why, in case
you need to alter something.  It's also important to understand why those
regexs are not perfect and will not work for every url or email, and from
time-to-time, could match things that aren't urls or email addresses.

-- 
Brian Wakem




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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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