[19240] in Perl-Users-Digest
Perl-Users Digest, Issue: 1435 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 3 14:05:36 2001
Date: Fri, 3 Aug 2001 11:05:09 -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: <996861909-v10-i1435@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 3 Aug 2001 Volume: 10 Number: 1435
Today's topics:
Re: Adding values of an array to an array in a hash (Anno Siegel)
Can you read email on an Exchange server with perl ?? <thechile@ntlworld.com>
Can't seem to get regex correct. (Mark Johnson)
Re: Can't seem to get regex correct. <vze2r2j8@verizon.net>
COmments appreciated <markku@huilustudio.fi>
Re: COmments appreciated (Tad McClellan)
Re: Creating small image of web page (Greg Bacon)
Re: data collection and file management (katherine)
Re: data collection and file management (Anno Siegel)
Re: DBI->connect parameters being pulled from XML file (Eric Bohlman)
Re: Finding files matching a pattern? (Eric Bohlman)
Re: FLATTEXT: Have it display random entries? (Anno Siegel)
frustrated beginner's question (Anthony_Barker)
Re: frustrated beginner's question (Anno Siegel)
Re: Generating Graphs (Anno Siegel)
Re: global variables <bart.lateur@skynet.be>
Re: Is regex in grep() automatically precompiled? (Eric Bohlman)
negative lookahead - cool (mike)
Re: Net::Ping troubles Solution <mcgeeb@jot.nb.ca>
Re: non-blocking read on win32, how? (Eric Bohlman)
Re: ODBC help (Paul Hancock's .pm) <jtjohnston@courrier.usherb.ca>
Re: parallel execution of shell commands in Perl script (Vladimir Parkhaev)
prompting and redirection with ssh - input.pl (0/1) <bob@bob.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 3 Aug 2001 15:41:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Adding values of an array to an array in a hash
Message-Id: <9kegmq$chp$1@mamenchi.zrz.TU-Berlin.DE>
According to J.C.Posey <jcp@myrtle.ukc.ac.uk>:
> I've searched groups.google.com (probably asking the wrong question), and
> looked in the Camel (probably not understanding what I've read), and
> looked at perldoc (see above).
>
> I'm taking a log file line by line, and I want to add the values of
> a, b, c, d (my four fields), to the same fields for the same unique
> key (a url).
>
> My codes snippet:
> # take the first value off and use it as the unique identifier
> # this leaves the four fields I'm interested in
> my $key = shift(@fields);
>
> # I then want to add a,b,c,d to the same fields already in the
> # hash--so a is added to a, etc.
> $urls{$key} += [$fields[0], $fields[1], $fields[2], $fields[3]];
It is not a good idea to describe your problem in terms of made-up
code. It doesn't make anything clearer, and it takes your readers'
time to parse it, find out it makes no sense, and understand that
it wasn't supposed to make sense.
> I thought the above method would add the array to the same fields
> in the array accessed by the key--but the results are wrong, I
> end up with my key, and one value, not four.
This is how I'd do it:
my %table;
while ( <DATA> ) {
chomp;
my ( $key, @values) = split; # one key, four values expected
# possible error checking goes here
my $i;
$table{ $key}->[ $i++] += $_ for @values; # add up field by field
}
__DATA__
key1 1 2 3 4
key2 5 6 7 8
key1 9 10 11 12
Note how the code builds up the table of sums without ever
initializing anything. That's what autovivification and general DWIMming
can do for you.
Anno
------------------------------
Date: Fri, 3 Aug 2001 16:50:34 +0100
From: "Scott" <thechile@ntlworld.com>
Subject: Can you read email on an Exchange server with perl ??
Message-Id: <EKza7.3561$tQ5.1403053@news2-win.server.ntlworld.com>
Just wondering if its possible to write a email client in perl or if there
is a module that allows you to access and read/send email using a microsoft
Exchange server??
I have seen many that do smtp/pop but i am prety sure exchange runs
diffrently.
Thanks,
[ Scott ]
------------------------------
Date: Fri, 03 Aug 2001 15:54:39 GMT
From: crvmp3@hotmail.com (Mark Johnson)
Subject: Can't seem to get regex correct.
Message-Id: <90F26DC10markjohnsononfiberco@24.28.95.150>
I'm having a really hard time getting the regular expressions down. I have
the following text to parse:
1:1 R 0 0 0 0 0 0
0 ESC[6;01H
1:2 R 0 0 0 0 0 0
0 ESC[7;01H
1:3 R 0 0 0 0 0 0
0 ESC[8;01H
1:4 R 0 0 0 0 0 0
0 ESC[9;01H
2:1 R 0 0 0 0 0 0
0 ESC[10;01H
2:2 R 0 0 0 0 0 0
0 ESC[11;01H
4:8 R 0 0 0 0 0 0
0 ESC[21;01H
4:9 R 0 0 0 0 0 0
0 ESC[01;55HThu Aug 2 16:49:23 2001
4:10 R 0 0 0 0 0 0
0 ESC[6;01H
4:32 R 0 0 0 0 0 0
0 ESC[01;55HThu Aug 2 16:49:31 2001
There are no newlines, I added them for posting purposes, and the ESC is
really a \033 or ASCII 27.
What I need to do is parse out just from the R to the \e (ESC character).
I tried:
@arr = (m/R*\e/g);
while( @arr )
{
$line = shift @arr;
$results .= "$line";
}
But this doesn't return me anything. I tried every variation of what I
could think of with no success. The closest I got was (m/\b\C/g)... There
must be some conceptual piece that I'm not understanding which is probably
really obvious.
Thanks for any help you can give me.
------------------------------
Date: Fri, 03 Aug 2001 16:40:55 GMT
From: "Kurt Stephens" <vze2r2j8@verizon.net>
Subject: Re: Can't seem to get regex correct.
Message-Id: <ruAa7.68$f_5.18666@typhoon2.gnilink.net>
"Mark Johnson" <crvmp3@hotmail.com> wrote in message
news:90F26DC10markjohnsononfiberco@24.28.95.150...
> I'm having a really hard time getting the regular expressions down. I
have
> the following text to parse:
>
> 1:1 R 0 0 0 0 0 0
0 ESC[6;01H
[snip]
> There are no newlines, I added them for posting purposes, and the ESC is
> really a \033 or ASCII 27.
>
> What I need to do is parse out just from the R to the \e (ESC character).
> I tried:
>
> @arr = (m/R*\e/g);
This regex returns nothing because it captures nothing. Even if it did, it
would return zero or more 'R's followed by \e. At first thought you might
say 'Doh! I meant /R.*\e/', however greedy behaviour would cause this to
match everything from the first 'R' through the last \e.
Examine the expression below. I think it should do what you want.
my @arr = m/
R # match the R delimiter
( # start capture
[^\e]* # zero or more chars excluding \e
) # end capture
\e # match the \e delimiter
/gx;
# Or, in brief:
@arr = /R([^\e]*)\e/g;
HTH,
Kurt Stephens
------------------------------
Date: Fri, 03 Aug 2001 20:05:57 +0300
From: Markku Hirvonen <markku@huilustudio.fi>
Subject: COmments appreciated
Message-Id: <8fmlmt0t7tareng5kea6ssqntq3u6l3h8d@4ax.com>
Hi!
I have a messageboard and i wanted to shorten all the words longer
than 20 characters and put 3 dots after them.
This is what i came up with:
if ($orig_message =~ m/(\w{20,})/) {
$truncated_message = substr($1, 0, 20);
$orig_message =~ s/(\w{20,})/$truncated_message.../g;
}
This is doing the trick for now but i was wondering if any of you
professionals see something that i miss here. Perhaps a better way to
do it...
Thank you for your time.
Markku Hirvonen
------------------------------
Date: Fri, 3 Aug 2001 12:34:08 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: COmments appreciated
Message-Id: <slrn9mlkk0.15f.tadmc@tadmc26.august.net>
Markku Hirvonen <markku@huilustudio.fi> wrote:
>
>I have a messageboard and i wanted to shorten all the words longer
>than 20 characters and put 3 dots after them.
$orig_message =~ s/(\w{20})\w+/$1.../g;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 03 Aug 2001 16:02:50 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Creating small image of web page
Message-Id: <tmlipa9e2hk358@corp.supernews.com>
In article <9kdgdj$9ul$04$1@news.t-online.com>,
Steffen Müller <tsee@gmx.net> wrote:
: "Randal L. Schwartz" <merlyn@stonehenge.com> schrieb im Newsbeitrag
: news:m14rrqceci.fsf@halfdome.holdit.com...
:
: [snipped my not-so-well-educated rant]
:
: > ImageMagick and therefore PerlMagick can take .html input and
: > generate PNG output if you have all the right helper programs.
: > Scaling is trivial. I was thinking of doing that for one of my
: > columns soon.
:
: You're right.
: I should have done my homework better. However, I still think my point
: about Perl being able to do this if any language can is valid ;-)
It's possible to write a Perl program that simulates a universal Turing
machine, so, yes, your point is both valid and correct.
Greg
--
Science is what we understand well enough to explain to a computer.
Art is everything else.
-- Knuth
------------------------------
Date: 3 Aug 2001 09:52:28 -0700
From: kstar8864@hotmail.com (katherine)
Subject: Re: data collection and file management
Message-Id: <848d6bd2.0108030852.68f65c0@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<9ke6tg$58c$1@mamenchi.zrz.TU-Berlin.DE>...
Sorry about the clarity, hopefully I can clear it up.
> Apparently "a file" here means "an individual file for each utility".
> Will all of the command output be stored, or a summary?
>
Yes, a file is an actual individual file for each utility.
> Will the
> information accumulate in the files or is each file overwritten with
> the next run?
>
The information accumulates.
> BTW, on some systems running the iostat/vmstat/cpustat/
> netstat combo every second would represent a considerable load.
>
My only other alternative to using these utilities is to use the
internal kernel statistics, and in Solaris (the OS I am using) those
statistics can change (although it would certainly be an easier
approach).
> Well obviously you are storing summaries (the last line of netstat
> output (say) wouldn't be very informative), and apparently the lines
> do accumulate (otherwise there would ever only be one). And why
> would you run the utilities every second when you gather data only
> every five seconds?
>
I am storing summaries--basically a continuous log of the 5 second
data. I don't need to limit its size, it can grow without bound. The
reason I am only keeping the data ever 5 seconds but not the 1 second
data is the need for synchronous output. If you run the utilities for
weeks at a time they get very out of sync, so simply taking the data
every 5 seconds won't give me the results I need. Therefore if the
utilities give information every second, and I am only taking data
every 5 seconds then I can guarantee they are in sync within a second
or so.
> Do you mean you want to get rid of the individual files? And
> "maintaining the one big file" means what? What properties do
> you want to maintain?
>
Yes I want to be able to figure out some way to store the output from
the individual files such that the data doesn't have to be logged to
files and then written to the "large 5 second log file" (aka the big
file). The most important properties is the data and the fact it is
synchronous. If I was programming in C (for example) I could do this
using shared memory and just store the last few lines of output into a
cirular buffer. Except shared memory is too precious as a system
resource to use for this program.
Any help/suggestions would be greatly appreciated.
-Katherine
kstar8864@hotmail.com
------------------------------
Date: 3 Aug 2001 17:54:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: data collection and file management
Message-Id: <9keofv$hj8$1@mamenchi.zrz.TU-Berlin.DE>
According to katherine <kstar8864@hotmail.com>:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<9ke6tg$58c$1@mamenchi.zrz.TU-Berlin.DE>...
>
> Sorry about the clarity, hopefully I can clear it up.
>
> > Apparently "a file" here means "an individual file for each utility".
> > Will all of the command output be stored, or a summary?
> >
> Yes, a file is an actual individual file for each utility.
>
> > Will the
> > information accumulate in the files or is each file overwritten with
> > the next run?
> >
> The information accumulates.
>
> > BTW, on some systems running the iostat/vmstat/cpustat/
> > netstat combo every second would represent a considerable load.
> >
> My only other alternative to using these utilities is to use the
> internal kernel statistics, and in Solaris (the OS I am using) those
> statistics can change (although it would certainly be an easier
> approach).
Well, these utilities give you only snapshots too. And they won't
sync among each other at all.
> > Well obviously you are storing summaries (the last line of netstat
> > output (say) wouldn't be very informative), and apparently the lines
> > do accumulate (otherwise there would ever only be one). And why
> > would you run the utilities every second when you gather data only
> > every five seconds?
> >
> I am storing summaries--basically a continuous log of the 5 second
> data. I don't need to limit its size, it can grow without bound. The
> reason I am only keeping the data ever 5 seconds but not the 1 second
> data is the need for synchronous output. If you run the utilities for
> weeks at a time they get very out of sync, so simply taking the data
> every 5 seconds won't give me the results I need. Therefore if the
> utilities give information every second, and I am only taking data
> every 5 seconds then I can guarantee they are in sync within a second
> or so.
>
> > Do you mean you want to get rid of the individual files? And
> > "maintaining the one big file" means what? What properties do
> > you want to maintain?
> >
> Yes I want to be able to figure out some way to store the output from
> the individual files such that the data doesn't have to be logged to
> files and then written to the "large 5 second log file" (aka the big
> file). The most important properties is the data and the fact it is
> synchronous. If I was programming in C (for example) I could do this
> using shared memory and just store the last few lines of output into a
> cirular buffer. Except shared memory is too precious as a system
> resource to use for this program.
Mucho clearer now, thanks. Here's my take. Replace the individual
files with processes that deliver the data as requested.
In particular:
For each utility write a program that runs in an endless loop: It
calls "it's" utility (taking time stamps before and after the run),
processes its output and prints a time-stamped informative line
to STDOUT, much like what would have been written to the individual
files. The program immediately loops back (but its output won't be
taken immediately).
Then have a central process that initially open()s pipes to the
individual utility-drivers. In its own endless loop it reads
lines from the subprocesses round-robin and combines them in useful
ways, considering the time stamps. Then it sleeps (what remains of)
five seconds and reads again. That way the subprocesses are
re-synchronized on each read.
Anno
------------------------------
Date: 3 Aug 2001 17:42:05 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: DBI->connect parameters being pulled from XML file using XML::DOM methods - throws error
Message-Id: <9kenpd$mko$4@bob.news.rcn.net>
brian donovan <usenet@lophty.com> wrote:
> (2.) looking at the error message, I wondered about those returns
> between parameters (a light went off), so I flattened out the xml a little :
> <database>
> <databasename>my_db_name</databasename>
> <hostname>localhost</hostname>
> <dbusername>my_db_username</dbusername>
> <dbpass>my_db_pass</dbpass>
> </database>
> Then it worked. The returns and tabs before and after the contents of
> the element nodes were getting left in the text nodes whose value I was
> extracting and it was killing the DBI->connect.
Yes, one of the first things you need to know about XML is that *all*
whitespace outside of markup is significant in an XML document.
"Prettyprinting" an XML document changes its meaning. This is a very
common trap for beginners.
------------------------------
Date: 3 Aug 2001 17:32:57 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Finding files matching a pattern?
Message-Id: <9ken89$mko$3@bob.news.rcn.net>
chiry@csua.berkeley.edu wrote:
> Hi, I am writing a perl script on Windows, where the shell does not do
> wildchar substitution.
> Lets say my script is passed in dsc*.jpg, how do I find all the files
> that matches this pattern?
The path of least resistance is to use the following technique to make
perl expand wildcards before running your code:
1) Set your PERL5OPT environment variable to "-MWild".
2) Put the following code in a file called "Wild.pm" in some directory
(e.g. \perl\lib) that's included in your @INC:
# Wild.pm - emulate shell @ARGV expansion on shells that don't
use File::DosGlob;
@ARGV = map {
my @g = File::DosGlob::glob($_) if /[*?]/;
@g ? @g : $_;
} @ARGV;
1;
Once you've done this, your code will behave as if the shell had done the
expansion.
------------------------------
Date: 3 Aug 2001 16:17:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FLATTEXT: Have it display random entries?
Message-Id: <9keiq1$e0e$1@mamenchi.zrz.TU-Berlin.DE>
According to charles <charles@vortus.com>:
> Hello. I have had great success with FLATTEXT and the Zip Code
> Locator section of the software. However, one step is causing
> problems. I would like to have it pull three RANDOM entires from the
> text file that meet the criteria. For example, if I do a search for
> stores in Chicago, I want it to just return three random stores in
> Chicago. Right now, I can only get it to return the first or last
> three alphabetically.
Have FLATTEXT (whatever that is) deliver all the hits and store them
in an array. Then select three random elements like so:
my @selection = map splice( @array, rand @array, 1), 1 .. 3;
"splice" removes the element selected by "rand @array" from @array,
so no duplicates will occur. If there are fewer than three elements
to begin with, only so many will be delivered (instead of giving
you undefs). This is probably what it should do.
Oh, and when you replace "3" with @array, it gives you a random
permutation.
Anno
------------------------------
Date: 3 Aug 2001 08:43:56 -0700
From: anthony_barker@hotmail.com (Anthony_Barker)
Subject: frustrated beginner's question
Message-Id: <899f842.0108030743.69b62874@posting.google.com>
Hi:
I am having problems sorting and comparing data.
Essentially I want to read 40,000 names into an array and then search
for duplicate last names with the same first three initials of a name
or the email address contains a number.
So in the following script we would get
where the fields are Company, shortname, First, Last, email, other
BM,jabad,JOUITA,ABAD,Jouita1.ABAD@bm.ok,D # email contains 1
BM,rabad,RACHEL,ABAD,non,U # flagged due to lastname + 3 char of first
name
BM,rabad,RACH,ABAD,non,U # ditto
I took the ST and tried it to work for me without any luck..
Does someone have any pointers or sample code I can look at?
Thanks
Anthony
+++++++++++++++++++++++++++++++++++++++++++++++++++
use strict;
my @data = <DATA>;
my @sorted = map { $_->[0] }
sort custom
map { [$_, split /,/ ] } @data;
print "@sorted \n";
my $test;
foreach $test (@sorted) {
if ($a->[4] eq $b->[4]) {
# this doesn't work....
}
}
sub custom {
$a->[4] cmp $b->[4];
}
__DATA__
BM,jaarbo,JOLENE,AARBO,non,U
BM,paarest,PETER,AARESTAD,Peter.Aarestad@bm.ok,U
BM,baasen,BRIAN,AASEN,non,U
BM,jabad,JOUITA,ABAD,Jouita1.ABAD@bm.ok,D
BM,rabad,RACHEL,ABAD,non,U
BM,rabad,RACH,ABAD,non,U
------------------------------
Date: 3 Aug 2001 17:11:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: frustrated beginner's question
Message-Id: <9kelvg$g0m$1@mamenchi.zrz.TU-Berlin.DE>
According to Anthony_Barker <anthony_barker@hotmail.com>:
> Hi:
>
> I am having problems sorting and comparing data.
>
> Essentially I want to read 40,000 names into an array and then search
> for duplicate last names with the same first three initials of a name
> or the email address contains a number.
>
> So in the following script we would get
> where the fields are Company, shortname, First, Last, email, other
>
> BM,jabad,JOUITA,ABAD,Jouita1.ABAD@bm.ok,D # email contains 1
> BM,rabad,RACHEL,ABAD,non,U # flagged due to lastname + 3 char of first
> name
> BM,rabad,RACH,ABAD,non,U # ditto
>
>
> I took the ST and tried it to work for me without any luck..
> Does someone have any pointers or sample code I can look at?
Why do you want to sort the data? That is much too much work when
you only want to mark duplicates. You don't even have to read all
the data at once. If you hadn't the requirement that *all* duplicates
must be flagged (even the first appearance), it could be done in
one pass over the data. This way we'll have to use two.
During the first pass we generate keys from the name and the beginning
of the first name. We glue them together with some separator that
can't appear in a name, so that "Ann Osiegel" and "Anno Siegel" don't
coalesce. These we store in a hash and count the number of occurrences,
so we will know on the second pass if we have a duplicate.
The second pass simply looks for duplicates and mail addresses with
a digit in them and flags all those. Code example below.
Anno
my $pos = tell DATA; # we need that for DATA, would be 0 otherwise
my $separator = ':'; # set to something that can't appear in a name
my %seen;
while ( <DATA> ) {
chomp; # we don't need that, but it's a good habit
my ( $first, $last) = ( split /,/)[ 2, 3];
$seen{ substr( $first, 0, 3) . $separator . $last}++; # mark as seen
}
seek DATA, $pos, 0; #rewind DATA
while ( <DATA> ) {
chomp;
my ( $first, $last, $addr) = ( split /,/)[ 2, 3, 4];
if ( $seen{ substr( $first, 0, 3) . $separator . $last} > 1 or
$addr =~ /\d/ ) {
# flag the line somehow, modifying $_
$_ .= ' <<<';
}
print "$_\n";
}
__DATA__
BM,jabad,JOUITA,ABAD,Jouita.ABAD@bm.ok,D
BM,rabad,RACHEL,ABAD,non,U
BM,rabad,RACH,ABAD,non,U
------------------------------
Date: 3 Aug 2001 15:49:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Generating Graphs
Message-Id: <9keh5j$chp$2@mamenchi.zrz.TU-Berlin.DE>
According to Keith Resar <3b533a81314e4@heavyk.org>:
> I've been trying to find a powerful interface for graphing data in PERL
> and have been relatively unsuccessful so far.
PERL is either spelled Perl or perl. There's a FAQ about that.
> I'm looking for a program that can approximate a function to graph given
> the data set, rather then just graphing the data itself.
I assume you mean "find an approximating function and graph that".
> So far I've had no success using GD::Graph and Chart::Graph.
Probably because the problem of interpolating an approximating
function isn't a graphical one. I'd look for mathematical or
data modeling modules on the CPAN.
Anno
------------------------------
Date: Fri, 03 Aug 2001 16:13:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: global variables
Message-Id: <objlmt460foktk3qf5m35e8t7ft8qalvqf@4ax.com>
Manuel Körner wrote:
>here's the sourcefile which to include with require:
>
># filename test.pl
>use strict;
>package test;
>our $TRUE = 1;
>...
>
># sourcefile which includes the test.pl
>use strict;
>require "./test.pl"
>...
>return $TRUE;
>...
>
>error message:
>"Global symbol $TRUE requires explicit package name at ...
If you want cross-package accessible globals, I think it's best to put
them in main. Like this:
use strict;
package Foo;
$::TRUE = 1;
package Bar;
print $::TRUE;
Note that $::var is the same as $main::var. And, since these variables
are qualified, you don't even have to declare them.
--
Bart.
------------------------------
Date: 3 Aug 2001 16:58:48 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Is regex in grep() automatically precompiled?
Message-Id: <9kel88$mko$1@bob.news.rcn.net>
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> While waiting for replies, I made a benchmark of grep versus for-loop
> over an array with 100000 elements each with both pre-compiled and
> non-pre-compiled patterns. qr() does in fact perform slightly worse both
> for grep and for. It also shows that grep is on overage 10% quicker than
> a for-loop which sort of surprised me since I heard that grep wouldn't
> be so very performant.
It's not surprising at all that grep would be faster than a for loop *for
the same number of iterations*; after all the looping with grep is taking
place in well-optimized C code whereas the looping with for is taking
place in perl opcodes that need to be dispatched.
The performance problems *sometimes* associated with grep have to do with
the fact that it will always loop over *every* element of its argument
list. That will slow things down in cases where finding the *first* match
is all you need to do (e.g. if your concern is that your input matches
one of a set of patterns).
------------------------------
Date: 3 Aug 2001 10:19:53 -0700
From: rafalam@cadmus.com (mike)
Subject: negative lookahead - cool
Message-Id: <bcffa3aa.0108030919.73c72f33@posting.google.com>
>>I want to match a string that starts with "aaa"
>>and ends with "bbb" as long as there is no "zzz"
>>between aaa and bbb.
>>My attempt:
>>$mystring =~ m/aaa.*?(?!zzz)bbb/si;
>>Result:
>>Still matches even if the string contains zzz.
>I think this will work: m/aaa(?:(?!zzz).)*?bbb/si;
This is cool! I can modify this so that with one line of code, I can
eliminate all superfluous nesting of the same tag:
1 while $wholefile =~
s/(<I>(?:(?!<\/I>).)*?)<I>((?:(?!<I>).)*?)<\/I>/$1$2/s;
Thus:
<I>Once <I>upon <I>a time </I><I>there</I> were </I>three bears</I>.
Becomes:
<I>Once upon a time there were three bears</I>.
mike
------------------------------
Date: Fri, 03 Aug 2001 17:27:46 GMT
From: "Brian McGee" <mcgeeb@jot.nb.ca>
Subject: Re: Net::Ping troubles Solution
Message-Id: <maBa7.1280$TQ6.197874@news-nb00s0.nbnet.nb.ca>
The solution (or at least the one I wound up using):
Net::Ping->ping() or Net::Ping->ping('udp') is not recognized by many
servers, so they are reported as inactive even though they are up and
running.
Net::Ping->ping('tcp') will not work on ActivePerl. ActivePerl does not have
the alarm
function, required for this method. Note: if ActivePerl does have an alarm
function or the function
can be added, please let me know as I would like to be able to the the tcp
ping method.
Net::Ping->ping('icmp') needs administrative priviledges to run correctly.
As soon as I told IIS to run that cgi file as an administrator, it worked
perfectly and was recognized by the NT, 2000 and Linux machines on which I
tested it.
I just thought I would share the solution as I did share the problem too.
Maybe it will help someone else.
-Brian
"Brian McGee" <mcgeeb@jot.nb.ca> wrote in message
news:0Jwa7.1219$TQ6.191971@news-nb00s0.nbnet.nb.ca...
> On an NT based machine running ActivePerl 5.6+, I can not get Net::Ping to
> behave.
>
> The following code always says that my server does not exist
>
> use Net::Ping;
>
> my $ping = Net::Ping->new();
> print "The result of pinging $address is: ", $ping->ping($address);
> $ping->close();
>
> I have experimented with new('tcp') and new ('icmp') but I get the errors
>
> The Unsupported function alarm function is unimplemented at
> D:/Perl/lib/Net/Ping.pm line 308.
>
> and
>
> icmp socket error - Unknown error at c:\inetpub\wwwroot\test1.pl line 11
>
> respectively. Any ideas? It is a simple function but it seems to have just
> stopped up on me.
>
> -Brian
>
>
------------------------------
Date: 3 Aug 2001 17:09:55 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: non-blocking read on win32, how?
Message-Id: <9kelt3$mko$2@bob.news.rcn.net>
Allan <clarke__@__hyperformix.com> wrote:
> I'm trying to read the standard output of a process from another
> process. The read needs to be NON-BLOCKING, the reason
> is that this is part of a GUI that needs to update during long
> operations.
> If I use a call like open(INPUT,"outputsomestuff.exe |"), I can read
> from the file handle, but I hang until the executable finishes. I have
> tried using IO::Handle with the nonblocking(1) call, but get the same
> behavior. The classical approach is to use fileevent() but this does not
> pick up output piecemeal on Win32. I have tried IO::Select, but it
> works only with sockets.
The problem (at least in the "desktop" versions of Win32) is that pipes
aren't really pipes; they're tanks with the entry and exit valves linked
together so that only one can be open at a time. They're implemented
using temporary files, and the processes run sequentially rather than
concurrently.
There may be some workarounds involving Win32::Process and various IPC
functions, but they may not be possible to implement unless you can write
them into both the calling and called programs.
------------------------------
Date: Fri, 03 Aug 2001 16:20:00 GMT
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: Re: ODBC help (Paul Hancock's .pm)
Message-Id: <3B6ACFDE.5C3F6E96@courrier.usherb.ca>
Trevor,
> Assuming you have a Windows machine and the Access engine: DBI+DBD::ODBC
> Go to control panels, open ODBC data sources, add a new system DSN,
> select your database as the source and give it a name. Close.
> In perl, you can now connect with
> use DBI;
> my $dbh = new DBI("DBI:ODBC:$dsn", $user, $pwd);
> where $dsn is the name you entered in the ODBC control panel, $user and
> $pwd is an existing username and password combination.
This much I can do. But I do not know where to find documentation or
examples to display (or edit) parts or the whole of "table1"
num|rec1|rec2|rec3|
1 |aa |bb |cc |
2 |aa |bb |cc |
--------snip---(This works so far as this:)------
print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n\n";
use Win32::ODBC;
$sql = "SELECT * FROM table1";
$dsn = "MyData";
$db = new Win32::ODBC($dsn);
$db->Sql($sql);
#How do I display my table? Now?
$db->Close();
------------------------------
Date: Fri, 03 Aug 2001 15:17:04 GMT
From: vladimir@bagel.arobas.net (Vladimir Parkhaev)
Subject: Re: parallel execution of shell commands in Perl script
Message-Id: <slrn9mlg06.4rt.vladimir@bagel.arobas.net>
In article <3B69D0E2.7DB98F90@tamu.edu>, testaccount wrote:
>Hi,
>
>How can I make command1 and command2 run in parallel instead of
>sequentially as shown below?
>
Something along these lines.... Be carefull with the output it
will be intermixed...
#!/usr/bin/perl -w
$|++;
@cmds = qw/ls df who/;
$children = 0;
foreach $cmd ( @cmds ) {
if( my $pid = fork() ) { # parent
$children++;
}
else { # child
exec $cmd or die "Cannot exec: $!\n";
# children never come back here, sad, sad story
}
}
while ( $children ) {
my $died = wait;
$children--;
}
print "All dead\n";
--
print chr hex for qw +
2D 2D 0A 76 6C 61 64 69 6D 69 72 40 61 72 6F 62 61 73 2E 6E 65 74 0A 44 38
37 44 20 44 32 46 42 20 46 31 36 33 20 46 31 43 31 20 34 32 30 41 20 20 31
44 31 46 20 36 43 42 39 20 31 46 38 39 20 38 35 30 42 20 30 38 44 44 0A +;
------------------------------
Date: Fri, 03 Aug 2001 16:40:09 GMT
From: Bob <bob@bob.net>
Subject: prompting and redirection with ssh - input.pl (0/1)
Message-Id: <bvklmtg3a9htq5o1pr4qngi1n3e34j6pco@4ax.com>
Hi,
I am trying to figure out how to "intelligently" prompt the user from
perl . I have read a great deal from this newsgroup (via
groups.google.com), the perl cookbook, and other resources. Attached
is the script that I have written based off of these readings.
It appears to work in every scenario I throw at it from the console.
Below are some examples usages:
./input.pl . file -
echo input | ./input.pl - file
echo input | ./input.pl - file /dev/tty
echo input | ./input.pl - file /dev/tty > a
./input_pl file - /dev/tty > a
However, when I try and run this last one via ssh the prompt does not
appear on the screen. It is re-directed to the file 'a'. That is,
when I:
ssh -t host input.pl file - /dev/tty > a
It does not work like I exepct. I am using ssh version:
OpenSSH_2.5.2p2, SSH protocols 1.5/2.0, OpenSSL 0x0090601f
Do you have any ideas on how I can get it to work with ssh?
------------------------------
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 1435
***************************************