[19198] in Perl-Users-Digest
Perl-Users Digest, Issue: 1393 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 27 14:10:37 2001
Date: Fri, 27 Jul 2001 11:10:22 -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: <996257422-v10-i1393@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 27 Jul 2001 Volume: 10 Number: 1393
Today's topics:
string extraction (shaz)
Re: string extraction <godzilla@stomp.stomp.tokyo>
Re: string extraction (Michel Dalle)
Re: Stripping extention from a filename in a string (Helgi Briem)
Re: Stripping extention from a filename in a string <godzilla@stomp.stomp.tokyo>
Re: Stripping extention from a filename in a string <stevea@wrq.com>
Re: Stripping extention from a filename in a string <godzilla@stomp.stomp.tokyo>
Re: suidperl works on one system, not another (Anno Siegel)
Re: suidperl works on one system, not another nobull@mail.com
Re: THIS GUY NEEDS A BULLET <bart.lateur@skynet.be>
Re: using a mail program to work on Windows NT servers nobull@mail.com
Win32::OLE running Excel macro <murthy@cox-internet.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Jul 2001 09:22:30 -0700
From: ssa1701@yahoo.co.uk (shaz)
Subject: string extraction
Message-Id: <23e71812.0107270822.292df62e@posting.google.com>
I am trying to write a script that will read the parsed text (tags
attached to each word, ie <NN>, <VBZ>, <DET>), and save all the words
into an array. The words in the array are then compared to see if they
occur else where (if they do, the word is removed but the counter is
incremented). Finally the the keyword is found.
The code shown previously attempts to find the words that have the
tags <NN> and <VBZ>.
The next step is to place the words in an array and implement the
counter.
------------------------------
Date: Fri, 27 Jul 2001 09:49:14 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: string extraction
Message-Id: <3B619B8A.939FCE04@stomp.stomp.tokyo>
shaz wrote:
> I am trying to write a script that will read the parsed text (tags
> attached to each word, ie <NN>, <VBZ>, <DET>), and save all the words
> into an array. The words in the array are then compared to see if they
> occur else where (if they do, the word is removed but the counter is
> incremented). Finally the the keyword is found.
> The code shown previously attempts to find the words that have the
> tags <NN> and <VBZ>.
> The next step is to place the words in an array and implement the
> counter.
Thank you for sharing with this newsgroup. Your comments
are of some interest. I wish you good luck in completing
your project in a timely manner.
Godzilla!
------------------------------
Date: Fri, 27 Jul 2001 17:47:31 GMT
From: news@mikespub.net (Michel Dalle)
Subject: Re: string extraction
Message-Id: <9js9c9$rcu$1@news.mch.sbs.de>
In article <23e71812.0107270822.292df62e@posting.google.com>, ssa1701@yahoo.co.uk (shaz) wrote:
>I am trying to write a script that will read the parsed text (tags
>attached to each word, ie <NN>, <VBZ>, <DET>), and save all the words
>into an array. The words in the array are then compared to see if they
>occur else where (if they do, the word is removed but the counter is
>incremented). Finally the the keyword is found.
Why do you want to use an array if you're interested in counting
how often a particular word appears ? A hash would be a more
obvious choice here.
Assuming that you want to count words per tag, and that 'words'
are simply alphanumerical (or _), you could use something like
this :
#!/usr/bin/perl -w
use strict;
my @tags = ('<NN>', '<VBZ>', '<DET>');
my $search = join('|',@tags);
my %taglist;
while (<DATA>) {
while (/(\w+)\s($search)/og) {
# print "$1 -> $2\n";
$taglist{$2}{$1}++;
}
}
foreach my $tag (sort keys %taglist) {
print "Tag $tag\n";
foreach my $word (sort keys %{$taglist{$tag}}) {
print "\t$word ($taglist{$tag}{$word})\n";
}
}
__DATA__
This is part of Sol05a.txt and also the final report <NN>. This is
used for eegggtgg the book <NN>.
hello <VBZ>
bye
computer<NN>
printer
table <VBZ>
monitor <NN>
explorer <NN>
thoughts
Your mileage will vary depending on how well the sample
you provided matches what you're looking for...
Michel.
P.S.: you'll get extra credit if you can actually explain
how this works to your teacher :)
------------------------------
Date: Fri, 27 Jul 2001 13:36:05 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: Stripping extention from a filename in a string
Message-Id: <3b616c2d.363380393@news.isholf.is>
On Thu, 26 Jul 2001 20:02:21 -0700, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote:
>#!perl
>
>print "Content-type: text/plain\n\n";
What is that supposed to accomplish outside of CGI??
>@Array = qw (file.txt file.pl file.h file.);
>
>for (@Array)
> {
> substr ($_, rindex ($_, "."), 4, "");
> print "$_\n";
> }
>
>exit;
What's that unnecessary exit for?
This script fails in the case of an extension longer
thanthree letters (increasingly common). For example
file.html gives you filel as the base filename,
obviously not what the original poster wanted.
why not use a simple regexp like:
s/\.\w*$//;
Regards,
Helgi Briem
------------------------------
Date: Fri, 27 Jul 2001 09:44:01 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Stripping extention from a filename in a string
Message-Id: <3B619A51.6A469B95@stomp.stomp.tokyo>
Helgi Briem AKA The CLPM Troll wrote:
> Godzilla! wrote:
(snipped)
> >print "Content-type: text/plain\n\n";
> What is that supposed to accomplish outside of CGI??
I will write my code examples in any style I wish
despite your self-proclaimed deity dictates.
> >exit;
> What's that unnecessary exit for?
I will write my code examples in any style I wish
despite your self-proclaimed deity dictates.
> This script fails in the case of an extension longer
> thanthree letters (increasingly common). For example
> file.html gives you filel as the base filename,
> obviously not what the original poster wanted.
Irrelevant. Your comments do not comply with the
originating author's stated parameters.
> why not use a simple regexp like:
> s/\.\w*$//;
Your code is exceptionally slow, inefficient and
highly memory wasteful.
I find your articles to be consistently a detriment
to this group. You serve no beneficial purpose here.
Godzilla!
------------------------------
Date: Fri, 27 Jul 2001 17:12:58 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Stripping extention from a filename in a string
Message-Id: <u8zhacn06.fsf@wrq.com>
"Ala Qumsieh" <qumsieh@sympatico.ca> writes:
>"Jason LaPenta" <lapenta_jm@yahoo.com> wrote in message
>news:3B60B687.B08F6531@yahoo.com...
>> Hi,
>>
>> I have a string var $filename = "filename.ext" and I want it to be
>> turned into $filename = "filename" by removing the ".ext" How can I do
>> this? I've been reading about pattern matching for an hour and can't
>> find even the slightest reference the such and operation.
>
>Perl comes with a plethora of documentation. Admittedly, it is a bit
>overwhelming to wade through at first, but once you get used to it, it
>becomes invaluable.
>
>For you specific task, you should read the perlre man page. Type 'perldoc
>perlre' on the command line and read on.
>
>Anyway, this code does what you want:
>
> $filename =~ s/\.[^.]+$//;
>
This will destroy file names like .emacs, which may or may not be what
the OP wants. I'm a beginner at re's, but if dotfiles need to be left
alone, would
$filename =~ s/([^.]+)\.[^.]+$/$1/;
be reasonable?
--
-- Steve __
------------------------------
Date: Fri, 27 Jul 2001 10:49:56 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Stripping extention from a filename in a string
Message-Id: <3B61A9C4.CB1042C5@stomp.stomp.tokyo>
Yves Orton AKA The CLPM Troll wrote:
> Jason LaPenta wrote:
(snipped)
> Response 3:
> Godzilla! (godzilla@stomp.stomp.tokyo) wrote:
> >substr ($filename, rindex ($filename, "."), 4, "");
> This one is a terrible solution. If you insert the filename
> "filename.text" into the filename list provided by godzilla you will
> see the output (for this filename) is:'filenamet' which is definitely
> wrong. DONT use this one.
Yours is a very lame and very poorly veiled troll article.
Godzilla!
------------------------------
Date: 27 Jul 2001 15:45:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: suidperl works on one system, not another
Message-Id: <9js2bk$sa3$1@mamenchi.zrz.TU-Berlin.DE>
According to David Efflandt <efflandt@xnet.com>:
> The following simple script (4755 permission) works on Linux Mandrake 7.0
> with Perl 5.005_03. However, on Linux SuSE 7.1 with Perl v5.6.0 it fails
> with simply "Can't do setuid" and no further explaination, if I am anyone
> other that root when I run it:
echo "Can't do setuid" | splain
[...]
> deffland@compaq:~ > ls -l /usr/bin/suidperl
> -rwxr-xr-x 2 root root 765243 Jan 18 2001 /usr/bin/suidperl
Afaik, suidperl must be setuid. It is normally not called directly,
but the standard perl exec's it under some circumstances.
Anno
------------------------------
Date: 27 Jul 2001 17:24:10 +0100
From: nobull@mail.com
Subject: Re: suidperl works on one system, not another
Message-Id: <u9zo9q1gt1.fsf@wcl-l.bham.ac.uk>
efflandt@xnet.com (David Efflandt) writes:
> The following simple script (4755 permission) works on Linux Mandrake 7.0
> with Perl 5.005_03. However, on Linux SuSE 7.1 with Perl v5.6.0 it fails
> deffland@compaq:~ > ls -l /usr/bin/suidperl
> -rwxr-xr-x 2 root root 765243 Jan 18 2001 /usr/bin/suidperl
SuSE Linux has stripped the SUID bit off /usr/bin/suidperl. If you
want suidperl to work you must reinstate it.
SuSE first did this in response to a report from me telling them that
suidperl was not safe on Linux because if failed to honour the nosuid
filesystem flag.
I do not know if this bug is fixed in 5.6.0 and if so if there is any
other valid reason not to install suidperl with the SUID bit set.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 27 Jul 2001 13:17:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: THIS GUY NEEDS A BULLET
Message-Id: <5hq2mtgnbam8706lrvpt0dmv1qemn9hc3c@4ax.com>
Andrew Hamm wrote:
>BEWARE, Brad! You have just fallen into a troll trap. This message comes
>around every few months and it is designed to trigger enormous arguments on
>the newsgroups.
I think not. IMO it's spam, posted in order to draw people TO that
website, instead of away from it.
--
Bart.
------------------------------
Date: 27 Jul 2001 18:00:53 +0100
From: nobull@mail.com
Subject: Re: using a mail program to work on Windows NT servers
Message-Id: <u9itge1f3u.fsf@wcl-l.bham.ac.uk>
Distortedrainbow@aol.com (Steve) writes:
> I've been reviewing a great many threads regarding sending email on on
> NT boxes, but hardly ever in layman's terms.
Laymen don't program on NT. The whole Microsoft mentality is "no user
servicable parts" compared to the Unix mentality of "all parts user
servicable".
> I've downloaded and installed net::smtp.
Sure it wasn't Net::SMTP ? (Perl module names are case sensative!)
Are you sure you installed it? (See recent flamewars about the
distinction between unpacking and installing).
> I'd like to use that in my
> scripts. Now, one web site i'm working on is on an NT server. I
> assume if I'm calling on net::smtp in a script, then that module must
> be uploaded to the cgi-bin directory on the server, is that correct?
Not quite, see FAQ: 'How do I keep my own module/library directory?'
> Is it also supposed to be in a particular path on my machine? If so,
> what's the proper path on my machine?
Whatever you decide.
> I've once uploaded smtp to my server, but am I supposed to set
> permissions for it?
Probably not. The user id as whom your Perl scripts run requires read
access to the files.
> In executing one of these scripts on an NT server, I got a message
> something like "Cannot locate net::smtp..." and it gave me locations
> and mentioned something about @INC.
Fix the @INC as per FAQ. Fix case.
> I really didn't understand the message very well.
Explainations of Perl error messages are found in the perldiag manual.
Please give details of what exactly what you found hard to understand
in the explaination of the error.
> The bottom line is: once the module is downloaded, where should it be
> installed into and how can I get it to execute in a script? I've read
> the FAQ pages that came with Perl, but they were vague.
Sometimes the answer really is "you choose". If there is something in
the manual that you don't understand then show us exactly what it is
so that if it really is unjustifiably vague one of us can send in a
patch.
Just because you are not yet a Perl expert does not mean you should
come to the community with the mindset "I only take, I have nothing to
give in return". As a relative newbie what you can give back to the
community is detailed information on shortcommings in the
documentation from a newbie perspective. Vague statements of
vagueness don't help to improve the documentation.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 27 Jul 2001 10:02:01 -0500
From: "UMurthy" <murthy@cox-internet.com>
Subject: Win32::OLE running Excel macro
Message-Id: <tm30if9vtlo664@corp.supernews.com>
I have a Perl script that's using Win32::OLE to open a couple of Excel files
and then run an Excel macro in one of the files. The thing works fine,
except if there's a problem with one of the files, which causes the macro to
hang. This results in the Perl script hanging as well.
Question: is there a way to specify a "time out" in the Win32::OLE call, so
that if the macro fails control can return to the Perl script (and possibly
return a message indicating that the macro failed, for whatever reason)?
The relevant part of the Perl script is below:
use Win32::OLE qw(in with);
use Win32::OLE::Enum;
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on errors...
$Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}); # get
already active Excel
# application or open
new
$xlfile = $Excel->Workbooks->Open($file1);
$xlfile1 = $Excel->Workbooks->Open($file2);
$Excel->Run("mymacro");
$xlfile1->Save;
If the "mymacro" macro fails, the whole script just hangs there
indefinitely. I'd like to have a "timeout" procedure where control returns
to the script even if the macro fails.
Any suggestions?
Thanks in advance!!
Uday
------------------------------
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 1393
***************************************