[12525] in Perl-Users-Digest
Perl-Users Digest, Issue: 6125 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 25 09:07:17 1999
Date: Fri, 25 Jun 99 06:00:18 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 25 Jun 1999 Volume: 8 Number: 6125
Today's topics:
Can't retain a directory change from within a script! (Paul D Enderson)
Can't retain a directory change from within a script! (Paul D Enderson)
Re: Can't retain a directory change from within a scrip <ibelgaufts@gfc-net.de>
Escape Newline ? <jarausch@igpm.rwth-aachen.de>
how do I save an MD5 checksum? <kevin.porter@fast.no>
Re: How to access MS Access using perl/cgi/unix <rootbeer@redcat.com>
Re: how to remove \n from middle of variable (Philip 'Yes, that's my address' Newton)
PB Opening word file with perl...Win32::OLE <olivier.maas@at-lci.com>
Re: Perl Alphanumeric Sort? <tlynch@cisco.com>
perl script for URLs? fheitka@ibm.net
Re: perl script for URLs? (Bart Lateur)
Re: perl script for URLs? (Jon Skeet)
Re: Read a file starting a a certain point in the middl (Philip 'Yes, that's my address' Newton)
Re: Reading Excel Sheets <gellyfish@gellyfish.com>
simple question. <hongy@panther.cs.ucla.edu>
Re: simple question. (Bart Lateur)
Re: simple question. <jcreed@cyclone.jprc.com>
Re: Viral matters [completely off-topic] (Philip 'Yes, that's my address' Newton)
Re: Viral matters [completely off-topic] (Philip 'Yes, that's my address' Newton)
Re: WWW-Authentication using CGi <rootbeer@redcat.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 25 Jun 1999 12:09:58 +0100
From: techsup@datascan.co.uk (Paul D Enderson)
Subject: Can't retain a directory change from within a script!
Message-Id: <MPG.11dd73de5ebdb056989680@news.demon.co.uk>
Hello,
I am trying to write a Perl5 script on an HP-UX machine that searches
through many directories trying to match a user input of three
characters, eg:
GO ABC (finds ABC_DEF, ABCD, ABC-BLUE etc)
I want to have the program change directory when it has found a match.
The problem I am having is that when I change directory from within the
script, and then exit the script, the directory change has been lost. I
think this is caused by Perl spawning a new shell to run the script (or
something similar) :)
Is there a way of retaining the modified directory variable once I have
quit the script? Any help would be greatly appreciated. Please CC to my
email address:
techsup(at)datascan.co.uk
Thanks!
Paul D Enderson
------------------------------
Date: Fri, 25 Jun 1999 12:12:03 +0100
From: techsup@datascan.co.uk (Paul D Enderson)
Subject: Can't retain a directory change from within a script!
Message-Id: <MPG.11dd7459dbc11893989681@news.demon.co.uk>
Hello,
I am trying to write a Perl5 script on an HP-UX machine that searches
through many directories trying to match a user input of three
characters, eg:
GO ABC (finds ABC_DEF, ABCD, ABC-BLUE etc)
I want to have the program change directory when it has found a match.
The problem I am having is that when I change directory from within the
script, and then exit the script, the directory change has been lost. I
think this is caused by Perl spawning a new shell to run the script (or
something similar) :)
Is there a way of retaining the modified directory variable once I have
quit the script? Any help would be greatly appreciated. Please CC to my
email address:
techsup(at)datascan.co.uk
Thanks!
Paul D Enderson
------------------------------
Date: Fri, 25 Jun 1999 14:03:04 +0200
From: =?iso-8859-1?Q?J=FCrgen?= Ibelgaufts <ibelgaufts@gfc-net.de>
Subject: Re: Can't retain a directory change from within a script!
Message-Id: <37736FF8.C590AE77@gfc-net.de>
Paul,
there might be a difference between Perl's builtin function chdir and the way
you possibly invoked chdir (did you use exec or system or backticks to use the
HP-UX command instead of Perl's command?)
Regards
Juergen
---------------------------------------------------------------
Paul D Enderson schrieb:
>
> Hello,
>
> I am trying to write a Perl5 script on an HP-UX machine that searches
> through many directories trying to match a user input of three
> characters, eg:
>
> GO ABC (finds ABC_DEF, ABCD, ABC-BLUE etc)
>
> I want to have the program change directory when it has found a match.
> The problem I am having is that when I change directory from within the
> script, and then exit the script, the directory change has been lost. I
> think this is caused by Perl spawning a new shell to run the script (or
> something similar) :)
>
> Is there a way of retaining the modified directory variable once I have
> quit the script? Any help would be greatly appreciated. Please CC to my
> email address:
>
> techsup(at)datascan.co.uk
>
> Thanks!
>
> Paul D Enderson
------------------------------
Date: Fri, 25 Jun 1999 14:21:50 +0200
From: Helmut Jarausch <jarausch@igpm.rwth-aachen.de>
Subject: Escape Newline ?
Message-Id: <3773745D.457A4950@igpm.rwth-aachen.de>
Sorry for that probably simple question!
Is there any (elegant) method to escape a newline?
E.g. for longish text using Perl/Tk I would like to write
$Help="1st part of line \
second part \
last part
before this there is a newline";
Unfortunately this doesn't work! Since I don't want extremely long
lines in the source,
the only solution I have come up so far is (ugly)
$Help="1st part of line ".
"second part ".
"last part
before this there is a newline";
Thanks for your solution,
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
Institute of Technology, RWTH Aachen
D 52056 Aachen, Germany
------------------------------
Date: Fri, 25 Jun 1999 13:58:22 -0400
From: kev <kevin.porter@fast.no>
Subject: how do I save an MD5 checksum?
Message-Id: <3773C33E.F419AEBD@fast.no>
I'm using an MD5 checksum to determine whether a web page has changed
since my web client prog last visited it.
The checksum can contain some weird characters which I'd like to escape
before putting it in a file. What is the usual method for doing this?
-Kev
------------------------------
Date: Fri, 25 Jun 1999 05:41:54 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How to access MS Access using perl/cgi/unix
Message-Id: <Pine.GSO.4.02A.9906250533330.6929-100000@user2.teleport.com>
On Wed, 23 Jun 1999, Bruce Chao wrote:
> Is there any way that I can connect to MS Access
> from a Netscape Server on Unix platform using /Perl/Cgi???
Well, maybe, if your machine has a program called /Perl/Cgi. But I've
never heard of such a program.
Maybe you want to make a Perl program to run in a CGI environment on a
Unix system which can connect to a MS Access database while running under
a Netscape webserver. If you could make a program in any language which
will run in a CGI environment on a Unix system and which can connect to a
MS Access database while running under a Netscape webserver, you can
almost certainly do the same with Perl.
Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 25 Jun 1999 12:53:45 GMT
From: nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton)
Subject: Re: how to remove \n from middle of variable
Message-Id: <37737af8.66512557@news.nikoma.de>
On Thu, 24 Jun 1999 17:47:09 GMT, Kazuma <kazuma@my-deja.com> wrote:
>You shoud use the substitution...
>
>$variable =~ s/\n/ /g;
No, you shouldn't. Ask Larry Rosler why not.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.net>
------------------------------
Date: Fri, 25 Jun 1999 14:18:35 +0200
From: Olivier Maas <olivier.maas@at-lci.com>
Subject: PB Opening word file with perl...Win32::OLE
Message-Id: <3773739B.5774F3F6@at-lci.com>
Hello
Here is a little piece of code:
##################################################
use Win32::OLE;
$application=Win32::OLE->GetActiveObject('Word.Application');
print "step 1";
unless (defined $application)
{
$application=Win32::OLE->new('Word.Application', 'Quit') || warn
"Impossible de créer un objet OLE";
print "step 2";
$CloseWhenGoingOut=1;
}
print "step 3 $fichier $application<BR>\n";
$document=$application->Documents->Open("$fichier");
print "step 4 <BR>\n $NomFichLocal <BR>\n $CloseWhenGoingOut $document
av\n";
$res= $document->{'Name'};#
print "$res step 1.5 \n";
$res=$document->SaveAs('c:\temp\testtest.txt',wdFormatText);
print "\n normally $res saved 2 \n";
$res= $document->Saved;
print "$res step 4.5 \n";
$res=$document->{'Name'};
print "$res step 5 \n";
$document->Close(0);
print "step 6\n";
$application->quit();
if (defined $CloseWhenGoingOut)
{
DESTROY ($application);
print "step 7";
}
#############################################
the $fichier looks allright (c:\InetPub\wwwroot\results\Or.doc)
the file exists and the same code works localy on my machine, but not on
the server.
the server (NT4) has Word and Excel installed, Active perl 5.09.
the error message goes :
Can't call method "SaveAs" on unblessed reference at assist.pl line
72...
I really cannot see what can go wrong...
any idears???
please also reply by email to maas@ensae.fr
olivier
passme
------------------------------
Date: Fri, 25 Jun 1999 08:18:55 -0400
From: Tom Lynch <tlynch@cisco.com>
Subject: Re: Perl Alphanumeric Sort?
Message-Id: <377373AF.148F3223@cisco.com>
Greetings:
I don't think the orginal poster gave enough information,
however I'm will to guess that if you change the array to
my @letter_nums = ("A11","A2","A1","A3");
You'll end up with:
A1 A11 A2 A3
Which is wrong, I had this same problem a while back and
Tom Christiansen was kind enough to send this little
program along:
#!/usr/local/bin/perl -w
#
# $USAGE = "ansort <column> <filename>";
#
# This perl script will sort alpha-numerics. Pulled from
# the perl news group. Prints to STDOUT.
#
use strict;
use vars qw($a $b);
use File::Basename;
$0 = basename $0;
die "syntax: $0 colnum [file ...]\n" unless @ARGV;
my($col) = shift;
print map { $_->[0] }
sort { $a->[1] cmp $b->[1] or $a->[2] <=> $b->[2] }
map { [ $_, (split)[$col] =~ /([a-z]+)(\d+)/i ] } <>;
Good Luck
Tom
>
> Short answer: I don't believe you!
>
> Long answer: This works exactly as expected. Can you provide a small
> program in which it doesn't? Here is my program in which it does work:
>
> #!/usr/local/bin/perl -w
> use strict;
>
> my @letter_nums = ("A4","A2","A1","A3");
>
> my @temp1 = sort by_values (@letter_nums);
>
> print "@temp1\n";
>
> sub by_values
> {
> ($a cmp $b)
> }
> __END__
>
> Output:
>
> A1 A2 A3 A4
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
--
#-----------------------+--------------------------+
# Tom Lynch | Email: tlynch@cisco.com |
# Cisco Systems | Phone: 978-244-8765 |
# 250 Apollo Drive | FAX: 978-244-8039 |
# Chelmsford MA 01824 | MS: CH1-2LF |
#-----------------------+--------------------------+
------------------------------
Date: 25 Jun 1999 11:38:25 GMT
From: fheitka@ibm.net
Subject: perl script for URLs?
Message-Id: <37736a31@news1.us.ibm.net>
Keywords: perl, URL,
I'm looking for a perl script that will take a plain
text list of URLS and turn them in to a clickable
list that works in a browser like Netscape. Does
anyone know of such a beast?
--
Fred
------------------------------
Date: Fri, 25 Jun 1999 12:06:59 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: perl script for URLs?
Message-Id: <37757002.2102803@news.skynet.be>
fheitka@ibm.net wrote:
>I'm looking for a perl script that will take a plain
>text list of URLS and turn them in to a clickable
>list that works in a browser like Netscape. Does
>anyone know of such a beast?
Hey, this is perl. The next script will not generate a full-blown HTML
file (it lacks the necessary header and footer, plus other fancy stuff),
but it's a start.
print "<UL>\n";
while(<>) { # file with URL list (one URL per line)
#as argument to script
chomp;
print "<LI><A HREF=\"$_\">$_</A>\n";
}
print "</UL>\n";
Bart.
------------------------------
Date: Fri, 25 Jun 1999 13:44:14 +0100
From: skeet@pobox.com (Jon Skeet)
Subject: Re: perl script for URLs?
Message-Id: <MPG.11dd89f83e9956619898fb@news>
fheitka@ibm.net wrote:
> I'm looking for a perl script that will take a plain
> text list of URLS and turn them in to a clickable
> list that works in a browser like Netscape. Does
> anyone know of such a beast?
Not that I had one, but it's not the hardest script in the world to
write :)
#!/usr/bin/perl
print "<html><body>\n";
while (<>)
{
chomp;
print "<a href=\"$_\">$_</a>\n";
}
print "</body></html>\n";
This just takes the URLs from stdin, so if you've got a file urls.txt and
the perl script is called urlfiles.pl, you'd use something like:
./urlfiles.pl < urls.txt
Hope this is what you're after...
--
Jon Skeet - skeet@pobox.com
http://www.pobox.com/~skeet/
------------------------------
Date: Fri, 25 Jun 1999 12:53:45 GMT
From: nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton)
Subject: Re: Read a file starting a a certain point in the middle
Message-Id: <37737b25.66558401@news.nikoma.de>
On Thu, 24 Jun 1999 20:06:30 GMT, bart.lateur@skynet.be (Bart Lateur)
wrote:
>Philip 'Yes, that's my address' Newton wrote:
>
>>perldoc -f seek may help you; however, seek() only knows about bytes,
>>not about lines.
>
>Oh, doing a random seek(), and reading and ignoring the first line
>(unless you seeked to the very start of the file) will get rid of the
>half-line.
True. However, this does not help the person who knows "$. was 28792
at the end of yesterday's run, so I'll just seek to ... errm, what
(byte) offset *do* I seek to?"
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.net>
------------------------------
Date: 25 Jun 1999 12:17:53 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Reading Excel Sheets
Message-Id: <37736561@newsread3.dircon.co.uk>
baga@gmx.net <baga@gmx.net> wrote:
> Hello!
>
> I want to read out special fields of an excel sheet with a perl
> program. Does someone know if that is possible or not?
>
You should use Win32::OLE - the ActiveState distribution includes a
number of examples of working with Excel spreadsheets...
/J\
--
"People say money brings its own problems. Rubbish, rubbish - I'm loaded -
it's fantastic" -
------------------------------
Date: 22 Jun 1999 19:12:49 GMT
From: Hong Yuan <hongy@panther.cs.ucla.edu>
Subject: simple question.
Message-Id: <7kon7h$ktm$1@news.cs.ucla.edu>
Hi
I have a line in a subroutine like this:
opendir(D, $dir) || (warn "Can't open $dir: $!\n" and return);
^^^
If I change it to:
opendir(D, $dir) || (warn "Can't open $dir: $!\n", return);
^
It won't print the warning message to STDERR.
Why?
Thx!
Hong Yuan.
------------------------------
Date: Fri, 25 Jun 1999 12:02:30 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: simple question.
Message-Id: <37746cf2.1319298@news.skynet.be>
Hong Yuan wrote:
>opendir(D, $dir) || (warn "Can't open $dir: $!\n" and return);
> ^^^
>If I change it to:
>
>opendir(D, $dir) || (warn "Can't open $dir: $!\n", return);
> ^
>It won't print the warning message to STDERR.
>
>Why?
Probably before it returns before anything is printed. Let's see.
#! perl -w
print "Before\n";
&test;
print "After\n";
sub test {
print "One\n";
print "Two\n", return;
print "Three\n";
}
__END__
Output:
Before
One
After
You don't see not just the "Three", but the "Two" also isn't printed.
This means that the sub is exited while evaluating the parameters for
the second print statement, BEFORE the call to print(). So, "print" s
never called. It's a bit weird, I admit.
You can fix that by adding parentheses.
opendir(D, $dir) || (warn("Can't open $dir: $!\n"), return);
This shows to the parser that warn has only one parameter, and that the
"return" keyword is a sibling of "warn", not a parameter.
If you try the same with print(), you MAY need a "+" sign, to avoid
warnings. Let's see... Change the "two" line to:
print (...) interpreted as function at test.pl line 9.
print ("Two\n"), return;
and now the output is:
print (...) interpreted as function at test.pl line 9.
Before
One
Two
After
It now prints a "Two", but also a warning.
print +("Two\n"), return;
Gives the same output without the warning. Yet another, more Lisp-ish
solution is
(print "Two\n"), return;
Bart.
------------------------------
Date: 25 Jun 1999 08:37:54 -0400
From: Jason Reed <jcreed@cyclone.jprc.com>
Subject: Re: simple question.
Message-Id: <a19098qwv1.fsf@cyclone.jprc.com>
Hong Yuan <hongy@panther.cs.ucla.edu> writes:
> Hi
> I have a line in a subroutine like this:
> opendir(D, $dir) || (warn "Can't open $dir: $!\n" and return);
> If I change it to:
> opendir(D, $dir) || (warn "Can't open $dir: $!\n", return);
> It won't print the warning message to STDERR.
Warn's a list operator; In the second example, the return
gets evaluated (as part of the list warn is operating on)
before warn actually does its job of printing the error message.
Try calling
sub foo { print "42", return }
and the same (no)thing will happen.
What you can do to avoid this is put parens around the warn, like this:
opendir(D, $dir) || ((warn "Can't open $dir: $!\n"), return);
or make it a do-block: (not necessarily recommended in this case)
opendir(D, $dir) || do {warn "Can't open $dir: $!\n"; return};
or just use unless:
unless (opendir(D, dir)) {
warn "Can't open $dir: $!\n";
return;
}
---Jason
------------------------------
Date: Fri, 25 Jun 1999 12:53:44 GMT
From: nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton)
Subject: Re: Viral matters [completely off-topic]
Message-Id: <37737928.66049205@news.nikoma.de>
That's "I don't dare" in my other posting, not "Don't you dare".
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.net>
------------------------------
Date: Fri, 25 Jun 1999 12:53:43 GMT
From: nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton)
Subject: Re: Viral matters [completely off-topic]
Message-Id: <377378c6.65950891@news.nikoma.de>
On Thu, 24 Jun 1999 10:01:16 -0700, David Cassell
<cassell@mail.cor.epa.gov> wrote:
>Philip 'Yes, that's my address' Newton wrote:
>>
>> After installing the newest ActiveState build of Perl in order to get
>> newer docs, I had a look at some of the Win32 specific facts. One of
>> them specifically points people at Selena Sol's and Matt Wright's
>> script archives as places to get scripts from. ... Don't know whether
>> there's much to add to that.
>
>It's another viral infection, of course. Maybe you should
>mention this to ActiveState.
Don't dare. For one, I've never seen any code directly[1] and can't
comment on the quality -- I've just gained the strong impression (from
reading this newsgroup) that the quality is not very good.
Cheers,
Philip
[1] Except, of course, for "How to misparse a CGI query string", again
and again.
--
Philip Newton <nospam.newton@gmx.net>
------------------------------
Date: Fri, 25 Jun 1999 05:27:13 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: WWW-Authentication using CGi
Message-Id: <Pine.GSO.4.02A.9906250524080.6929-100000@user2.teleport.com>
On Thu, 24 Jun 1999, Mohd Idaham wrote:
> I'm trying to create a script where users can relogin with their other
> account.
This sounds as if you're having trouble with the environment your program
is running in. If that's the Common Gateway Interface (CGI) environment,
you may find better help in the docs, FAQs, and newsgroups about CGI. Do
you know where to find those?
> But unfortunately the script doesn't work.
That's quite vague. In exactly what way does your program not work?
> #!/usr/bin/perl
The perl docs will tell you about the -w warnings option and the 'use
strict' pragma.
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> @pairs = split(/&/, $buffer);
Use the CGI module. It not only does all this for you...
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
> else { $INPUT{$name} = $value; }
> }
...but it'll do it correctly, as well.
> open (SA, "<switch.num");
Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.
> open (SA, ">switch.num");
> print SA "$Last\n";
> close SA;
I think you could use the methods in Randal's fourth Web Techniques
column, which explains how to use flock() to avoid problems when multiple
processes need to modify one file.
http://www.stonehenge.com/merlyn/WebTechniques/
Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 6125
**************************************