[25413] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7658 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 16 18:05:35 2005

Date: Sun, 16 Jan 2005 15:05:13 -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           Sun, 16 Jan 2005     Volume: 10 Number: 7658

Today's topics:
    Re: [newbie] chomp acting weird (or me not understandin <matternc@comcast.net>
    Re: [newbie] chomp acting weird (or me not understandin <1usa@llenroc.ude.invalid>
    Re: [newbie] chomp acting weird (or me not understandin <1usa@llenroc.ude.invalid>
    Re: [newbie] chomp acting weird (or me not understandin <hendrik_maryns@despammed.com>
    Re: [newbie] chomp acting weird (or me not understandin <bik.mido@tiscalinet.it>
    Re: [newbie] chomp acting weird (or me not understandin <1usa@llenroc.ude.invalid>
    Re: [newbie] chomp acting weird (or me not understandin <hendrik_maryns@despammed.com>
    Re: [newbie] chomp acting weird (or me not understandin <hendrik_maryns@despammed.com>
    Re: Adding a delimiter inbetween number characters and  <bik.mido@tiscalinet.it>
    Re: Array generation <bik.mido@tiscalinet.it>
    Re: CGI: Execute a perl script inside another perl scri <groleau+news@freeshell.org>
        Closing Excel <jimsimpson@cox.net>
    Re: Closing Excel <usa1@llenroc.ude.invalid>
    Re: Closing Excel (Jay Tilton)
    Re: convention regarding lexical filehandles <bik.mido@tiscalinet.it>
        email regex help <asf@sadfkj.cosdf>
        how can I use perl to do a windows "postmessage"  ? <pauls@nospam.com>
    Re: how can I use perl to do a windows "postmessage"  ? <1usa@llenroc.ude.invalid>
    Re: how can I use perl to do a windows "postmessage"  ? <pauls@nospam.com>
    Re: how can I use perl to do a windows "postmessage"  ? <1usa@llenroc.ude.invalid>
    Re: implementing "protected" in OO perl <shawn.corey@sympatico.ca>
    Re: Loop through a text file line by line <news@chaos-net.de>
    Re: Loop through a text file line by line <bik.mido@tiscalinet.it>
    Re: Need help with Perl and MySQL database data load <oscar@nowhere.com>
    Re: Need help with Perl and MySQL database data load <oscar@nowhere.com>
    Re: Need help with Perl and MySQL database data load <news@chaos-net.de>
    Re: Print question <bik.mido@tiscalinet.it>
    Re: Print question <bik.mido@tiscalinet.it>
    Re: system command on Win98 <bik.mido@tiscalinet.it>
    Re: system command on Win98 <mikeflan@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 16 Jan 2005 11:43:48 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: [newbie] chomp acting weird (or me not understanding how it works??)
Message-Id: <q7udnR-FF_5aBHfcRVn-2w@comcast.com>

Hendrik Maryns wrote:

> Hi,
> 
> I'm reading lines from an inputfile which contains on every line a word,
> a description of it, and the word again.  I want to reconstruct the
> sentence these words formed.  "LET" is the sign for punctuation, thus
> means the end of the sentence is reached. Whend i use chomp like this:
> 
> #add this when testing
> open(INFILE, "test.txt");
> #
> 
> do{
> my @zinwoorden;
> chomp($lijn=<INFILE>);
> while ($lijn!~/LET/){
> $lijnnr++;
> push(@zinwoorden,$lijn);
> $lijn=<INBESTAND>;
> } #enduntil
> for (@zinwoorden){
> s/(\w+).*/$1/;
> }
> my $zin=join (" ", @zinwoorden);
> print "$lijnnr \n$zin \n";
> } until eof(INFILE);
> 
> it doesn't work, just prints 0.

You attempted to translate this code and then posted it without
running the translation--the inner loop still reads from 
INBESTAND instead of INFILE.  Post problem code you have 
actually run (and cut and paste it so you don't have typos).
In any case, your problem is that you forgot the chomp for
reading INFILE/INBESTAND in the inner loop.


-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: 16 Jan 2005 17:34:10 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [newbie] chomp acting weird (or me not understanding how it works??)
Message-Id: <Xns95E07FDFCC032asu1cornelledu@132.236.56.8>

Hendrik Maryns <hendrik_maryns@despammed.com> wrote in
news:T7ednZHf0q5HFnfcRVnyug@scarlet.biz: 

> Hi,
> 
> I'm reading lines from an inputfile which contains on every line a
> word, a description of it, and the word again.  I want to reconstruct
> the sentence these words formed.  

Since I do not speak the language in which these words are supposed to 
form a sentence, I cannot figure out what your program is supposed to 
do.

> "LET" is the sign for punctuation, thus means the end of the sentence 
> is reached. Whend i use chomp like this: 

use strict;
use warnings;

> #add this when testing
> open(INFILE, "test.txt");

You should always, with no exceptions, check if open succeeded.

> do{
>      my @zinwoorden;
>      chomp($lijn=<INFILE>);

The canonical way to read a file line by line until the end is to use:

while(my $lijn = <INFILE>) {
    	chomp $lijn;


}

>      while ($lijn!~/LET/){

What do you think this does? Why are you not using an if statement here?

The rest snipped.

Please read the posting guidelines and post codes others can run by 
copying and pasting in an editor. The guidelines explain how to do that.

#! /usr/bin/perl

use strict;
use warnings;

my @words;

while(<DATA>) {
    chomp;
    next unless $_;
    last if 0 <= index $_, 'LET';
    if( /^(\w+)\s+/ ) {
        push @words, $1;
    }
}

print "@words.\n";

__DATA__
dames	N(soort,mv,basis)	dame
en	VG(neven)	en
heren	N(soort,mv,basis)	heer
meneer	N(soort,ev,basis,zijd,stan)	meneer
de	LID(bep,stan,rest)	de
rector	N(soort,ev,basis,zijd,stan)	rector
een	LID(onbep,stan,agr)	een
hele	ADJ(prenom,basis,met-e,stan)	heel
mooie	ADJ(prenom,basis,met-e,stan)	mooi
avond	N(soort,ev,basis,zijd,stan)	avond
en	VG(neven)	en
een	LID(onbep,stan,agr)	een
hartelijk	ADJ(vrij,basis,zonder)	hartelijk
welkom	N(soort,ev,basis,onz,stan)	welkom
aan	VZ(init)	aan
alle	VNW(onbep,det,stan,prenom,met-e,agr)	al
aanwezigen	ADJ(nom,basis,met-e,mv-n)	aanwezig
in	VZ(init)	in
de	LID(bep,stan,rest)	de
zaal	N(soort,ev,basis,zijd,stan)	zaal
 .	LET()	.


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

Date: 16 Jan 2005 19:08:51 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [newbie] chomp acting weird (or me not understanding how it works??)
Message-Id: <Xns95E08FED595AAasu1cornelledu@132.236.56.8>

Hendrik Maryns <hendrik_maryns@despammed.com> wrote in
news:6I-dnQEW_6WaKXfcRVnyiQ@scarlet.biz: 

> Ok, I humbly beg for forgiveness on my bare knees for not testing
> before I posted.  And promise solemnly to never do it again.

That attitude will not get you anywhere. 
 
> So here is a second try, and I did test those two, trimmed some lines
> of it too.

You might want to go and read the posting guidelines as well.

> You really don't have to care about the meaning of the
> words, it's just that in the first script, there is a \n at the end of
> each word, whereas in the second, there isn't.

You have only posted one set of data that consists of lines that seem to 
have three components: a word, some grammatical classification of the 
word, and the plural of the word. Then, a newline terminates the line. 
What I see and what you wrote above are not compatible.

Remember that thing I said about posting a short but complete script 
that others can run just by pasting it in their favorite editor? 

Please do that!

> I didn't understand your explanations in the two answers up to now, so
> could you please be more specific,

No.

> I really only started with Perl last week.

All the more reason to follow advice that serves to help you help others 
help you.
 
> Attachment decoded: untitled-2.txt
> --------------070504050109010601000209
> dames    N(soort,mv,basis)    dame
> en    VG(neven)    en

There is no need to post attachments.

Sinan.


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

Date: Sun, 16 Jan 2005 20:29:43 +0100
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Re: [newbie] chomp acting weird (or me not understanding how it works??)
Message-Id: <us-dnYIldME6XXfcRVnygw@scarlet.biz>

A. Sinan Unur schreef:

> Hendrik Maryns <hendrik_maryns@despammed.com> wrote in
> news:T7ednZHf0q5HFnfcRVnyug@scarlet.biz: 
> 
Ok, I'll give it a last try.

>>Hi,
>>
>>I'm reading lines from an inputfile which contains on every line a
>>word, a description of it, and the word again.  I want to reconstruct
>>the sentence these words formed.  
> 
> 
> Since I do not speak the language in which these words are supposed to 
> form a sentence, I cannot figure out what your program is supposed to 
> do.

Basically, just taking the first word of each line, and joining them all 
into a sentence, in the same order.
> 
>>"LET" is the sign for punctuation, thus means the end of the sentence 
>>is reached. Whend i use chomp like this: 
> 
> 
> use strict;
> use warnings;

Yes, I read about that and am using it now, thanks.


>>#add this when testing
>>open(INFILE, "test.txt");
> 
> 
> You should always, with no exceptions, check if open succeeded.
I normally do, but forgot here.

> 
>>do{
>>     my @zinwoorden;
>>     chomp($lijn=<INFILE>);
> 
> 
> The canonical way to read a file line by line until the end is to use:
> 
> while(my $lijn = <INFILE>) {
>     	chomp $lijn;
> 
> 
> }
I know that, but I didn't see a way to do this _and_ do the other stuff 
I want to do with the reconstructed sentence afterwards, so I tried it 
another way.

>>     while ($lijn!~/LET/){
> 
> 
> What do you think this does? Why are you not using an if statement here?

Because of the way I'm reading the file: read a line until you encounter 
punctuation, which is indicated by "LET" occuring in the line.  This 
_does_ work fine by the way.

> The rest snipped.
> 
> Please read the posting guidelines and post codes others can run by 
> copying and pasting in an editor. The guidelines explain how to do that.
Ok, and where can I find these guidelines, please?

<snipped code>
This indeed does exactly what I was looking for! (And you don't even 
need chomp here ;-)
My problem still remains: how can I do this, sentence per sentence (as, 
in the real DATA, more of those follow each other), and manipulate each 
line of the data in another way after each sentence.
But don't bother answering, I'll try for myself some more.

So, thank you,
Hendrik

PS: the start of my other post was meant ironic, but I suppose your 
answer was too :-p


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

Date: Sun, 16 Jan 2005 20:37:56 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: [newbie] chomp acting weird (or me not understanding how it works??)
Message-Id: <68glu0hmmv7aq7b686b46sipcqlo5jfq7d@4ax.com>

On Sun, 16 Jan 2005 16:44:16 +0100, Hendrik Maryns
<hendrik_maryns@despammed.com> wrote:

>I'm reading lines from an inputfile which contains on every line a word, 
>a description of it, and the word again.  I want to reconstruct the 
>sentence these words formed.  "LET" is the sign for punctuation, thus 
>means the end of the sentence is reached. Whend i use chomp like this:
>
>#add this when testing
>open(INFILE, "test.txt");

Please, _don't_! Even if this is meant to be only a minimal example
typing something like

  open my $in, '<', 'test.txt' or die $!

takes only a few more keystrokes.

>do{
[snip all code]

>I tried to change $/="\n", but as I don't really know what that does, 

  perldoc perlvar

>An easy example of INFILE would be:
>
>## start of test.txt
>dames	N(soort,mv,basis)	dame
>en	VG(neven)	en
>heren	N(soort,mv,basis)	heer
[snip]
>.	LET()	.
>## end of test.txt

Please note that this doesn't _strictly_ match the description above
(not that it matters, IMHO). Also, it _seems_ that '.' in the first
field ends a sentence just as much 'LET()' in the second one does.

>Any comment on my code welcome too!

Personally I found it overly clumsy and hard to follow, and being
particularly lazy in this moment I didn't even try to understand it or
to test it either.

All in all, if I understand correctly the description of your task
(and if you descripted it correctly in the first place!) I suppose you
may want something along these lines:

  #!/usr/bin/perl -ln
  
  use strict;
  use warnings;
  
  push our @wordz, (split)[0];
  print "@wordz" and @wordz=() 
    if $wordz[-1] eq '.';
  
  __END__

(Of course most probably you do _not_ want that whitespace before the
period... ;-)


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 16 Jan 2005 20:01:31 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [newbie] chomp acting weird (or me not understanding how it works??)
Message-Id: <Xns95E098DAE20F9asu1cornelledu@132.236.56.8>

Hendrik Maryns <hendrik_maryns@despammed.com> wrote in
news:us-dnYIldME6XXfcRVnygw@scarlet.biz: 

> A. Sinan Unur schreef:

>>>     while ($lijn!~/LET/){
>> 
>> 
>> What do you think this does? Why are you not using an if statement
>> here? 
> 
> Because of the way I'm reading the file: read a line until you
> encounter punctuation, which is indicated by "LET" occuring in the
> line.  This _does_ work fine by the way.

You must have an interesting definition of 'fine'. The above body of the 
while statement above will either not be executed or will be excuted 
exactly once.

Also, the data you posted does not match the verbal description you give 
above. Looking at the data, I see no lines terminated by LET but rather 
a sequence of lines terminated by a line containing LET. Why would you 
lie to people whose help you are asking for.
 
>> Please read the posting guidelines and post codes others can run by 
>> copying and pasting in an editor. The guidelines explain how to do
>> that. 

> Ok, and where can I find these guidelines, please?

They are posted here several times every month. You did read the FAQ 
list and lurk a little before posting, didn't you.

Even if you hadn't, there is no excuse for asking _this_ question.

Even the most dimwitted among us are able to type

    comp.lang.perl.misc guidelines in

in the searchbox at http://www.google.com/ .

> This indeed does exactly what I was looking for! (And you don't even 
> need chomp here ;-)
> My problem still remains: how can I do this, sentence per sentence
> (as, in the real DATA, more of those follow each other), and
> manipulate each line of the data in another way after each sentence.

So, you did not show real data and therefore wasted our time? That's 
nice.

> But don't bother answering, 

OK.

> PS: the start of my other post was meant ironic, but I suppose your 
> answer was too :-p

ITYM sarcastic rather than ironic.

Sinan.


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

Date: Sun, 16 Jan 2005 23:10:10 +0100
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Re: [newbie] chomp acting weird (or me not understanding how it works??)
Message-Id: <TtidnXZwVqLfe3fcRVnyvQ@scarlet.biz>

Michele Dondi schreef:
> On Sun, 16 Jan 2005 16:44:16 +0100, Hendrik Maryns
> <hendrik_maryns@despammed.com> wrote:
> 
> 
>>I'm reading lines from an inputfile which contains on every line a word, 
>>a description of it, and the word again.  I want to reconstruct the 
>>sentence these words formed.  "LET" is the sign for punctuation, thus 
>>means the end of the sentence is reached. Whend i use chomp like this:
>>
>>#add this when testing
>>open(INFILE, "test.txt");
> 
> 
> Please, _don't_! Even if this is meant to be only a minimal example
> typing something like
> 
>   open my $in, '<', 'test.txt' or die $!
> 
> takes only a few more keystrokes.

Uh, ok, but as I don't even understand what this does, you can't expect 
me to type it...  I'll study the docs.

> 
> 
>>do{
> 
> [snip all code]
> 
> 
>>I tried to change $/="\n", but as I don't really know what that does, 
> 
> 
>   perldoc perlvar
> 
> 
>>An easy example of INFILE would be:
>>
>>## start of test.txt
>>dames	N(soort,mv,basis)	dame
>>en	VG(neven)	en
>>heren	N(soort,mv,basis)	heer
> 
> [snip]
> 
>>.	LET()	.
>>## end of test.txt
> 
> 
> Please note that this doesn't _strictly_ match the description above
> (not that it matters, IMHO). Also, it _seems_ that '.' in the first
> field ends a sentence just as much 'LET()' in the second one does.
It does, but sometimes, it is not '.' but '?' or '...', whereas there 
will always be 'LET()' in the second column.


>>Any comment on my code welcome too!
> 
> 
> Personally I found it overly clumsy and hard to follow, and being
> particularly lazy in this moment I didn't even try to understand it or
> to test it either.
> 
> All in all, if I understand correctly the description of your task
> (and if you descripted it correctly in the first place!) I suppose you
> may want something along these lines:
> 
>   #!/usr/bin/perl -ln
>   
>   use strict;
>   use warnings;
>   
>   push our @wordz, (split)[0];
>   print "@wordz" and @wordz=() 
>     if $wordz[-1] eq '.';
>   
>   __END__
> 
> (Of course most probably you do _not_ want that whitespace before the
> period... ;-)
I'll try this out, thanks.

H.


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

Date: Sun, 16 Jan 2005 23:17:27 +0100
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Re: [newbie] chomp acting weird (or me not understanding how it works??)
Message-Id: <zKOdnauQmsRqenfcRVnyrw@scarlet.biz>

A. Sinan Unur schreef:

> Hendrik Maryns <hendrik_maryns@despammed.com> wrote in
> news:us-dnYIldME6XXfcRVnygw@scarlet.biz: 
> 
> 
>>A. Sinan Unur schreef:
> 
> 
>>>>    while ($lijn!~/LET/){
>>>
>>>
>>>What do you think this does? Why are you not using an if statement
>>>here? 
>>
>>Because of the way I'm reading the file: read a line until you
>>encounter punctuation, which is indicated by "LET" occuring in the
>>line.  This _does_ work fine by the way.
> 
> 
> You must have an interesting definition of 'fine'. The above body of the 
> while statement above will either not be executed or will be excuted 
> exactly once.

If I execute my testfile, I get the whole sentence (i.e. the first word 
of every line) as output, so I deduce from that it does iterate it 
several times??
I see no other loop in there which could cause this.

> Also, the data you posted does not match the verbal description you give 
> above. Looking at the data, I see no lines terminated by LET but rather 
> a sequence of lines terminated by a line containing LET. Why would you 
> lie to people whose help you are asking for.

Sorry, if you misunderstand me.  I meant: a line, containing 'LET'.  Of 
course, as I answered to Michele, you could use '.' as an 
end-of-sentence token, but others are possible too, that's why I use 
'LET', which is there in any case.

>>>Please read the posting guidelines and post codes others can run by 
>>>copying and pasting in an editor. The guidelines explain how to do
>>>that. 
> 
> 
>>Ok, and where can I find these guidelines, please?
> 
> 
> They are posted here several times every month. You did read the FAQ 
> list and lurk a little before posting, didn't you.
> 
> Even if you hadn't, there is no excuse for asking _this_ question.
> 
> Even the most dimwitted among us are able to type
> 
>     comp.lang.perl.misc guidelines in
> 
> in the searchbox at http://www.google.com/ .

You're right about that <blush>

>>This indeed does exactly what I was looking for! (And you don't even 
>>need chomp here ;-)
>>My problem still remains: how can I do this, sentence per sentence
>>(as, in the real DATA, more of those follow each other), and
>>manipulate each line of the data in another way after each sentence.
> 
> 
> So, you did not show real data and therefore wasted our time? That's 
> nice.

I did, I only took an excerpt, so as to not waste bandwidth on 
irrelevant text.

Whatever, you can put me in your kikkfile now.


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

Date: Sun, 16 Jan 2005 17:07:51 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Adding a delimiter inbetween number characters and letter characters
Message-Id: <ps0lu0lt0d2glsrmhlpojbq01si01p9ael@4ax.com>

On 15 Jan 2005 21:59:29 GMT, Martin Kissner <news@chaos-net.de> wrote:

>>      s/\n\D//g;
>>      s/(^\d+|\n\d)/$1-/g;
>>      print;
>
>Thanks for that hint.
>I use $_ far to rarely.

Well, there's nothing wrong in, say,

  $var =~ s/foo//;

but it tends to become tiresome if it has also to be

  $var =~ s/foo//;
  $var =~ s/bar//;
  $var =~ s/baz//;

(not that it's strictly _wrong_ either), so you will find out that
people often do

  for ($var) {
      s/foo//;
      s/bar//;
      s/baz//;
  }

instead, using C<for> "only" for its aliasing properties, or even

  s/foo//, s/bar//, s/baz// for $var;
  
(depending on how complex the code acting on $_ really is). IIRC all
this is mentioned in a FAQ entry too.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 16 Jan 2005 17:07:54 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Array generation
Message-Id: <b83lu0de1pmcsk0jc292a1bjpfbs93k9b1@4ax.com>

On 15 Jan 2005 20:01:32 -0800, poopdeville@gmail.com wrote:

>written machine readable code).  Therefore, I'm not familiar with the
>nicities that make Perl a high level language (this relates to my
>remark concerning my lack of understanding of strictures.  I chose Perl

IMHO it relates poorly to your remark in that _not_ using strictures
in some sense increases the kind of niceties that make Perl a high
level language.

When you C<use strict;> you "pay" to have part of your freedom
reSTRICTed, when this would allow you too easily to introduce bugs in
your code.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 16 Jan 2005 16:35:11 -0500
From: Wes Groleau <groleau+news@freeshell.org>
Subject: Re: CGI: Execute a perl script inside another perl script
Message-Id: <QO6dnV1-NqEIf3fcRVn-tQ@gbronline.com>

xdarcos@hotmail.com wrote:
> I am using perl scripts as CGI. What I want to do is to call another
> perl script where I only set environment variables (envCGI.pl).
> 
> If I set these variables in my initial perl script, it works well (I
> get my HTML page) but if I call the other perl script, I get:

"require" works OK for this.  Or at least I think it
worked.  It's been three or four years since I did it.

-- 
Wes Groleau

Answer not a fool according to his folly,
    lest thou also be like unto him.
Answer a fool according to his folly,
    lest he be wise according to his own conceit.
                         -- Solomon

Are you saying there's no good way to answer a fool?
                         -- Groleau


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

Date: Sun, 16 Jan 2005 12:52:12 -0500
From: "jim simpson" <jimsimpson@cox.net>
Subject: Closing Excel
Message-Id: <QRxGd.77526$Jk5.18511@lakeread01>

I need to determine if Excel is running and if so close it. Can this be done
with a Perl script and can someone suggest an approach to do it.

Thanks,

Jim




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

Date: Sun, 16 Jan 2005 13:43:33 -0500
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Closing Excel
Message-Id: <pan.2005.01.16.18.43.02.192756@asu1cornelledu>

In article <QRxGd.77526$Jk5.18511@lakeread01> posted on Sun, 16 Jan 2005
12:52:12 -0500, jim simpson wrote:

> I need to determine if Excel is running and if so close it. Can this be done
> with a Perl script and can someone suggest an approach to do it.

See http://search.cpan.org/dist/Win32-OLE/

-- 
A. Sinan Unur
usa1@llenroc.ude.invalid -- remove invalid and
reverse each component for email address.



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

Date: Sun, 16 Jan 2005 21:30:55 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Closing Excel
Message-Id: <41eadcff.63134402@news.erols.com>

"jim simpson" <jimsimpson@cox.net> wrote:

: I need to determine if Excel is running and if so close it. Can this be done
: with a Perl script and can someone suggest an approach to do it.

    #!perl
    use warnings;
    use strict;
    use Win32::OLE;

    while( 
        my $excel = 
        Win32::OLE ->GetActiveObject('Excel.Application') 
    ) {
        $excel ->Quit
    }



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

Date: Sun, 16 Jan 2005 17:07:52 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: convention regarding lexical filehandles
Message-Id: <la1lu09j897qtf7uqpp8pkua6f6n28dvd2@4ax.com>

On 15 Jan 2005 22:10:38 GMT, Abigail <abigail@abigail.nl> wrote:

>\\  Using the two args form of open() leaves a big security hole.
>
>No, it doesn't have to. People where able to write Perl 5.005 programs
>without having security holes.

This is not in contraddiction with what I wrote. In the kind of
situation I mentioned the two args form of open() _does_ leave a
security hole[1]. This security hole _must_ be closed _if_ one cares
about security. One way to close this security hole (and a "cheap"
one[2] IMHO) is to use the three args form of open() and _another_ one
is to use some sort of data validation or whatever technique that
those people used to write Perl 5.005 programs with no security holes.

As a side note I would argue that if one duly takes care about data
validation as to avoid potential risks of the kind we're talking
about, then he's most probably _not_ interested in the advantages that
"magic open" can offer, as tersely shown by you in another post.

As a side note to the side note I would argue that one can restore the
advantages of magic open by some sort of input validation as well. At
which point you may and probably would argue that it's stupid to
reinvent the wheel to do something that Perl can do out of the box.

Still, _logically_ the open() mode is a separate entity from the
filename of the file to be open()ed, and I feel more satisfied if I'm
certain that e.g. an handle supposed to be read is open() to something
that can be read.

So I can have e.g. (no claim of completeness/reliability/etc.):

  my $mode = '<';
  $mode = '-|' if $filename =~ s/\s*|\s*//;
  open my $fh, $mode, $filename or
    die "Can't open/run `$filename': $!\n";

and be sure that if someone tries this on '>file', then it won't
(succesfully, most probably) open() 'file' for writing.


[1] In fact you wrote yourself "no, it doesn't have to", rather than
"no, it doesn't". There's a substantial difference.

[2] In the sense that newbies can be safely thought to do so, and with
no other effort a huge source of insecurity (for the cases in which
this may matter) is already done away. With no implication whatsoever
that they should not care about other possible ones...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 16 Jan 2005 17:15:02 -0500
From: "nntp" <asf@sadfkj.cosdf>
Subject: email regex help
Message-Id: <10ulpsn8or9tl22@corp.supernews.com>

Ive been trying to come up with two regex's but im having trouble...
the script that im writing will first ask for the domain.
im trying to get a regex to match valid domain names.

the second should be able to match an email address (without the
@domain.tld)..

so far i have this
 if ($name !~ /^([a-zA-Z0-9]([a-zA-Z0-9\-\.]{0,63}))$/ ) {
                print "REGEX OK\n";
}


i really don't know what im doing.... but i know im pretty close....




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

Date: Sun, 16 Jan 2005 11:07:46 -0800
From: "Paul S." <pauls@nospam.com>
Subject: how can I use perl to do a windows "postmessage"  ?
Message-Id: <raSdndzO7YkcJnfcRVn-uQ@seanet.com>

Hi,
I want to use PERL to communicate with another software package I have. 
The other software allows one to "talk" to it using the postmessage 
command. I am using activestate PERL - do you know where I can get a 
compatible (to active state PERL 5.6) package that has the postmessage 
function?


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

Date: 16 Jan 2005 19:12:00 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: how can I use perl to do a windows "postmessage"  ?
Message-Id: <Xns95E0907549915asu1cornelledu@132.236.56.8>

"Paul S." <pauls@nospam.com> wrote in news:raSdndzO7YkcJnfcRVn-
uQ@seanet.com:

> I want to use PERL to communicate with another software package I have. 
> The other software allows one to "talk" to it using the postmessage 
> command. I am using activestate PERL - do you know where I can get a 
> compatible (to active state PERL 5.6) package that has the postmessage 
> function?

You can use the Win32::API module.

See also http://tinyurl.com/vy31 

Sinan.


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

Date: Sun, 16 Jan 2005 12:59:19 -0800
From: "Paul S." <pauls@nospam.com>
Subject: Re: how can I use perl to do a windows "postmessage"  ?
Message-Id: <vqqdnSY_uPI6SHfcRVn-tw@seanet.com>

A. Sinan Unur wrote:
> "Paul S." <pauls@nospam.com> wrote in news:raSdndzO7YkcJnfcRVn-
> uQ@seanet.com:
> 
> 
>>I want to use PERL to communicate with another software package I have. 
>>The other software allows one to "talk" to it using the postmessage 
>>command. I am using activestate PERL - do you know where I can get a 
>>compatible (to active state PERL 5.6) package that has the postmessage 
>>function?
> 
> 
> You can use the Win32::API module.
> 
> See also http://tinyurl.com/vy31 
> 
> Sinan.


Hi Sinan,
Thank you!
I tried using the Activestate package manager to install the win32-api 
module but it did not work. You wouldn't happen to know where I could 
get the module would you?

Thanks

Paul


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

Date: 16 Jan 2005 21:13:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: how can I use perl to do a windows "postmessage"  ?
Message-Id: <Xns95E0A4FF540BDasu1cornelledu@132.236.56.8>

"Paul S." <pauls@nospam.com> wrote in
news:vqqdnSY_uPI6SHfcRVn-tw@seanet.com: 

> A. Sinan Unur wrote:
>> "Paul S." <pauls@nospam.com> wrote in news:raSdndzO7YkcJnfcRVn-
>> uQ@seanet.com:
>> 
>> 
>>>I want to use PERL to communicate with another software package I
>>>have. The other software allows one to "talk" to it using the
>>>postmessage command. I am using activestate PERL - do you know where
>>>I can get a compatible (to active state PERL 5.6) package that has
>>>the postmessage function?
>> 
>> 
>> You can use the Win32::API module.
>> 
>> See also http://tinyurl.com/vy31 

 ...

> I tried using the Activestate package manager to install the win32-api
> module but it did not work. You wouldn't happen to know where I could 
> get the module would you?

I have only installed Win32::API through ppm but I am using 5.8.

In any case, you could try:

<http://ppm.activestate.com/PPMPackages/zips/6xx-builds-only/Win32-API-
0.41.zip> (http://tinyurl.com/6dacg in case the URL wraps).

Google and CPAN are your friends, BTW.

Hope this helps.

Sinan.


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

Date: Sun, 16 Jan 2005 15:58:18 -0500
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: implementing "protected" in OO perl
Message-Id: <UxAGd.2680$K03.126936@news20.bellglobal.com>

SNeelakantan_C@zaplet.com wrote:
> Is there a way of making a certain variable 'protected' so that only
> methods in derived classes may access it? I would prefer a mechanism
> that doesn't wrap the variable in a method call since performance would
> slow down by an order of magnitude.
> 
> -Shanker
> 
Short answer no and yes. See perldoc -f my

'my' limits the variable's scope to the file (among other things) so if 
your object is in a single file, this will work.

    --- Shawn


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

Date: 16 Jan 2005 16:53:31 GMT
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Loop through a text file line by line
Message-Id: <slrncul70a.9mu.news@maki.homeunix.net>

Joe Smith wrote :
>
> If you replace <DATA> with <> you can read from STDIN, provided that
> @ARGV is empty.  If there is anything in @ARGV, the items will be
> interpreted as file names and <> will read from them instead.
>
> Without qualifiers, your statement implied that <> always reads from
> STDIN, and that is not exactly true.

Thanks for that additional explanation.

-- 
Epur Si Muove (Gallileo Gallilei)


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

Date: Sun, 16 Jan 2005 20:37:53 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Loop through a text file line by line
Message-Id: <i7glu01d0og845alm0gnv29k61u4e0f5dk@4ax.com>

On Sun, 16 Jan 2005 03:19:18 -0800, Joe Smith <joe@inwap.com> wrote:

>> I said: "If you replace <DATA> with <> you can read from STDIN."
>> You said: "Not exactly. ..."
[snip]
>If you replace <DATA> with <> you can read from STDIN, provided that
>@ARGV is empty.  If there is anything in @ARGV, the items will be
>interpreted as file names and <> will read from them instead.

While this is a better approximation to the truth(TM) than what the OP
wrote, if we want to be really fussy it's not _entirely_ exact: try 

  perl -pe '' - -

arguably @ARGV is not empty.

>Without qualifiers, your statement implied that <> always reads from
>STDIN, and that is not exactly true.

Indeed.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 16 Jan 2005 19:46:49 GMT
From: Oscar <oscar@nowhere.com>
Subject: Re: Need help with Perl and MySQL database data load
Message-Id: <41EAC4AE.3070608@nowhere.com>

Hello,

Thanks for the responses.

I modified my script to declare
my $user
my $dsn
my $pass
my %args
and modified my connect command to accomodate the new variables.
When I ran the script I got the message:
"Global symbol "$dns" requires explicit package name at sqltst2.pl line 13.
Global symbol "$DBI requires explicit package name at sqltst2.pl line 14."

I then added the line
package MySQL;
at the beginning of my script and got the same error.

What does the above error mean and how can I fix?

Thanks,
Oscar


Tore Aursand wrote:
> Oscar wrote:
> 
>> my $dbh = DBI->connect("dbi:mysql:sd_tst','localhost:3306','root',
>> 'XXXXXXX'",
>> {RaiseError => 1, AutoCommit => 1 }
>>   ) || die "Database connection not made: $DBI::errstr";
> 
> 
> The connection string is wrong. As stated in the DBI documentation, 
> connect() may receive _four_ parameters;
> 
>   1. Data source
>   2. Username
>   3. Password
>   4. Extra arguments
> 
> Your connection string contains _five_ parameters; you should have 
> specified the host and port in the data source part like this:
> 
>   my $dsn  = 'DBI:mysql:database=sd_tst;host=localhost;port=3306';
>   my $user = 'root';
>   my $pass = 'XXXXXXXX';
>   my %args = ( RaiseError => 1,
>                AutoCommit => 1 );
> 
>   my $dbh  = DBI->connect( $dns, $user, $pass, \%args )
>              or die "Can't connect; $DBI:errstr";
> 
> 


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

Date: Sun, 16 Jan 2005 19:48:05 GMT
From: Oscar <oscar@nowhere.com>
Subject: Re: Need help with Perl and MySQL database data load
Message-Id: <VxzGd.18307$_56.6132@fe2.texas.rr.com>

Hello,

Thanks for the responses.

I modified my script to declare
my $user
my $dsn
my $pass
my %args
and modified my connect command to accomodate the new variables.
When I ran the script I got the message:
"Global symbol "$dns" requires explicit package name at sqltst2.pl line 13.
Global symbol "$DBI requires explicit package name at sqltst2.pl line 14."

I then added the line
package MySQL;
at the beginning of my script and got the same error.

What does the above error mean and how can I fix?

Thanks,
Oscar


Tore Aursand wrote:
> Oscar wrote:
> 
>> my $dbh = DBI->connect("dbi:mysql:sd_tst','localhost:3306','root',
>> 'XXXXXXX'",
>> {RaiseError => 1, AutoCommit => 1 }
>>   ) || die "Database connection not made: $DBI::errstr";
> 
> 
> The connection string is wrong. As stated in the DBI documentation, 
> connect() may receive _four_ parameters;
> 
>   1. Data source
>   2. Username
>   3. Password
>   4. Extra arguments
> 
> Your connection string contains _five_ parameters; you should have 
> specified the host and port in the data source part like this:
> 
>   my $dsn  = 'DBI:mysql:database=sd_tst;host=localhost;port=3306';
>   my $user = 'root';
>   my $pass = 'XXXXXXXX';
>   my %args = ( RaiseError => 1,
>                AutoCommit => 1 );
> 
>   my $dbh  = DBI->connect( $dns, $user, $pass, \%args )
>              or die "Can't connect; $DBI:errstr";
> 
> 


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

Date: 16 Jan 2005 21:06:36 GMT
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Need help with Perl and MySQL database data load
Message-Id: <slrncullqs.9ru.news@maki.homeunix.net>

Oscar wrote :
> Hello,
>
> Thanks for the responses.
>
> I modified my script to declare
> my $user
> my $dsn
> my $pass
> my %args
> and modified my connect command to accomodate the new variables.
> When I ran the script I got the message:
> "Global symbol "$dns" requires explicit package name at sqltst2.pl line 13.
> Global symbol "$DBI requires explicit package name at sqltst2.pl line 14."
>
> [...]
>
> What does the above error mean and how can I fix?

It means, you have a typo in your skript.
my $dsn
"Global symbol "$dns"
$dsn <-> $dns

HTH

-- 
Epur Si Muove (Gallileo Gallilei)


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

Date: Sun, 16 Jan 2005 20:37:44 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Print question
Message-Id: <knflu09puarc2vmavh0equi7dv6mcnco4v@4ax.com>

On 16 Jan 2005 05:36:42 -0800, beliavsky@aol.com wrote:

>>reasons: (i) a hystorical one (tradition) and (ii) it is (said to be)
>>_fast_[*].
>
>At least one "young researcher" likes Fortran -- I am in my 30's.

Of course I didn't mean to make any claim of absoluteness in this
sense...

>I think the reasons for using Fortran are not entirely historical. For

Well, one point that I feel like adding is that historical reasons can
be just at the same time be practical as well, for example in terms of
availability of huge libraries of highly optimized code created and
updated over the years.

>numerical work involving arrays, especially multi-dimensional arrays,
>Fortran 90/95 is arguably a higher-level language than C or C++. It is

To be fair I had heard about Fortran 77 and 90, I didn't even know
about 95. All in all thinking of the lifetime of this programming
language, even taking into account all these updates and
redefinitions, one unavoidably ends thinking that it's really
astonishing...

>easy to dynamically allocate multidimensional arrays, pass them to
>functions and subroutines, and perform operations on whole arrays and
>array sections, as in Matlab.

This is what I heard too, hence also the anedocte I reported in the
footnote.

>Joel Spolsky wrote,
>"I've mentally divided the world into three groups. The largest group
>of people can't program at all. There's another, smaller group of
>people who can program, but not with pointers. And there's a tiny group
>of people who can program, even with pointers. Those elite few can even
>understand what it means to write CString*& in C++."

I already feel like including this amongst my .sigs! But first I must
admit that I don't know who Joel Spolsky is, so Google is awaiting
me...

>The middle group that can program but cannot grasp pointers can still
>use Fortran :).

;-)

>Of course, C++ is a rich and powerful language that can be used for
>almost any programming task.

Putting aside for a moment C++, C was definitely born for system
programming, and despite it verstility, it's the area in which it
really excels...

I had heard about the 'numeric C' project, but I don't have the
slightest idea about at which point it may be.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 16 Jan 2005 20:37:48 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Print question
Message-Id: <0galu0tg1tpjjp6ssfdkk2d1nr2d0vgtq9@4ax.com>

On 16 Jan 2005 13:54:59 GMT, "A. Sinan Unur"
<1usa@llenroc.ude.invalid> wrote:

>the same league as "Robin", at least in this arena. While I am not going 
>to rule out the possibility that he is another Einstein biding his time 
>at the patent office, I am sceptical and mostly annoyed with his posts 
>right now.

:-)


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 16 Jan 2005 17:07:55 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: system command on Win98
Message-Id: <9g3lu05u6ttrried0r8h39thbgnf9lpc27@4ax.com>

On Sat, 15 Jan 2005 22:35:33 GMT, Mike Flannigan
<mikeflan@earthlink.net> wrote:

>> > I also see that the shell on Win98 sucks.
>>
>> It works.
>
>Yeah, but it doesn't seem to keep a historical record of
>typed lines that can be recalled with the up arrow.

While I largely agree on the former cmt, doskey has been there and
useful[*] at least as of DOS5.0 (the one I began with).

>That's why I say it sucks.  I need to see if I can
>find another one that I like better.

See if this helps you:
<http://home.wanadoo.nl/fvu/Projects/Bash/Web/bash.htm>

>> What on God's Orange Titan is lltost.fch??? Does that file exist? Is that
>> really an executable? If not, does the associated application exist? If it
>> does, have you tried
[snip]
>It is a programing language that I create with the
>Perl script and then execute immediately.

HUH?!?


[*] Albeit only a tiny fraction of how useful history management of
e.g. bash is.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 16 Jan 2005 19:54:35 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: system command on Win98
Message-Id: <41EAC70E.F3DE8D4B@earthlink.net>


Michele Dondi wrote:

>
> While I largely agree on the former cmt, doskey has been there and
> useful[*] at least as of DOS5.0 (the one I began with).
>
>
> See if this helps you:
> <http://home.wanadoo.nl/fvu/Projects/Bash/Web/bash.htm>
>

Thanks.

Wow, 250 MB!  That's quite a program.


> >It is a programing language that I create with the
> >Perl script and then execute immediately.
>
> HUH?!?

Maybe I should say it is a scripting language that I write
with perl and then execute immediately.


Mike




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

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


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