[15551] in Perl-Users-Digest
Perl-Users Digest, Issue: 2964 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 5 21:05:25 2000
Date: Fri, 5 May 2000 18:05:12 -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: <957575112-v9-i2964@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 5 May 2000 Volume: 9 Number: 2964
Today's topics:
Re: $[ causing problems down the line <Jonathan.L.Ericson@jpl.nasa.gov>
associating a filename with a FileHandle <lancon@mail.ce.utexas.edu>
Best way to search multiple files for multiple expressi timhood@my-deja.com
Re: CHECKING FORM DATA FOR NUMERIC DATA <lr@hpl.hp.com>
Re: Color under MSDOS/NT <Jonathan.L.Ericson@jpl.nasa.gov>
Re: Context in examples (was: LWP POST syntax @{@$%??}) <rootbeer@redcat.com>
date manipulations/library <rloebusenet@cticonsulting.net>
Re: date manipulations/library <rootbeer@redcat.com>
Re: DIRHANDLE problems <rootbeer@redcat.com>
Re: gethostbyaddre: Address family not supported by pro <s1dugan@exnet.iastate.edu>
Re: gethostbyaddre: Address family not supported by pro <lr@hpl.hp.com>
Re: help about NDBM_File and tie <rootbeer@redcat.com>
Re: how do I replace all html tags <rootbeer@redcat.com>
Re: how do I replace all html tags (Tad McClellan)
Re: How single-line switch (/s) works in regexps? <lr@hpl.hp.com>
IO::Socket keep alive problem <webmaster@urpsearch.com>
Re: IO::Socket keep alive problem <rootbeer@redcat.com>
Re: mystery: perl -e '<>;<>' (Alan Curry)
Re: parsing input to confirm a valid e-mail address <nospam@devnull.com>
Re: Passing DBI Connection between Processes? reedjd@bitsmart.com
Re: Perl Lazy Matching <lr@hpl.hp.com>
Re: problem with "system" and file copy <Petri_member@newsguy.com>
Re: problem with "system" and file copy <rootbeer@redcat.com>
Re: Reading delimited file into hash <rootbeer@redcat.com>
Re: Reading delimited file into hash <sumus@aut.dk>
Re: Real and Windows streaming media access? <rootbeer@redcat.com>
Re: regex question (Tad McClellan)
seeking a more elegant grouping algorithm than this ... (Eric Smith)
Re: Should a class that exports no symbols provide an e (M.J.T. Guy)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 05 May 2000 16:25:42 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: $[ causing problems down the line
Message-Id: <39135876.66AF3FC7@jpl.nasa.gov>
Mike Mulvaney wrote:
> I've done some more investigating, and now I am more confused.
Although it may not eleviate all of your confusion, read perlfunc/'use',
perlfunc/'require', perlmod and the Exporter documentation.
> (I know I can fix this by using local(). but I have a lot of scripts
> that use this module, and I need to know which ones rely on $[ being
> 1. In order to figure that out, I need to understand why setting $[
> affects other files when the docs say that it shouldn't.)
Here is a less confusing test case:
$ cat BadIdea.pm
$[ = 1;
1;
$ cat temp.pl
#!/usr/bin/perl -w
use strict;
require BadIdea;
my @array = ("Doesn\'t work :(\n", "Works!\n");
print $array[1];
$ temp.pl
Works!
$ cat temp.pl
#!/usr/bin/perl -w
use strict;
BEGIN{require BadIdea;};
my @array = ("Doesn\'t work :(\n", "Works!\n");
print $array[1];
$ temp.pl
Doesn't work :(
Quoting from perlvar:
As of Perl 5, assignment to "$[" is treated as a compiler
directive, and cannot influence the behavior of any other file.
Its use is discouraged.
As far as I can make out, if you 'require' a file that sets $[ _before_
you compile the rest of the script (i.e., in a BEGIN block), assiment to
$[ _will_ influence the behavior of the other file. That's what perlvar
means when it says that assignment to $[ is treater as a "compiler
directive". This is the same sort of behaviour as strict.pm:
$ perl -e 'use strict;$foo=qq(strict not in effect\n);print $foo'
Global symbol "$foo" requires explicit package name at -e line 1.
Global symbol "$foo" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.
$ perl -e 'require strict;$foo=qq(strict not in effect\n);print $foo'
strict not in effect
Once again, making $[ local is the quick-and-dirty solution. In the
long run, you should probably fix the scripts to use the standard value
of $[.
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Fri, 05 May 2000 19:03:17 -0500
From: Donald Lancon <lancon@mail.ce.utexas.edu>
Subject: associating a filename with a FileHandle
Message-Id: <39136145.BA1156AF@mail.ce.utexas.edu>
Since a FileHandle object is just an anonymous glob, you should be able
to use its hash member however you want, right?
In particular, you could store the filename for an opened FileHandle in
the hash and it would be passed around with the FileHandle:
use FileHandle;
sub name {
my $FH = shift;
my $FN = shift;
$$FH->{filename} = $FN;
}
sub name_of {
my $FH = shift;
$$FH->{filename};
}
my $fn = "filename.ext";
my $fh = new FileHandle $fn, "<";
name($fh, $fn);
print name_of($fh); # filename.ext
Are there any caveats with this approach? Is the hash already being
used in any way?
Why isn't this discussed anywhere in the documentation? (Or is it?)
--
Donald Lancon
------------------------------
Date: Fri, 05 May 2000 22:51:10 GMT
From: timhood@my-deja.com
Subject: Best way to search multiple files for multiple expressions?
Message-Id: <8evj8q$lm$1@nnrp1.deja.com>
I have a file with a list of items in it. (Let's call it file_a). I also
have a directory with a bunch of files. I want to look at each file in
the directory to see if any of the items listed in file_a appear in the
file, and if so, report the file name and the item name.
My approach was to open the file to be read, and for each line in that
file, open the item list (file_a) and do an index search like this:
$found_it = index $_, $item;
The process works fine, except that due to the large number of items in
my (file_a) list (more than 3300), and the large number of files to
parse (more than 4800), it takes a long time to complete.
I tried some code from the FAQ file like this:
sub _bm_build {
my $condition = shift;
my @regexp = @_; # this MUST not be local(); need my()
my $expr = join $condition => map { "m/\$regexp[$_]/o" }
(0..$#regexp);
my $match_func = eval "sub { $expr }";
die if $@; # propagate $@; this shouldn't happen!
return $match_func;
}
sub bm_or { _bm_build('||', @_) }
$f2 = bm_or qw{
item1
item2
item3
.
.
item3300};
while ( <> ) {
print "Found: $_" if &$f2;
}
exit;
The problem is when I ran this against a test file (redirected from
standard input, it appeared to erroneously match every line of the
scanned file. This, as opposed to only a few lines matching when run
against my first script.
Is the large number of items loaded into $f2 causing problems, or am I
missing something else?
Thanks for the help.
Tim
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 5 May 2000 15:17:24 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: CHECKING FORM DATA FOR NUMERIC DATA
Message-Id: <MPG.137ce8511a26af5a98aa0f@nntp.hpl.hp.com>
[Using all capital letters in your subject means that many who otherwise
might answer won't even see your question, because their newsreaders
will have filtered it out. In this case, maybe that's all to the good.
:-]
In article <8evbso$ob6$1@nnrp1.deja.com> on Fri, 05 May 2000 20:45:16
GMT, linux4all@yahoo.com <linux4all@yahoo.com> says...
> With Perl, how can I check a string from a form submission to make sure
> that the string contains *only* digits and zero or one period (decimal
> point).
...
> I assume that by using a regular expression I'm going about this the
> right way. Please tell me if I'm way off base.
>
> Isn't this a popular task in Perl? That is, checking for good input
> data. Aren't there any functions or well-documented subroutines?
Yes, it is so popular a task in Perl that how to do it is a Frequently
Asked Question (at least, it is a Question Asked Frequently by those who
don't read the documentation before asking).
perlfaq4: "How do I determine whether a scalar is a
number/whole/integer/float?"
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 05 May 2000 17:36:40 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Color under MSDOS/NT
Message-Id: <39136918.3A2A1F9@jpl.nasa.gov>
Aurelien wrote:
> I have a problem to have color under MS-DOS (Windows NT). I have installed
> ActivePerl with PPM. I have installed the Termios-ANSIColor module and when
> I run my script I don't have color but I have the colors codes. What can I
> do to have color ?
From Windows NT Help:
Device--Example
To use an ANSI escape sequence to control the
screen and keyboard for the MS-DOS subsystem,
add the following command to your CONFIG.NT or
equivalent startup file:
device=c:\winnt\system32\ansi.sys
(Contents|Windows NT Commands|Device)
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Fri, 5 May 2000 16:33:11 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Context in examples (was: LWP POST syntax @{@$%??})
Message-Id: <Pine.GSO.4.10.10005051627230.6766-100000@user2.teleport.com>
On 5 May 2000 nobull@mail.com wrote:
> Tom Phoenix <rootbeer@redcat.com> writes:
>
> > If you're still stuck, cut your code down to just one or two lines
> > which aren't doing what you want, perhaps along with a couple of
> > additional lines for context.
>
> In general this is not the best advice. Experience (and common sense)
> shows that the person who doesn't understand what's going on is not
> best suited to judge how much context is required to understand what
> is going on.
You may be right.
> Normally I wouldn't bother to criticise but since Tom gives such
> prolific advice to newbies I think it is important that he should be
> giving optimal advice.
I don't think the quantity of my advice is relevent here. If this were the
only answer I ever posted to Usenet, it would be just as important that I
give optimal advice.
Unless, of course, you mean by that that you expect me to post further
advice - a reasonable expectation! - and you'd like me to improve it. But
if you meant that, I'm sure that you would have used my e-mail address to
contact me privately.
> Cut code down to the smallest script that compiles and runs without
> warnings under "use strict" and illustrates the lines not doing what
> is wanted. Often the process of doing this will enable you to find
> the problem yourself.
>
> If the small script is less than a few dozen lines then post it in its
> entirity. If it's still big then post only the bits you think are
> important and give a URL where the whole thing can be found.
Well, that's a little longer than what I said.
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 05 May 2000 18:33:34 -0500
From: Randon Loeb <rloebusenet@cticonsulting.net>
Subject: date manipulations/library
Message-Id: <39135A4E.B63E514D@cticonsulting.net>
I am looking for a library that will do things like allow me to add and
subtract days from a given date, giving me the new date. It would take
into account # of days in each month, etc.. Most languages have some
function called dateserial, something like this. I'm finding hard to
explain, if you understand and have an answer please email me.
Thanks,
--
Randon Loeb
CTI Consulting and Training
rloeb@cticonsulting.net
954-971-6888
DO NOT ADD THIS ADDRESS TO ANY JOKE LISTS OR OTHER LISTS
------------------------------
Date: Fri, 5 May 2000 16:24:34 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: date manipulations/library
Message-Id: <Pine.GSO.4.10.10005051624140.6766-100000@user2.teleport.com>
On Fri, 5 May 2000, Randon Loeb wrote:
> I am looking for a library that will do things like allow me to add
> and subtract days from a given date, giving me the new date. It would
> take into account # of days in each month, etc..
If there's a module which does what you want, it should be listed in
the module list on CPAN. If you don't find one to your liking, you're
welcome and encouraged to submit one! :-) Hope this helps!
http://search.cpan.org/
http://www.cpan.org/
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 5 May 2000 17:36:13 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: DIRHANDLE problems
Message-Id: <Pine.GSO.4.10.10005051729571.6766-100000@user2.teleport.com>
On Fri, 5 May 2000, Daniel Berger wrote:
> whenever I change directories (via win32dirselect - which is
> why I'm posting in the tk newsgroup), I can no longer read the
> files in the (new) current directory.
If you change files with chdir(), do you see the same thing?
> In other words, I no longer get a return value from
> 'telldir DIRHANDLE'. I've tried various permutations
> of rewinddir and seekdir, all to no avail.
If you get no return value, that's telling you something. :-)
> $cwd = cwd;
> opendir(DIRHANDLE, "$cwd") || die "\nCouldn't open directory : $!";
Those first double-quote marks are merely misleading. But why not simply
use '.' as the directory name? Should be faster and more reliable, unless
you need the directory's full name - which, I suspect, you might. :-)
> while(defined ( $fileName = readdir (DIRHANDLE) ) ){
> if( -f "$fileName" ){
Now, if you change directory somewhere while this while loop is running,
there's your problem. You're looking for $filename in one directory, but
it's really in another. Is that it?
> open(FILE, "$fileName") || die "\nUnable to open file $filename :
> $!";
> $curDir = telldir DIRHANDLE;
> print "\n$curDir";
It's unusual to do anything with the return value of telldir other than
save it to pass back to seekdir later. But there's no law against printing
it. :-) (Still, if you'll be using it much later, remember that the
directory's contents may have changed, making it invalid.)
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 5 May 2000 17:21:12 -0500
From: "Darin Dugan" <s1dugan@exnet.iastate.edu>
Subject: Re: gethostbyaddre: Address family not supported by protocol
Message-Id: <8evhgn$jr4$1@news.iastate.edu>
Oops.. Works much better with quotes around the IP address:
...inet_aton("129.186.107.10").....
"Darin Dugan" <s1dugan@exnet.iastate.edu> wrote in message
news:8evfh1$jl3$1@news.iastate.edu...
> Can anyone point out what could be wrong with my setup here?
>
> perl -e 'use Socket; $name = gethostbyaddr(inet_aton(129.186.107.10),
> AF_INET) || die "Dying: $!"; print "\n$name\n";'
> Dying: Address family not supported by protocol at -e line 1.
>
> #uname -a
> Linux www 2.2.13 #7 Tue Apr 4 09:33:39 CDT 2000 i686 unknown
> #perl -v
> This is perl, v5.6.0 built for i686-linux
> --
> Darin Dugan
> s1dugan(at)exnet(dot)iastate(dot)edu
>
------------------------------
Date: Fri, 5 May 2000 16:26:47 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: gethostbyaddre: Address family not supported by protocol
Message-Id: <MPG.137cf896d32b74c998aa12@nntp.hpl.hp.com>
In article <8evfh1$jl3$1@news.iastate.edu> on Fri, 5 May 2000 16:47:13 -
0500, Darin Dugan <s1dugan@exnet.iastate.edu> says...
> Can anyone point out what could be wrong with my setup here?
>
> perl -e 'use Socket; $name = gethostbyaddr(inet_aton(129.186.107.10),
> AF_INET) || die "Dying: $!"; print "\n$name\n";'
> Dying: Address family not supported by protocol at -e line 1.
>
> #uname -a
> Linux www 2.2.13 #7 Tue Apr 4 09:33:39 CDT 2000 i686 unknown
>
> #perl -v
> This is perl, v5.6.0 built for i686-linux
I tried it with my own IP address, and it resolved fine. I got
different errors for your address using gethostbyaddr or nslookup.
Note for the unwary:
Before perl 5.6.0, that argument would be the decimal number
129186.10710 !
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 5 May 2000 17:07:54 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: help about NDBM_File and tie
Message-Id: <Pine.GSO.4.10.10005051659160.6766-100000@user2.teleport.com>
On Thu, 4 May 2000, Federico Abascal wrote:
> I don't find documentation about perl's NDBM_File module.
> I only find examples like this:
> tie(%hash, 'NDBM_File', './nueva.dbx', O_RDWR|O_CREAT, 0640);
You're right, it's kind of skimpy. But if you follow the other things it
suggests you read, and the other things suggested there, you should start
to get a better picture of the way it works. (Still, patches to improve
the docs are always needed.)
> but I would like to know what do the parameters mean, what can I do
> with them. (I want to store hashes at files)
Well, the O_ constants are described in the perlopentut manpage. Is that
the parameter you didn't understand?
> Another question I have is why there are so many *DBM* modules, is some
> of them better to store hashes at files?
Yes, depending upon what you mean by "better". See the AnyDBM_File manpage
for a discussion of the different types; it'll also answer some of your
questions from above.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 5 May 2000 16:20:54 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: how do I replace all html tags
Message-Id: <Pine.GSO.4.10.10005051619310.6766-100000@user2.teleport.com>
On Fri, 5 May 2000, Ala Qumsieh wrote:
> $line =~ s/<[^>]+>/< >/g;
Don't try to parse HTML using such simple regular expressions.
<img src= "arrow.gif" alt= "==>" >
Use HTML::Parser or equally-good parsing code instead. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 5 May 2000 18:50:52 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how do I replace all html tags
Message-Id: <slrn8h6k2c.66f.tadmc@magna.metronet.com>
On Fri, 05 May 2000 14:43:25 -0700, skye <szovakNOszSPAM@hotmail.com.invalid> wrote:
>I was wondering it anyone had any ideas of
>how to remove all HMTL tags while leaving all other text
>behind.
Everybody who checks the Perl FAQ before posting to
the Perl newsgroups has ideas about that:
perldoc -q HTML
"How do I remove HTML from a string?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 5 May 2000 16:06:46 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How single-line switch (/s) works in regexps?
Message-Id: <MPG.137cf3dff120bc1798aa11@nntp.hpl.hp.com>
In article <u9pur16wmn.fsf@wcl-l.bham.ac.uk> on 05 May 2000 12:53:52
+0100, nobull@mail.com <nobull@mail.com> says...
+ Larry Rosler <lr@hpl.hp.com> writes:
+
+ > In article <u9ya5qfrmr.fsf@wcl-l.bham.ac.uk> on 04 May 2000 13:04:44
+ > +0100, nobull@mail.com <nobull@mail.com> says...
+ >
+ > ...
+ >
+ > > Given a prefix of string and a pattern is it possible to test if
+ > > is necessary to read in more to know if (or what) the pattern will
+ > > match in that prefix.
+ > >
+ > > eg.
+ > >
+ > > ("foo" . $unread) =~ /f/ # Matches
+ > > ("foo" . $unread) =~ /o+/ # Matches but we dont know how many
+ > > ("foo" . $unread) =~ /od/ # Don't know if is maches
+ > > ("foo" . $unread) =~ /d/ # Doesn't match
+ >
+ > Your example code bears little relation to your question.
+
+ It's not code, it's pseudo-code using the syntax of Perl. This should
+ be blantently obvious since I'm taking about something that AFAIK
+ can't be done in Perl. We are for ever telling people to write
+ pseudo-code following Perl syntax.
Then label it 'PSEUDO-CODE FOLLOWING Perl SYNTAX'. It looks just like
real Perl to me.
+ > In these examples, the scalar to be matched is computed by
+ > concatenation before the matching operation is begun.
+
+ You are just deliberately pretending to dense, please stop it. I know
+ you are not relly that dense. I _know_ Perl does not have lazy
+ evaluation in this situation, what I'm asking is if there is some why
+ to fake it.
I am so really that dense. I think I finally grasped what you are
after, because of your further explanation below.
+ > Perhaps what you mean is something like this:
+
+ No I really mean what I said.
+
+ Given a prefix of string and a pattern is it possible to test if is
+ necessary to read in more to know if (or what) the pattern will match
+ in that prefix.
What does 'prefix of string' mean? What does 'match in that prefix'
mean?
+ If you find the previous pseudo-code un-helpful then try this actual
+ code:
+
+ need_more("foo", qr/f/) # Matches => false
+ need_more("foo", qr/o+/) # Matches but we dont know how many => true
+ need_more("foo", qr/od/) # Don't know if is maches => true
+ need_more("foo", qr/d/) # Doesn't match => false
+
+ So my question is can we construct the need_more() function using
+ Perl?
Ah, this is gnarly! You are asking whether a *trailing* portion of a
string matches a *leading* portion of a regex, and there is more to the
regex that might be matched by the *leading* part of some arbitrary
other string. Whew!
I can't imagine how to do this, other than by dissecting the regex atom
by atom and matching it against the original string and analyzing what
is left in the regex. You can't have a regex on the left side of a
match:
/foo.+/s =~ /od/
That is valid but rather silly Perl:
($_ =~ /foo.+/s ? "1" : "") =~ /od
But maybe someone else can figure it out now.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 6 May 2000 00:33:24 +0200
From: "Erwin de Villeneuve" <webmaster@urpsearch.com>
Subject: IO::Socket keep alive problem
Message-Id: <39134c9c$0$12376@reader1.casema.net>
Hi everyone!
I'm writing a perl script which connects to a server (http protocol) and has
to keep a connection to the server.. A few requests should be made, but for
the second request I need the information from the first request and so on.
I use IO::Socket::INET, but I can't get the received information before I
closed the connection. Does anybody know how to get this working?
Erwin de Villeneuve
------------------------------
Date: Fri, 5 May 2000 17:12:13 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: IO::Socket keep alive problem
Message-Id: <Pine.GSO.4.10.10005051708420.6766-100000@user2.teleport.com>
On Sat, 6 May 2000, Erwin de Villeneuve wrote:
> I'm writing a perl script which connects to a server (http protocol)
> and has to keep a connection to the server.. A few requests should be
> made, but for the second request I need the information from the first
> request and so on. I use IO::Socket::INET,
Wouldn't LWP do what you need, and much more easily?
> but I can't get the received information before I closed the
> connection.
That sounds as if the remote machine isn't flushing output when you wish
it would, although I can't be sure.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sat, 06 May 2000 00:40:28 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: mystery: perl -e '<>;<>'
Message-Id: <0SJQ4.11020$UF3.10183783@news-east.usenetserver.com>
In article <8evf7u$s72$1@nnrp1.deja.com>,
Daniel Pfeiffer <occitan@esperanto.org> wrote:
>Hi!
>
>when I execute the above programme it waits for two lines of input, at
>least a newline each. Now, when I close the file by typing ^D, on the
>first <>, it sure enough returns the empty string. But the second <>
>again manages to read on that filehandle, even though it had already
>reached eof!
>
>How can this be? Does Perl somehow reopen the filehandle, or at least
>reset its eof-reached-state?
EOF on a tty (generated with ^D) is not a state at all. You type ^D once, you
get EOF once. If you want different behavior, you need to maintain the EOF
state with a flag in your program.
You could make it completely transparent with a tied filehandle, and make a
"StickyEOF.pm" that reassigns STDIN/STDOUT/STDERR on startup and replaces
main::open with a wrapper that makes all new filehandles stickyeof'ed.
But maybe it would be simpler to revise your expectations of what happens
when you hit ^D
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: 5 May 2000 22:26:24 GMT
From: The WebDragon <nospam@devnull.com>
Subject: Re: parsing input to confirm a valid e-mail address
Message-Id: <8evhqg$gqn$1@216.155.33.26>
In article <MPG.137cd7086b25209398aa0d@nntp.hpl.hp.com>, Larry Rosler
<lr@hpl.hp.com> wrote:
| In article <8ev7bt$qfk$2@216.155.33.10> on 5 May 2000 19:27:57 GMT, The
| WebDragon <nospam@devnull.com> says...
| > is there a way to
| >
| > simple:
| > . confirm that an e-mail address entered is in fact a simple e-mail
| > address (and doesn't contain 'funny' chars or multiple '@'s), and if
| > not, set the variable to an error message like "!!Invalid E-mail
| > Address!!"
| >
| > complex:
| > . verify that selfsame e-mail address is a *valid* one, i.e. stands
| > the
| > chance of actually existing as a working address.
|
| perlfaq9: "How do I check a valid mail address?"
doh! *smacks forehead* :D
thanks. :)
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Sat, 06 May 2000 00:43:07 GMT
From: reedjd@bitsmart.com
Subject: Re: Passing DBI Connection between Processes?
Message-Id: <8evpqp$7fn$1@nnrp1.deja.com>
This sounds like a good plan for my CGI stuff, but that's only about
half of the perl process accessing the database. There are a bunch
of "engines" that also access it. Anyway they can grab the DB
connection?
-jr
In article <390E2B9D.5A8EC8BF@My-Deja.com>,
Makarand Kulkarni <makarand_kulkarni@My-Deja.com> wrote:
> > How would I do it?
>
> (a)have a mod_perl enabled web server and use Apache::DBI
> (b) or FastCGI
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 5 May 2000 15:08:34 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Perl Lazy Matching
Message-Id: <MPG.137ce63aecc1605798aa0e@nntp.hpl.hp.com>
In article <8ev904$kv9$1@nnrp1.deja.com> on Fri, 05 May 2000 19:55:57
GMT, edlong@yahoo.com <edlong@yahoo.com> says...
> The crux of the question, is there are multiple variables in my hash
> that start similiar
> (ie: ab, abc, abcd). And there are sections of text that I want to
> replace
> (ie: "This ab, is abc, the next abcd") And Perl picks up the first ab
> and replaces it with the ab replacement, but I want Perl to match the
> WHOLE string and replace the whole string with the correct replacement.
[You have very odd line breaks. Please check your line wrapping and set
it to 72 characters.]
...
> (Note: I don't think I can use ^ and $, because (I tried it) and these
> string are anywhere in the text.
In all likelihood, what you want to use to delimit the match are the
word-boundary assersions, \b, at each end. See perlre for details. But
I don't think you want a regex match at all. See below.
> Example:
>
> %myhash = ("[ec_order_header].sold_to_member_name","getSoldToMemberName
> ()","[ec_order_header].sold_to","getSoldTo()");
my %myhash = (
'[ec_order_header].sold_to_member_name' =>
'getSoldToMemberName()',
'[ec_order_header].sold_to' => 'getSoldTo()',
);
Isn't that a lot clearer?
> $tmpstr ='<Name xml:lang="en">
> [ec_order_header].sold_to_member_name</Name>';
>
> foreach $k (keys %myhash)
> {
> $currkey = quotemeta $k;
> #print "CURRKEY: $currkey\n";
If this is commented out, the code doesn't do what you says, does it?
That casts doubt on the rest of it.
> ($tableid,$rest) = split("\\.",$k);
my ($tableid, $rest) = split(/\./, $k);
> $prefix = $prefixhash{$tableid};
> print ("CURRKEY: $currkey\nTABLEID: $tableid\nPREFIX:
> $prefix\nHASH: $prefixhash{$tableid}\n");
This $prefixhash{$tableid} stuff clutters your question, and should have
been edited away before posting.
> $tmpstr =~ s/$currkey/\<\%=$prefix$myhash{$k}\%\>/g;
$tmpstr =~ s/\b$currkey\b/<%=$prefix$myhash{$k}%>/g;
Or, putting the quotemeta here where it is needed:
$tmpstr =~ s/\b\Q$currkey\E\b/<%=$prefix$myhash{$k}%>/g;
If you have matched and made the substitution, you should be done. But
you continue to loop over the remaining keys. Each one has to be
compiled into a regex, and if you do this in a loop over data it will
take a very long time.
The approach is faulty. You should isolate the entire part that might
be the key, and just look it up in the hash. No loop searching the
keys. See below.
> }
>
> print $tmpstr;
>
> This prints:
> CURRKEY: \[ec_order_header\]\.sold_to
> TABLEID: [ec_order_header]
> PREFIX: oh.
> HASH: oh.
> CURRKEY: \[ec_order_header\]\.sold_to_member_name
> TABLEID: [ec_order_header]
> PREFIX: oh.
> HASH: oh.
> <Name xml:lang="en"><%=oh.getSoldTo()%>_member_name</Name>
>
> Notice how it just grabed "Sold_to" but not the rest.
I think your whole example can be reduced to this:
if ($tmpstr =~ />([^<]+)/ && $myhash{$1}) {
... do whatever you want to $tmpstr ...
}
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 5 May 2000 15:54:56 -0700
From: Petri Oksanen <Petri_member@newsguy.com>
Subject: Re: problem with "system" and file copy
Message-Id: <8evjg0$28a6@edrn.newsguy.com>
In article <Pine.GSO.4.10.10005050917470.6766-100000@user2.teleport.com>, Tom
says...
>> His problem is that he forgot to put $command inside quotes:
>> $rc = system("$command");
>You seem to be mistaken. The quote marks in that statement are merely
>misleading. Cheers!
Perhaps you can explain to me then why these work:
perl -we "system(\"echo Works fine on Win32\");"
perl -we 'system("echo Works fine on *ix");'
Exactly where am I wrong?
In the original code, this _works_:
system("$command");
This _doesn't_:
system($command);
Petri Oksanen
------------------------------
Date: Fri, 5 May 2000 17:22:53 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: problem with "system" and file copy
Message-Id: <Pine.GSO.4.10.10005051714000.6766-100000@user2.teleport.com>
On 5 May 2000, Petri Oksanen wrote:
> >> His problem is that he forgot to put $command inside quotes:
> >> $rc = system("$command");
>
> >You seem to be mistaken. The quote marks in that statement are merely
> >misleading. Cheers!
>
> Perhaps you can explain to me then why these work:
>
> perl -we "system(\"echo Works fine on Win32\");"
> perl -we 'system("echo Works fine on *ix");'
The quote marks in those lines are _not_ merely misleading. :-) I stand
by my earlier statement, though.
> In the original code, this _works_:
> system("$command");
>
> This _doesn't_:
> system($command);
Unless there's more to the picture than you're showing us, you're still
mistaken. The relevant part of the original code looks like this:
$command = "cp ~/dir1/*.c ~dir2";
print $command;
$rc = system($command);
print "rc=$rc\n";
Adding double quote marks around $command in the third line will not
change anything. (Adding double quote marks and a little more could help
the first print to look nicer, though.)
It may be that I'm misunderstanding you, though. Or maybe there's more to
what you're seeing than you're telling us. Can you post a small,
self-contained example program in which the line with quotes works and the
other doesn't? Of course, if these lines are themselves quoted in some
way, all bets are off! :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 5 May 2000 16:23:02 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Reading delimited file into hash
Message-Id: <Pine.GSO.4.10.10005051621460.6766-100000@user2.teleport.com>
On Fri, 5 May 2000 agodfrey1118@my-deja.com wrote:
> The file is currently delimited with ~ but delimiting character could
> be changed if need be.
Have you read the docs on 'split' in the perlfunc manpage? If that's not
where you're stuck, please ask more specifically. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 06 May 2000 01:44:19 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Reading delimited file into hash
Message-Id: <u2gc8svg.fsf@macforce.sumus.dk>
agodfrey1118@my-deja.com writes:
> I need to read a text file (/share/answer.txt) into a hash. The file is
> currently delimited with ~
if the file is delimited into key-value pairs it's pretty straightforward:
%data = ( split '~', <THEFILE> );
assuming that the file is one long line: key1~val1~key2~val2...
--
Jakob
------------------------------
Date: Fri, 5 May 2000 16:58:30 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Real and Windows streaming media access?
Message-Id: <Pine.GSO.4.10.10005051656560.6766-100000@user2.teleport.com>
On Thu, 4 May 2000 ajs@ajs.com wrote:
> e.g., if I have a URL of the form rtsp://... or mms://... what can I
> do to verify that that URL can be accessed? LWP/URI does not seem to
> know how to cope (need to fetch the most recent versions, though).
>
> I could just connect to the port, but I don't know how to speak the
> protocol, so I'd just be verifying that the server is accepting
> connections. I suppose I could go read the RFC for rtsp (is MMS a
> known quantity?)
If you can implement the protocol, you should probably extend LWP to
support it, rather than make a separate module to do so. Contact the LWP
mailing list before you start, though; their address is in the LWP docs.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 5 May 2000 16:50:20 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: regex question
Message-Id: <slrn8h6d0c.64k.tadmc@magna.metronet.com>
On Fri, 05 May 2000 20:27:25 GMT, gbaker@cs.umb.edu <gbaker@cs.umb.edu> wrote:
>
>I have a messy data set of street names with stuff like :
>
> 55 PARK WEST
>
>What I would like to do is replace /st$/ with " st"
>if the two letters before it are not some of the common
>ones that come up ( i.e. CU in Locust, WE in West, EA in East, ).
>Any Suggestions?
You do not have a "regex question".
You have a "natural language processing" question.
Those are Much Harder to answer.
For instance, if you disallow "WE" before the "ST", then
it won't do The Right Thing with LOWEST.
Is that "Lowe St" or "Lowest" ?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 May 2000 23:04:09 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: seeking a more elegant grouping algorithm than this ...
Message-Id: <slrn8h6kr8.l61.eric@plum.fruitcom.com>
#!/usr/bin/perl -w
for (split /\n\s*/, <<EOF) {
item1,f,e,sssss
item1,g,p,ddddd
item1,h,y,ggggg
item2,f,e,ddddd
item2,g,p,eeeee
item2,r,e,iiiii
item3,f,e,sssss
item3,g,p,ddddd
item3,h,y,ggggg
item4,t,g,ddddd
item4,g,p,eeeee
item4,r,e,iiiii
item5,f,e,ddddd
item5,g,p,eeeee
item5,r,e,iiiii
EOF
my ($first,$second,$third,$fourth) = split /,/;
$data{$first}{$second}{$third}{$fourth} = 1;
}
for my $first (sort keys %data) {
print "$first: ";
for my $second (sort keys %{$data{$first}}) {
for my $third (sort keys %{$data{$first}{$second}}){
$groupindex{$first}.= "$second$third";
}
}
print "Index for $first is $groupindex{$first}\n";undef $groupindex;
}
__END__
Once we have the unique groupage key from the above (based on the combined
values of all second and third fields for each Item), we then have to pass
through the data-set a /second/ time in order to prepend this key to each
record. And then a /third/ pass to actually process the resulting data-set.
I would like to get more elegantly from here ..
item1,f,e,sssss
item1,g,p,ddddd
item1,h,y,ggggg
item2,f,e,ddddd
item2,g,p,eeeee
item2,r,e,iiiii
item3,f,e,sssss
item3,g,p,ddddd
item3,h,y,ggggg
item4,t,g,ddddd
item4,g,p,eeeee
item4,r,e,iiiii
item5,f,e,ddddd
item5,g,p,eeeee
item5,r,e,iiiii
to here ..
group1,item1,f,e,sssss
group1,item1,g,p,ddddd
group1,item1,h,y,ggggg
group1,item3,f,e,sssss
group1,item3,g,p,ddddd
group1,item3,h,y,ggggg
group2,item2,f,e,ddddd
group2,item2,g,p,eeeee
group2,item2,r,e,iiiii
group2,item5,f,e,ddddd
group2,item5,g,p,eeeee
group2,item5,r,e,iiiii
group3,item4,t,g,ddddd
group3,item4,g,p,eeeee
group3,item4,r,e,iiiii
(the "group[123]" may just as well be a key like "fegphy")
thanx
--
Eric Smith
eric@fruitcom.com
------------------------------
Date: 5 May 2000 22:54:23 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Should a class that exports no symbols provide an empty import method?
Message-Id: <8evjev$b4v$1@pegasus.csx.cam.ac.uk>
Francis Litterio <franl-removethis@world.omitthis.std.com> wrote:
>mjtg@cus.cam.ac.uk (M.J.T. Guy) writes:
>> Better still - you don't need to provide an import method at all.
>
>That's probably not wise given this documentation:
>
> $ perldoc -f use
> ...
> If no `import()' method can be found then the error is currently
> silently ignored. This may change to a fatal error in a future
> version.
Current versions of the Perl documentation say
If no `import' method can be found then the call is skipped.
Mike Guy
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 2964
**************************************