[19601] in Perl-Users-Digest
Perl-Users Digest, Issue: 1796 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 23 18:05:45 2001
Date: Sun, 23 Sep 2001 15:05:10 -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: <1001282710-v10-i1796@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 23 Sep 2001 Volume: 10 Number: 1796
Today's topics:
Re: [ASK[ Perl and Windows <bwalton@rochester.rr.com>
Re: access old DIBOL file <cb@onsitetech.com>
Re: CGI module (Chad Yoshikawa)
Re: CGI module <bwalton@rochester.rr.com>
eval-statement fools garbage-collection ? <pilsl_@goldfisch.at>
Re: garbage collextion - anonymous structures : self an <pilsl_@goldfisch.at>
Re: Getting "Subject" in (Net::POP3) <bwalton@rochester.rr.com>
Re: Getting "Subject" in (Net::POP3) <Tassilo.Parseval@post.rwth-aachen.de>
Re: Help with reading web page from socket. <bart.lateur@skynet.be>
How to remove whitespace without losing the 'real' whit (RiCaRdO)
Re: How to remove whitespace without losing the 'real' (Logan Shaw)
Re: How to remove whitespace without losing the 'real' (Tim Hammerquist)
Re: how to replace several blank lines with 1 <goldbb2@earthlink.net>
locating cd drive <matthew.garrish@sympatico.ca>
Re: locating cd drive <bwalton@rochester.rr.com>
Re: locating cd drive <philip@zaynar.demon.co.uk>
Matching Strings Help Needed (Ralph Freshour)
Re: Me VS. Parsing <rob_13@excite.com>
Re: only allowing characters from a list to be inputed <goldbb2@earthlink.net>
Re: Perl or not? <newspost@coppit.org>
Re: Perl or not? (Logan Shaw)
Re: perl, lvalues, rvalues, and operators <tinamue@zedat.fu-berlin.de>
Re: pretty printing a web page <goldbb2@earthlink.net>
Re: Problems with $ character <goldbb2@earthlink.net>
Re: regex needed <goldbb2@earthlink.net>
Re: Setting cookies <rob_13@excite.com>
Re: Simple question <tsee@gmx.net>
Re: Socket server closing itself when client disconnect <goldbb2@earthlink.net>
Re: Sorting Hashes <goldbb2@earthlink.net>
Re: Unusual error message... <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 23 Sep 2001 20:29:15 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: [ASK[ Perl and Windows
Message-Id: <3BAE458B.95EBA346@rochester.rr.com>
"¤ßÂÅ Dennis" wrote:
>
> How can a PERL script only show at tray-icon without text-console?????
If it is run under a decent OS instead of Windoze. But even with
Windoze, depending on your version of Windoze, you could check out
"srvany" -- see the ActiveState faqs -- don't know if that would help,
but it might. You might also be able to write a C-language stub that
would fire up Perl without the annoying black window. Or if you put a
"use Tk;" in your program, the annoying black window will show for only
a bit. You might also be able to create a shortcut that specifies the
program be run minimized, and, if it is fired up via that shortcut, it
would run minimized. There are probably other ways, too.
--
Bob Walton
------------------------------
Date: 23 Sep 2001 21:32:24 GMT
From: "Christian Brink" <cb@onsitetech.com>
Subject: Re: access old DIBOL file
Message-Id: <9olkd8$970@dispatch.concentric.net>
Jeremiah -
I did this about 3 years ago. DIBOL uses a proprietary ISAM format that I
never found a module for. What you have to do is use the DIBOL dump
utilities to dump the tables. The Schema is laid out in text files that are
a bitch to parse, but I did it in about a month. I will try and dig that
script up and send it to you, but I am not at work right now so if you send
me and email 'cb@onsitetech.com' I will remember to look for it.
What it did was use the DIBOL utilities to dump the database in ASCII. The
format of the dump is fixed len, but it gets worse. All floating point
numbers in the ASCII dump (get this) use a proprietary format (i.e. if the
number is negative the last digit is a lower case letter q-z. The fact that
it is a letter designates that it is a negative number and 'q' thru 'z'
represent the last digit being 0-9) The place of the decimal is set (if I
remember correctly by the schema). So the program goes parses the scheme for
field len and dec place. This schema parsing gets real hairy since you can
have (get this) overlapping schemas on the same row (this unfortunately was
a popular feature). So you will also have to go thru the schema files and
edit them to the most granular schema.
So to make a long story short - ' BE AFRAID BE VERY VERY AFRAID'
BTW as a side note DEC sold DIBOL off to a company that keeps DIBOL alive
(heaven forbid) I forget the name but a google search on DIBOL will provide
it. (All I remember about the name was it used obnoxious buzzwords in the
title like, Synergy or Paradigm or something)
"jeremiah" <brimstonesfc@hotmail.com> wrote in message
news:4a7434b6.0109211303.794f401f@posting.google.com...
> I've got a bit of a problem. I need to acces an old DIBOL db via perl.
> I can't seem to find much on the the net concerning DIBOL and searches
> on cpan for existing modules didn't yield any thing that directly
> relates to my problem. I'm considering just something with DBI but am
> at a loss to how the data is writen by DIBOL. Any suggestions? Any
> clues where I can find some helpful info? THanks
>
> Jeremiah
------------------------------
Date: Sun, 23 Sep 2001 17:55:23 GMT
From: m_010@yahoo.com (Chad Yoshikawa)
Subject: Re: CGI module
Message-Id: <3bae1eb8.1177242@enews.newsguy.com>
On Sun, 23 Sep 2001 11:24:04 +0000, Andrew McGregor
<a.mcgregor@bath.ac.uk> wrote:
>Chad Yoshikawa wrote:
>>
>> I heard the CGI module ( use CGI; ) is come with standard perl
>> distribution, I think i should use that, since I don't have permission
>> to install extra perl module( e.g. CGI Lite ..etc ) on my perl
>> machine.
>
>yes.
>
>> CGI-QuickForm-1.92 ...etc etc
>
>QuicForm is written by a different programmer and relies on CGI.pm being
>installed. You can install it to your home dir and use the -I switch:
>
>#!/perl -TwI/path/to/home/dir
what's the -I flag of the perl command does? I had looked at the
perldoc --> perldoc perl but i didn't find any info on each of the
switch of perl command.
I know perl -w means show warning.
but what's perl -T in the above?
Is that perl -I /opt/apache/cgi-bin/cgi-lite.pm, then i can use the
cgi-lite module?
I heard to install a perl module, I need to do:
perl Makefile.PL
make
make test
make install
I wonder what are each of those steps different from putting the
actual perl module (test.pm) into perl's path witha copy command?
/usr/local/lib/perl5/5.00503/sun4-solaris
/usr/local/lib/perl5/5.00503
/usr/local/lib/perl5/site_perl/5.005/sun4-solaris
/usr/local/lib/perl5/site_perl/5.005
What are the the paths above use for? i saw alot of modules in
/usr/local/lib/perl5/5.00503, Which dir has the core perl modules?
>
>It is particularly good at, well, developing forms quickly.
>
>> But I browsed through CPAN categories but can't find a module call CGI
>> ( use CGI; ). Where can I find documentation for this module?
>
>http://stein.cshl.org/WWW/software/CGI/
------------------------------
Date: Sun, 23 Sep 2001 20:55:24 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: CGI module
Message-Id: <3BAE4BA9.DAF493E8@rochester.rr.com>
Chad Yoshikawa wrote:
>
> On Sun, 23 Sep 2001 11:24:04 +0000, Andrew McGregor
> <a.mcgregor@bath.ac.uk> wrote:
>
> >Chad Yoshikawa wrote:
...
> what's the -I flag of the perl command does? I had looked at the
> perldoc --> perldoc perl but i didn't find any info on each of the
> switch of perl command.
perldoc perlrun
...
--
Bob Walton
------------------------------
Date: Sun, 23 Sep 2001 20:32:43 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: eval-statement fools garbage-collection ?
Message-Id: <3bae2acc$1@e-post.inode.at>
I work with big anonymous structures and have the problem, that garbage
collection doesnt work. First I thought about circular references, but now
I found my problem:
When I add an anonymous subroutine to my structure via an eval-statement
(the routine is defined in a config-file that is parsed), something goes
awfully wrong. The used mem of the structure is not released. This happens
only when involving an eval in a sub that adds an anonymous sub to the
structure ....
I wrote a small script that shows my problem:
(It runs on unixlike systems only cause I use `ps` for easy printing of
used memory)
----script named mem.pl ----
#!/usr/bin/perl -w
use strict;
print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
my $ptr={};
$ptr->{big}=[];
$#{$ptr->{big}}=5000000;
def2($ptr);
print &{$ptr->{test}->{func2}}(5),"\n";
print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
undef $ptr;
print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
sub def2 {
my $ptr=shift;
my $cmd='$ptr->{test}->{func2}=sub{return $_[0]+4};';
# $ptr->{test}->{func2}=sub{return $_[0]+4};
eval $cmd;
}
when running this way I get (skipped last column, the 5th column is the
size):
pilsl 24212 0.0 1.0 2816 1288 pts/9 S 20:17 0:00
9
pilsl 24212 0.0 16.4 22356 20900 pts/9 S 20:17 0:00
pilsl 24212 0.0 16.4 22356 20904 pts/9 S 20:17 0:00
So the memory is *not* freed at the undef-statement ..
When commenting the eval-statement in the def2-sub and uncomment the other
assignment, I get the following (expected result):
pilsl 24245 0.0 1.0 2820 1292 pts/9 S 20:21 0:00
9
pilsl 24245 0.0 16.4 22356 20900 pts/9 S 20:21 0:00
pilsl 24245 0.0 1.0 2824 1372 pts/9 S 20:21 0:00
So the mem is released at the undef-statement ...
this is strange ...
thnx,
peter
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Sun, 23 Sep 2001 20:28:54 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: garbage collextion - anonymous structures : self and cross-references
Message-Id: <3bae29e8@e-post.inode.at>
Bob Walton wrote:
>
> Perl's garbage-collection model is very simple: When the reference
> count to an entity goes to zero, the entity is garbage-collected. If
> the reference count is not zero, it is not garbage-collected.
> Therefore, collections of entities containing circular references are
> not garbage-collected. If you want them to be garbage-collected, you
> must break the circular reference structure. It is done this way for
> efficiency: the only overhead needed is a test whenever a reference
> counter is decremented: is it now zero? See perldoc perlguts, in
> particular the section "reference counts and mortality".
>
I really digged my script for hours now and finally found the problem.
Unfortunately it has nothing to do with circular references, but with a
eval-statement that somehow seems to add an additional reference count.
I decided to start a new thread about this (subject " eval-statement fools
garbate-collection ?")
thnx,
peter
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Sun, 23 Sep 2001 20:04:39 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Getting "Subject" in (Net::POP3)
Message-Id: <3BAE3FC7.C54385B2@rochester.rr.com>
eDeveloper wrote:
...
> I coded a script that get email messages in a pop server
> but the problem is : some messages has a strange subject
> for example : ?windows-1256?B?0d3WIMfh4+TKz+wgytPM7eHt?=
...
> eDeveloper
If that is what the subject is, why is that a problem?
--
Bob Walton
------------------------------
Date: Sun, 23 Sep 2001 22:56:58 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Getting "Subject" in (Net::POP3)
Message-Id: <3BAE4C9A.3020801@post.rwth-aachen.de>
Bob Walton wrote:
>>I coded a script that get email messages in a pop server
>>but the problem is : some messages has a strange subject
>>for example : ?windows-1256?B?0d3WIMfh4+TKz+wgytPM7eHt?=
>>
> ...
>
>>eDeveloper
>>
>
> If that is what the subject is, why is that a problem?
The problem is that this is base64 encoded data. Can you read it? I can't.
MIME::Words should be able to deal with that.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 23 Sep 2001 21:06:30 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Help with reading web page from socket.
Message-Id: <f7jsqto1l07hfbep4k0hlsslko8d6oq2nb@4ax.com>
Brian Carlson wrote:
>I am trying to read a web page from a socket, and I'm getting a 400 (bad
>request), Parameter Incorrect. What am I doing wrong? I'm trying to
>read the baseball scoreboard from espn.
>
>Here's what im doing....
>
>
>$socket =
>IO::Socket::INET->new(Proto=>"tcp",PeerAddr=>"msn.espn.go.com",PeerPor
>t=>"80") or die "Can't open socket";
>
>
>print $socket "GET /mlb/scoreboard HTTP:/1.0\n\n";
>
> while ($raw_line = <$socket>)
> {
> print "$raw_line\n";
> }
First of all, the URL appears to be wrong. Today, you appear to have to
use <http://sports.espn.go.com/mlb/scoreboard>.
Second: why aren't you using LWP::Simple?
And finally, there's a scriptlet that can be reached from
<http://www.delorie.com/web/headers.html> that takes your approach (AKA
"the hard way") and which seems to have no problem with this particular
web page. It's not 100% kosher, "\r" and "\n" are actually system
dependent, which is a bad thing; but it's a start.
--
Bart.
------------------------------
Date: Sun, 23 Sep 2001 19:55:56 GMT
From: rdok@netscape.net (RiCaRdO)
Subject: How to remove whitespace without losing the 'real' whitespace?
Message-Id: <3bae3c3f.39612059@ricardo.tuus.nl>
N.G.,
I'm looking for a way to filter out whitespaces from an input file
without losing the actual information in a script that reads shares on
a system to recreate them on another server.
I came up with this:
my $inputfile="testfile.txt";
my $dummy;
my $lengte;
my $teller;
my $voor;
my $na;
my $middel;
my $result;
open (leesfile,$inputfile) or die "bestand niet gevonden: ($dummy)\n";
while ($dummy = <leesfile>) {
$teller=1;
$lengte=length($dummy)-1;
$result = substr($dummy,0,1);
while ($lengte>=$teller) {
$voor = substr($dummy,($teller-2),1);
$middel= substr($dummy,($teller-1),1);
$na = substr($dummy,$teller,1);
if ((($voor eq " " || $voor eq "") && ($middel eq " "
&& $na eq " ")) || ($voor ne " " && $middel eq " " && $na eq " ")) {}
else {$result=$result.$middel}
if ($na eq "\n") {$result=$result."\n"}
$teller=$teller+1;
}
print $result;
}
testfile contains examples like
a b
c
d
e
and the output should be like
a b
c
d
e
variables 'voor' (previous character in line), 'middel' (the actual
character) and 'na' (character following 'middel') seem to be OK but
the output is incorrect. I can't figure out what the if-statement
should look like and, in fact, I'm pretty sure that there must be a
much easier way.
Any advice?
TIA,
Richard.
------------------------------
Date: 23 Sep 2001 15:09:14 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: How to remove whitespace without losing the 'real' whitespace?
Message-Id: <9olfha$hgn$1@charity.cs.utexas.edu>
In article <3bae3c3f.39612059@ricardo.tuus.nl>,
RiCaRdO <rdok@netscape.net> wrote:
>I'm looking for a way to filter out whitespaces from an input file
>without losing the actual information in a script that reads shares on
>a system to recreate them on another server.
:
:
>open (leesfile,$inputfile) or die "bestand niet gevonden: ($dummy)\n";
>while ($dummy = <leesfile>) {
> $teller=1;
> $lengte=length($dummy)-1;
> $result = substr($dummy,0,1);
> while ($lengte>=$teller) {
> $voor = substr($dummy,($teller-2),1);
> $middel= substr($dummy,($teller-1),1);
> $na = substr($dummy,$teller,1);
> if ((($voor eq " " || $voor eq "") && ($middel eq " "
>&& $na eq " ")) || ($voor ne " " && $middel eq " " && $na eq " ")) {}
> else {$result=$result.$middel}
> if ($na eq "\n") {$result=$result."\n"}
> $teller=$teller+1;
> }
> print $result;
>}
>
>testfile contains examples like
> a b
> c
> d
>e
>
>and the output should be like
>a b
>c
>d
>e
I'm not sure if I understand what your script is trying to do, but if I
do understand, then I think you should use the substitution operator.
It will make things much simpler. Here is one way to write it:
open (FOO, $inputfile) or die "can't open $inputfile ($!)\n";
while ($line = <FOO>)
{
# collapse every sequence of white space into a single space
$line =~ s/\s+/ /g;
# remove the space at the end, if any
$line =~ s/ $//;
# remove the space at the beginning, if any
$line =~ s/^ //;
print $line;
}
close FOO;
Hope that helps.
- Logan
--
"Everybody
Loves to see
Justice done
On somebody else" ( Bruce Cockburn, "Justice", 1981 )
------------------------------
Date: Sun, 23 Sep 2001 20:59:33 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: How to remove whitespace without losing the 'real' whitespace?
Message-Id: <slrn9qsk2j.h63.tim@vegeta.ath.cx>
Me parece que Logan Shaw <logan@cs.utexas.edu> dijo:
> In article <3bae3c3f.39612059@ricardo.tuus.nl>,
> RiCaRdO <rdok@netscape.net> wrote:
> >I'm looking for a way to filter out whitespaces from an input file
> >without losing the actual information in a script that reads shares on
> >a system to recreate them on another server.
> :
> :
> >open (leesfile,$inputfile) or die "bestand niet gevonden: ($dummy)\n";
> >while ($dummy = <leesfile>) {
> > $teller=1;
> > $lengte=length($dummy)-1;
> > $result = substr($dummy,0,1);
> > while ($lengte>=$teller) {
> > $voor = substr($dummy,($teller-2),1);
> > $middel= substr($dummy,($teller-1),1);
> > $na = substr($dummy,$teller,1);
> > if ((($voor eq " " || $voor eq "") && ($middel eq " "
> >&& $na eq " ")) || ($voor ne " " && $middel eq " " && $na eq " ")) {}
> > else {$result=$result.$middel}
> > if ($na eq "\n") {$result=$result."\n"}
> > $teller=$teller+1;
> > }
> > print $result;
> >}
> >
> >testfile contains examples like
> > a b
> > c
> > d
> >e
> >
> >and the output should be like
> >a b
> >c
> >d
> >e
>
> I'm not sure if I understand what your script is trying to do, but if I
> do understand, then I think you should use the substitution operator.
> It will make things much simpler. Here is one way to write it:
>
> open (FOO, $inputfile) or die "can't open $inputfile ($!)\n";
> while ($line = <FOO>)
> {
> # collapse every sequence of white space into a single space
> $line =~ s/\s+/ /g;
>
> # remove the space at the end, if any
> $line =~ s/ $//;
>
> # remove the space at the beginning, if any
> $line =~ s/^ //;
>
> print $line;
> }
> close FOO;
This will also strip newlines, as \s matches \n (and \r).
It produces 'a bcde'. Unless you prefer to chop/chomp it out and put it
back before output, we can just narrow the definition of WS. The most
likely per-line, non-EOL whitespace chars are ' ' (space) and \t (tab).
ergo:
#!/usr/bin/perl -w
# ws_strip
while (<>) {
s/[ \t]+/ /g;
s/[ \t]*$//;
s/^[ \t]*//;
print;
}
(or the oneliner version:
s/[ \t]+/ /g, s/[ \t]*$//, s/^[ \t]*//, print while <>;
)
And us it like so:
$ ws_strip infile > outfile
$ script | ws_strip > outfile
$ ws_strip infile | parser
...the glories of Perl's diamond op.
HTH
--
All language designers are arrogant. Goes with the territory...
-- Larry Wall
------------------------------
Date: Sun, 23 Sep 2001 15:04:40 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: how to replace several blank lines with 1
Message-Id: <3BAE3248.C93D7066@earthlink.net>
Jonadab the Unsightly One wrote:
>
> ced@bcstec.ca.boeing.com (Charles DeRykus) wrote:
>
> > >I cannot find how to replace or delete several successive blank
> > >lines from a text file.
> >
> > perl -ni.bak -e 'print if !/^$/' file1 file2 ...
>
> That removes *all* blank lines. Admittedly, he could have
> been more clear, but I *think* what he wanted was to remove
> only multiple adjascent blank lines, leaving one...
[snip]
perl -lp00i.bak -e1 file1 file2 ...
NB this is untested.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Sun, 23 Sep 2001 15:09:31 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: locating cd drive
Message-Id: <Foqr7.517$aP1.287859@news20.bellglobal.com>
I'm trying to write a search program that will read the contents of a CD and
was wondering if anyone knows if there is an easier way to locate the drive
(the script will be dumped locally onto the user's hard drive as part of the
install, but I need to allow them to search the documents on the CD, which
are not). Currently, I just run a test of drives a-z to see if one of the
files exists:
for (a..z) {
my $test_file = $_ . ':\courses\lnote.txt';
if (-f $test_file) {
$root_dir = $_ . ':\\';
last;
}
}
Luckily, I only need to worry about testing windoze drives, so the above
will work if nothing else (yes, barring another directory with the same name
and file!). I just don't like hearing the floppy drive being checked (I
guess I could reverse the search order or exclude drives a and b in the
hopes that no one uses them, but those are less aesthetically pleasing
alternatives...) Any ideas would be greatly appreciated!
Thanks in advance,
Matt
------------------------------
Date: Sun, 23 Sep 2001 20:42:42 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: locating cd drive
Message-Id: <3BAE48B0.1AA7104F@rochester.rr.com>
Matt Garrish wrote:
>
> I'm trying to write a search program that will read the contents of a CD and
> was wondering if anyone knows if there is an easier way to locate the drive
> (the script will be dumped locally onto the user's hard drive as part of the
> install, but I need to allow them to search the documents on the CD, which
> are not). Currently, I just run a test of drives a-z to see if one of the
> files exists:
>
> for (a..z) {
>
> my $test_file = $_ . ':\courses\lnote.txt';
>
> if (-f $test_file) {
>
> $root_dir = $_ . ':\\';
> last;
>
> }
>
> }
>
> Luckily, I only need to worry about testing windoze drives, so the above
> will work if nothing else (yes, barring another directory with the same name
> and file!). I just don't like hearing the floppy drive being checked (I
> guess I could reverse the search order or exclude drives a and b in the
> hopes that no one uses them, but those are less aesthetically pleasing
> alternatives...) Any ideas would be greatly appreciated!
...
> Matt
Your strategy sounds pretty good. I don't think there's any reason to
check A:, B: or C:, as those are pretty much guaranteed to be floppies
and a hard drive. And you could put a file on just for the purpose of
this check, making it be something with a very unlikely name. To be
100% sure, make the file contents something you PGP, and verify it.
Other strategies could have problems if the user has more than one CDROM
drive, as I do, for example (I have trouble with install programs
picking up the wrong drive, even though they were started from the drive
with the CD in it).
--
Bob Walton
------------------------------
Date: Sun, 23 Sep 2001 21:35:44 +0100
From: Philip Taylor <philip@zaynar.demon.co.uk>
Subject: Re: locating cd drive
Message-Id: <tm31zFAgekr7EwKc@zaynar.demon.co.uk>
In article <Foqr7.517$aP1.287859@news20.bellglobal.com>, Matt Garrish
<matthew.garrish@sympatico.ca> writes
>I'm trying to write a search program that will read the contents of a CD and
>was wondering if anyone knows if there is an easier way to locate the drive
On Windows, try the Win32API::File module:
getLogicalDrives
@roots= getLogicalDrives()
Returns the paths to the root directories of all logical drives
currently defined. This includes all types of drive lettters, such as
floppies, CD-ROMs, hard disks, and network shares. A typical return
value on a poorly equipped computer would be ("A:\\","C:\\").
GetDriveType
$uDriveType= GetDriveType( $sRootPath )
Takes a string giving the path to the root directory of a file system
[called a ``drive'' because every file system is assigned a ``drive
letter''] and returns an unsigned value indicating the type of drive
the file system is on. The return value should be one of:
[...]
DRIVE_CDROM
A CD-ROM drive.
[...]
etc
--
Philip Taylor
philip @ zaynar . demon . co . uk
http://robowarriors.ultrastore.com/legoworld.shtml
-- If the Earth was made of Lego...
------------------------------
Date: Sun, 23 Sep 2001 21:34:16 GMT
From: ralph@primemail.com (Ralph Freshour)
Subject: Matching Strings Help Needed
Message-Id: <3bae5669.5610036@news-server>
I'm a bit confused here - I have two vars that should be comparing but
they are not:
if ($filtFilter eq $hAttachFileNames[$x])
{
# matches
}
else
{
# no match
}
I've stepped thru with the debugger and the string data are identical
and I even checked the string lengths - what am I missing here? There
is no match when there should be as far as I can see.
Thanks...
Ralph
------------------------------
Date: Sun, 23 Sep 2001 19:47:51 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: Me VS. Parsing
Message-Id: <Xns9125A0A52A46Drock13com@64.8.1.227>
Michael Lugassy
<news:342805fe.0109230459.54ff1605@posting.google.com>:
> Have anyone succesfuly managed to run a perl script that will
> parse the DMOZ dump data (over 800mb of RDF/XML formatted
> content)?
Are you an ODP editor? I'm assuming not. Editor nurey sticks the
RDF into a mySQL database regularly. As I recall he makes the
database available to other editors depending on their needs.
At any rate he has some items here: http://dmoz.nurey.net/
--
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/
------------------------------
Date: Sun, 23 Sep 2001 14:46:02 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: only allowing characters from a list to be inputed
Message-Id: <3BAE2DEA.556CAF92@earthlink.net>
Kiaya wrote:
>
> We have a cgi form that inputs to a pipe-delimited file. We want to
> prevent people from inputing symbols, hard returns, etc. which mess up
> the flat file.
Use Text::CSV_XS to read and write the file, and it will quote or escape
any funky characters in the data... then you won't have to limit what
the users enter.
But if you *do* want to limit, then try:
} elsif( $email =~ tr!-A-Za-z,.;'/@_ \t!!c ) {
Note: the - is at the beginning, otherwise it counts as a range. I used
exclamation point instead of / so I wouldn't have to escape the / in the
pattern. I added space and \t, cause I felt like it. I used the c flag
on the tr to complement [reverse] the pattern, so it looks for things
*not* in the pattern. And I put the binding operator as =~ so that it
means "if we find any character except a-z, etc, then it's bad"
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Sun, 23 Sep 2001 14:17:24 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Perl or not?
Message-Id: <3BAE2734.2070009@coppit.org>
Tom wrote:
> Perl is good, I love it, but it lacks the speed of compiled programs.
> Anyone got a good alternative?
Are you crunching lots of numbers? If so, C would be good. Even better,
use the Inline module to write the compute-intensive parts in C, and
write the rest in Perl. The best of both worlds!
Remember that it doesn't matter how fast your code is if it gives you
the wrong answer, or takes a long time to develop so that it does give
the right answer. For me, Perl is the fastest way to write code that
does the job. And my time is worth more than the $100 a faster CPU might
cost.
David
------------------------------
Date: 23 Sep 2001 14:43:59 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Perl or not?
Message-Id: <9ole1v$h6p$1@charity.cs.utexas.edu>
In article <m1u1xtvoyq.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Tom" == Tom <tom@zerofiveone.nosp@m.com> writes:
>
>Tom> Perl is good, I love it, but it lacks the speed of compiled programs.
>
>Perl *is* compiled. See the FAQ. Are you just quoting rumors, or
>do you have a specific counterexample?
Hmm. I think he means "compiled into native machine code". Which,
unless there is a JIT compiler for Perl that I don't know about, Perl
isn't. Correct?
- Logan
--
"Everybody
Loves to see
Justice done
On somebody else" ( Bruce Cockburn, "Justice", 1981 )
------------------------------
Date: 23 Sep 2001 18:07:06 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: perl, lvalues, rvalues, and operators
Message-Id: <9ol8ca$dme0c$2@fu-berlin.de>
Andrew Cady <please@no.spam> wrote:
> Tina Mueller <tinamue@zedat.fu-berlin.de> writes:
>> > Given a subroutine foo() that returns a string, I would like to
>> > call the routine, mangle the output, and print it in one swell
>> > foop:
>>
>> > print foo($arg, $notherarg) =~ s/regex/subst/;
>>
>> you can do:
>> print map {s/regex/subst/;$_} foo($arg, $notherarg);
> Funny, this works:
> $ perl -le ' sub f{return shift}; print map {tr/a/b/;$_} f("aaa") '
> bbb
yep. f() returns a scalar which is interpreted as a one-element
list (anonym, so the values will be changed without any effect.
> but not this:
> $ perl -le ' print map {tr/a/b/;$_} "aaa" '
> Modification of a read-only value attempted at -e line 1.
yeah, you're trying to change "aaa". but you can't change "aaa"
becauase it is no variable - just a sequence of characters.
try this:
perl -le ' print map {tr/a/b/;$_} @{["aaa"]}'
bbb
or this:
$ perl -le ' print map {tr/a/b/;$_} ["aaa"]->[0]'
bbb
here you make an anonymous variable out of "aaa". this works.
> One would think that one rvalue should be as good as another, and it
> seems (from perldoc -f map) that *neither* should work, as map
> supposedly makes $_ an "alias" to the list value, not a copy. But
> apparently it's willing to work on the copy made for the function
> call, even though other builtins demanding lvalues are not. Hm.
well, inside f() $_[0] is an alias for the argument, here "aaa".
but it returns $_[0], and a value returned from a sub is a new
anonymous variable, it's no alias any more (only if you return a reference
to something, that's a different case).
but in every case you're returning a list or a scalar, and then you're
assigning it to something or not. a scalar or a list returned from
a sub is always writeable. (hope i don't forget something here)
hth, tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Sun, 23 Sep 2001 16:16:56 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: pretty printing a web page
Message-Id: <3BAE4338.597734E4@earthlink.net>
Desrosiers, Benoit [CAR:9F53:EXCH] wrote:
>
> Thanks,
>
> but it's not enought. The main content on the page is a table. And
> some of its cells are multilines so I can't just print it sequentialy.
>
> If I use the print button on Netscape or on IE, I only get the left
> part of the page.
> What I would like is something that would reduce the size of what is
> being printed and fit it on one page.
Sounds like you need some kind of html2ps converter... that way you
could set some kind of parameter and get it the right size.
I don't know if there is such a program, and I'm not going to look...
but I will say that you might possibly get better results if you modify
the program which creates the page output either postscript directly, or
output latex, which you can convert to postscript with various tools.
Hmm... Here's a funky idea. What if someone made a module with the same
kind of interface as CGI.pm, but whose content generating functions
produce latex (or postscript, or [nt]roff) analogs of the html markup...
eg, start_html() would print a header for the beginning of a latex
document, table() would produce a latex table, hr() would be whatever
latex uses as a horitontal line, etc.
Any comments?
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Sun, 23 Sep 2001 17:28:08 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Problems with $ character
Message-Id: <3BAE53E8.EFE10411@earthlink.net>
JJ wrote:
>
> Hi,
>
> Problem 1.
> Step 1.1: I have a perl script that collects table names from a Oracle
> database.
> Step 1.2: In that script it then execute another perl script with the
> table as argument, that extracts the table (data and structure).
>
> The table name from step 1.1 can contain the character '$' such as
> 'MLOG$_WI_PISECTIONUS'. When executing the second script it says:
> "Table MLOG does not exist"
>
> Earlier when I executed those scripts on Linux it worked with the fix
> in the first script:
> $replace='\$';
> while(@row = $sth->fetchrow_array())
> {
> $tmp = $row[0];
> # fix the '$' in the table name if it exist
> $tmp =~ s/\$/$replace/g; ## <<<== The fix <<<<
> push @tables, $tmp;
> }
>
> # For each table, dump the data
> foreach $table ( @tables )
> {
> $outfile = "$dataDir$table$dumpFileExtension";
> print "Dumping table $table for schema $dbSchema\n";
> $command = "./oracledump_to_mySQL.pl --add-drop-table -u $dbSchema
> -p $password $database $table >> $outfile";
> system($command);
> }
Eww. Why do it like this? Surely dropping the table from within your
script would be better than calling an external program to do it...
my $dbh2 = DBI->connect( $dbSchema, '', $password, {RaiseError=>1} );
my $droptable = $dbi2->prepare(q[DROP TABLE ?]); # or whatever.
while( my ($tablename) = $sth->fetchrow_array ) {
$droptable->execute( $tablename );
}
> Now when have moved it to Solaris this doesn't work.
> Why?
Probably a different shell. You would be better off not calling any
external commands, and doing it all in one script.
>
> Problem 2:
> I also need to execute a system command '. $SOEORA_SETUP dtim1t' but
> here is the '$' character again and it doesn't work.
There's probably two problems. The first is likely that you're using ""
to quote the command [it should be '' instead]. The second problem you
will see, once you fix the first, is that you're calling a shell script
whose purpose is to change the shell environment. system() creates a
new shell, runs the $SEORA_SETUP program within that shell, and then the
shell exits.
> How can I solve this and execute it in my Perl script?
foreach( qx'. $SOEORA_SETUP dtim1t 1>&2; /bin/env' ) {
chomp;
(my ($key, $val) = split /=/, $_, 2) == 2 or next;
$ENV{$key} = $val if !defined $ENV{$key};
}
Or:
foreach( qx". $ENV{SOEORA_SETUP} dtim1t 1>&2; /bin/env" ) {
etc. In this version, just about any delimiter, not just "", may be
used. So it could be qx// or qx[] etc.. In this case, the variable
interpolation will end up being done by perl, not by the shell.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Sun, 23 Sep 2001 14:34:25 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: regex needed
Message-Id: <3BAE2B31.6D8A77A9@earthlink.net>
Dave Tweed wrote:
>
> [mailed and posted]
>
> peter wrote:
> > i need to scan any number of files to find patterns similar to the
> > following:
> >
> > (set! glErrorParameters (list (string-append "Stored
> > Procedure Name= " (get ~input%etd_Event_Tri
> > gger_Out.payload)) (string-append "Oracle Error= " (db-get-error-str
> > connection-handle))))^M
> >
> > the string i key off now is "set! glErrorParameter" but that doesnt get
> > me the whole pattern acroos multiple lines i need to match. what i need
> > is to match the first, opening paren to the left of the set! command and
> > then match to the corresponding, closing paren. please provide a regex
> > to accomplish this task.
>
> A regex alone cannot handle the general problem of delimiter matching.
> You're going to have to actually parse the string. One place to start
> is Text::DelimMatch.
Yes and no. A 'true' regular expression cannot handle the general
problem of delimiter matching, but perl's regexes aren't truly regular.
my $re; $re = qr/^
((?>[^()]*\([^()]*)) # a left paren [and surrounding stuff]
(??{ $re }) # a subexpression, possibly parenthesised.
((?>[^()]*\)[^()]*)) # a left paren [and surrounding stuff]
| ((?>[^()]*))
\z/x;
my @stuff = $string_with_nested_parens =~ /$re/;
For that matter, you can generate an R.E. from the string and let perl's
expression compiler do the work for you [this will work even in other
kinds applications, not just perl.... even ones which are limited to
true regular expressions, the type which can be compiled to a DFA]
my $the_string = q[
(set! glErrorParameters (list
(string-append "Stored Procedure Name= "
(get ~input%etd_Event_Trigger_Out.payload))
(string-append "Oracle Error= "
(db-get-error-str connection-handle))))
];
(my $re = $the_string) =~ s/([^()]+)/\Q$1\E/g;
my @stuff = $the_string =~ /$re/;
# at this point, @+ and @- tell where the nested thingies begin and end.
Of course, all this doesn't mean that REs are the best way to handle
this problem. You'd likely be much better off using Text::Balanced than
trying to write your own code for it.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Sun, 23 Sep 2001 19:55:11 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: Setting cookies
Message-Id: <Xns9125A1E339764rock13com@64.8.1.227>
Marshall Dudley <news:3BAE11F6.572D172B@execonn.com>:
> I am unable to set a cookie using a perl script. This is the
> script:
> print "Set-Cookie: AFFILIATE=$affiliate; ";
> print "expires=$expdate; " if ($expires);
> print "domain=www.king-cart.com; "; #works if I
> leave this line
> out
> print "path=/; \n";
>
> If I leave out the domain line, it will set cookies fine.
> Why will Netscape NOT set the cookie when I specify a domain I
> want the cookie availabe from?
Sounds like, perhaps, NN is rejecting cookies that are not returned
to the domain they're set from. That is, if you are not testing the
script when its installed on king-cart.com it will fail.
--
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/
------------------------------
Date: Sun, 23 Sep 2001 20:29:52 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Simple question
Message-Id: <9ol9d2$vg7$06$1@news.t-online.com>
"bob" <bob@offend.org> schrieb im Newsbeitrag
news:tqo01jtjl2bg7a@corp.supernews.com...
> no need to get your panties in a twist over it...
>
>
> <nobull@mail.com> wrote in message news:u9hetwecxi.fsf@wcl-l.bham.ac.uk...
> > mauroid@csi.forth.gr (Dimitri) writes:
[snip complaints]
learn.to/quote
Steffen
------------------------------
Date: Sun, 23 Sep 2001 16:39:45 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Socket server closing itself when client disconnects.
Message-Id: <3BAE4891.D81EB808@earthlink.net>
Stuart Allen wrote:
>
> Hello
>
> I have a socket server written in perl that forks on each incomming
> connection. The problem that I am having is that when the client (an
> applet) disconnects (ie, the use closes their browser window), the
> forked process doesn't close.
The forked process will only exit when you tell it to exit.
> The condensed server code is below. I am presuming that the while(1)
> bit could be changed to some sort of test, but so far nothing I have
> tried seems to have achieved the desired effect.
You need to test that the Client socket is still valid. You can't just
use eof(Client) to test it, since that tries to *read* from the
socket... and there won't [shouldn't] be anything coming from the
client. Thus, you should test if the print succeeds.
> while (accept(Client, Server)) {
> if ($childpid = fork) {
> close Client; # parent closes unused handle
> next REQUEST;
> }
> defined ($childpid) or die "cannot fork: $!\n";
>
> close Server; # child closed unused handle;
>
> select (Client); # new default for prints
> $| = 1; # enable autoflush
> while (1) {
> print "hello\r\n";
> sleep(10);
> }
while( print "hello\015\012" ) {
sleep 10;
}
> close Client;
> exit;
> }
However, I must admit, one thing confuses me. Printing to a closed
socket *should* [I think] result in a SIGPIPE being raised, which
[unless you have a signal handler installed to catch and ignore it]
would then kill the child process.
I would guess that when the user closes the browser window, the applet
within it continues to run, instead of stopping and closing the socket
as it should. If that's so, you've a java problem, not a perl problem.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Sun, 23 Sep 2001 15:54:41 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sorting Hashes
Message-Id: <3BAE3E01.8E237010@earthlink.net>
Michael J. Vincent wrote:
>
> perl guru's,
>
> I have a hash whose index is IP addresses and value is the
> number of times the IP address appears in a file. I'd like to print
> output sorted by the most occurances to the least and secondary sorted
> on the increasing IP address.
>
> An example:
>
> $hash{172.16.5.1} = 5
> $hash{172.16.5.2} = 5
> $hash{172.16.5.3} = 7
> $hash{172.16.6.1} = 10
> $hash{172.16.7.1} = 2
>
> I would like the output to be:
>
> 10 172.16.6.1
> 7 172.16.5.3
> 5 172.16.5.1
> 5 172.16.5.2
> 2 172.16.7.1
my %hash = qw(
172.16.5.1 5
172.16.5.2 5
172.16.5.3 7
172.16.6.1 10
172.16.7.1 2);
# here's an ST
printf " %3d x %d.%d.%d.%d\n", $_->[0], unpack "c4", $_->[1]
for sort { $b->[0] <=> $a->[0] or $a->[1] cmp $b->[1] }
map [ $hash{$_}, pack "c4", /\d+/g ], keys %hash;
# here's a GRT
for( sort map pack("nc4", -$hash{$_}, /\d+/g), keys %hash ) {
my ($cnt, @ip) = unpack "nc4", $_;
printf " %3d x %d.%d.%d.%d\n", -$cnt, @ip;
}
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Sun, 23 Sep 2001 17:38:10 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Unusual error message...
Message-Id: <3BAE5642.53FE388A@earthlink.net>
Ilmari Karonen wrote:
[snip]
> The "EXPR for LIST;" syntax was introduced in perl 5.005. It
> is exactly equivalent to "for (LIST) {EXPR}",
Not *exactly* equivilant... it doesn't introduce a new scope.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
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 1796
***************************************