[18939] in Perl-Users-Digest
Perl-Users Digest, Issue: 1134 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 14 14:05:43 2001
Date: Thu, 14 Jun 2001 11:05:11 -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: <992541911-v10-i1134@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 14 Jun 2001 Volume: 10 Number: 1134
Today's topics:
Re: (csv) Split at a coma, how? <mbudash@sonic.net>
Re: accuracy on $i on for($i=0;$i<=1;$i++) <tinamue@zedat.fu-berlin.de>
Re: accuracy on $i on for($i=0;$i<=1;$i++) nobull@mail.com
Re: accuracy on $i on for($i=0;$i<=1;$i++) <ren@tivoli.com>
Re: An ever unwanted growing array??? <peb@bms.umist.ac.uk>
Cookbook Socket 605 <skpurcell@hotmail.com>
Re: Date of Halloween (for Date::Calc module)? <ryantate@OCF.Berkeley.EDU>
Re: DBI problem (Mike Driggers)
Re: efficient change file with locking? <newspost@coppit.org>
Re: initialising multi-dimensional array (Anno Siegel)
Re: initialising multi-dimensional array nobull@mail.com
Re: initialising multi-dimensional array <ren@tivoli.com>
Re: initialising multi-dimensional array (Ben Okopnik)
Re: Memory Issues/File Slurping <john.imrie@pa.press.net>
Re: Memory Issues/File Slurping <ren@tivoli.com>
Multiplexing stdin and stderr to screen and logfile (LMC)
Re: Multiplexing stdin and stderr to screen and logfile (LMC)
Re: Negative lookahead not working <ren@tivoli.com>
Re: Negative lookahead not working <joe+usenet@sunstarsys.com>
Re: new to perl need help with concordance (Helgi Briem)
Re: newbie-- re:win32 system() calls -- rmdir /s/q <korac@dirig.com>
Re: newbie-- re:win32 system() calls -- rmdir /s/q <stevea@wrq.com>
Re: newbie-- re:win32 system() calls -- rmdir /s/q <korac@dirig.com>
Re: newbie-- re:win32 system() calls -- rmdir /s/q <ren@tivoli.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 14 Jun 2001 08:55:10 -0700
From: Michael Budash <mbudash@sonic.net>
Subject: Re: (csv) Split at a coma, how?
Message-Id: <mbudash-D933AD.08551014062001@news.pacbell.net>
In article <VA.00000017.0030b247@fox-europe.com>,
alan1.pettigrew1@fox1-europe1.com wrote:
> In article <EPrT6.118214$I5.27391631@news1.rdc1.tn.home.com>, Todd Smith
> wrote:
> > "Steve Martin" <stevemartintelecom@home.com> wrote in message
> > news:cxrT6.44423$Be4.14411182@news3.rdc1.on.home.com...
> > > Hi,
> > >
> > > I am doing a small script that opens a weekly schedule that an admin
> > assist
> > > is producing and saving in .csv.
> > > I need to know how to split at every coma in order to incert every
> > > separation in a nice html table.
> >
> > Wow Steve Martin!
> >
> > just use this, sir:
> >
> > while (<FILE>) {
> > chomp;
> > @a = split /,/;
> > for (@a) {
> > print "<td>$_</td>";
> > }
> > }
> >
> But what about embedded commas? What happens with a line like
> field1,"field2a, field2b, field2c",field3
> This would give
> <td>field1</td>
> <td>"field2a</td>
> <td> field2b</td>
> <td> field2c"</td>
> <td>field3</td>
> which isn't correct. This is the standard CSV problem.
> The data given did start
> "Version finale, le 18 mai,
> 2001",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
> Saison du 4 juin au 3 septembre
> 2001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
> so I assume that embedded commas are expected.
>
> I haven't worked out the regex for this. Perhaps one of you can.
>
> Alan
>
use Text::Parsewords;
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: 14 Jun 2001 16:04:39 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: accuracy on $i on for($i=0;$i<=1;$i++)
Message-Id: <9ganan$87158$1@fu-berlin.de>
hi,
Frederic Magnard <magnard@iap.fr> wrote:
> As I type
> $ perl -e 'for ($i=0.1; $i<=1; $i+=0.01) {print "$i\n";}'
> I'm surprised to read the last lines on an DEC-osf machine:
> 0.690000000000001
> ...
> 0.??0000000000001
> ...
> 0.990000000000001
[...]
> My perl version :
is alright =)
it's a rounding problem. numbers are not stored in the decimal
system. look at this:
perl -e ' for ($i=0.1; $i<=1; $i+=0.01) { printf "%.40f\n",$i; }'
then you see the a bit more how the numbers really look.
you probably want:
perl -e ' for ($i=0.1; $i<=1; $i+=0.01) { printf "%.2f\n",$i; }'
^^
perldoc -f sprintf
hth,
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx
------------------------------
Date: 14 Jun 2001 17:51:26 +0100
From: nobull@mail.com
Subject: Re: accuracy on $i on for($i=0;$i<=1;$i++)
Message-Id: <u9ae3bm369.fsf@wcl-l.bham.ac.uk>
Frederic Magnard <magnard@iap.fr> writes:
> $ perl -e 'for ($i=0.1; $i<=1; $i+=0.01) {print "$i\n";}'
> I'm surprised to read the last lines on an DEC-osf machine:
> 0.990000000000001
> What kind of error is that ?
Rounding.
> Or do I do something wrong ?
What you have done wrong is to post a FAQ: "Why am I getting long
decimals (eg, 19.9499999999999) instead of the numbers I should be
getting (eg, 19.95)?"
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 14 Jun 2001 10:40:22 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: accuracy on $i on for($i=0;$i<=1;$i++)
Message-Id: <m3n17bhxy1.fsf@dhcp9-173.support.tivoli.com>
On Thu, 14 Jun 2001, magnard@iap.fr wrote:
>
> Hello,
>
> As I type
> $ perl -e 'for ($i=0.1; $i<=1; $i+=0.01) {print "$i\n";}'
> I'm surprised to read the last lines on an DEC-osf machine:
> 0.690000000000001
> ...
> 0.??0000000000001
> ...
> 0.990000000000001
>
> and these lines on a linux (pentium 3) machine:
> 0.889999999999999999
> ...
> 0.??9999999999999999
> ...
> 0.999999999999999999
>
> What kind of error is that ? Or do I do something wrong ?
Take a look at:
$ perldoc -q number
Found in /usr/lib/perl5/5.6.0/pod/perlfaq4.pod
Why am I getting long decimals (eg, 19.9499999999999)
instead of the numbers I should be getting (eg, 19.95)?
[answer snipped]
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 14 Jun 2001 16:31:22 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: An ever unwanted growing array???
Message-Id: <3B28D8CA.50BB2AA9@bms.umist.ac.uk>
Mark Stellaard wrote:
>
> Anybody who can help me with this one????
> I have two files: 'foo.pl' and a package 'bar.pm' see below
<code>
> The problem is that every time I call 'func_1' the @list is growing and
> growing.
> I guess it has something to do with the global var @files.
Yep. You keep adding to it.
>
> But when using the 'my' for @files in the recursive function like this: push
> ( my @files, $foo),
> it clears the @files every time when 'recursive' is called, because of the
> 'my'.
>
> How can I use the function 'func_1' without letting the @list growing to
> abnormal porportions???
> So every time I call func_1 a new list must be used, which will be filled by
> the 'recursive' function.
how about clearing the array every time you call func_1?
sub func_1 {
my @list = ();
@files = ();
@list = recursive($bar);
}
that should do it.
HTH
Paul
------------------------------
Date: Thu, 14 Jun 2001 11:23:04 -0500
From: "spurcell" <skpurcell@hotmail.com>
Subject: Cookbook Socket 605
Message-Id: <3b28e238$0$175@wodc7nh6.news.uu.net>
Hello,
I basically have been using the code from the Cookbook on page 605 for
IO::Socket::INET->new yada yada.
All has worked solidly for talking to another box for a year. I have the
need to actually create the Handle and pass it to another routine. I have
always used a global for the past year, but as I am fixing up some old code,
I am using strict and do not want to make it a global.
If I have the following line in a sub called makeSocket()
sub makeSocket {
my $handle = IO::Socket::INET->new(PeerAddr => "XXX.XXX.XXX.XXX",PeerPort =>
'8xxx') or die $@;
}
and later on I want to print to that handle in another sub
sub askProduct {
my $msg = "\%BEGIN\tHello What A Good Day You Are Having";
print $handle "$msg";
}
without making $handle global, how to I pass it. I tried it just as a
variable
return $handle
my $newhandle = shift, but I get a 1, not a reference to some object
handle?
Thank you
Scott Purcell
------------------------------
Date: Thu, 14 Jun 2001 17:35:01 +0000 (UTC)
From: Ryan Travis Tate <ryantate@OCF.Berkeley.EDU>
Subject: Re: Date of Halloween (for Date::Calc module)?
Message-Id: <9gask5$294q$1@agate.berkeley.edu>
In comp.lang.perl.modules Randal L. Schwartz <merlyn@stonehenge.com> wrote:
| Unions. Sheesh. Still hanging around long past their actual use.
"Jayadev, an assembly worker in a Hewlett-Packard packaging plant,
loses his job when he blows the whistle on pay inequities and health
and safety conditions. 'There's nothing new about this new economy,'
Jayadev says. 'The only difference is that the (poor working
conditions) aren't acknowledged.'"
<URL:http://www.sfgate.com/cgi-bin/article.cgi?file=/chronicle/archive/2001/04/06/DD227099.DTL> (second item)
"'It's interesting that people see, feel, and buy all these computers,
printers, hardware, and software,' Jayadev said over stock footage of
the assembly-line, 'but they do not think that real people make those
things, that human beings physically construct them. They must think
our technology is sent down by some divine presence. It's phenomenal
to think there could be such a massive public misconception.'"
<URL:http://www.wired.com/news/digiwood/0,1412,43990,00.html>
Documentary website:
<URL:http://www.secretsofsiliconvalley.org/reviews.html>
This is an excellent film. I do not adore unions blindly -- in fact, I
have had a National Labor Relations Board grievance brought against me
-- but I believe they have their place in free markets in general and
in the tech sector in particular.
cheers
ryam
------------------------------
Date: 14 Jun 2001 09:27:39 -0700
From: mike.driggers@xo.com (Mike Driggers)
Subject: Re: DBI problem
Message-Id: <1fd3ee27.0106140827.569e9623@posting.google.com>
Have you tried
DBI->trace( 1 );
Or from the command line:
$ DBI_TRACE=1 ./myscript.pl
This has always been a great tool for me.... for more detail, use level 2 or 3.
Mike
------------------------------
Date: Thu, 14 Jun 2001 11:48:45 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: efficient change file with locking?
Message-Id: <Pine.SUN.4.33.0106141147590.20271-100000@mamba.cs.Virginia.EDU>
On 14 Jun 2001, Anno Siegel wrote:
> According to John Hall <jhall@ifxonline.com>:
> > My system for whatever reason doesn't have flock or lockf, so I did this
> > instead.. I don't know how great it is.. Simple semaphore-
> >
> > sub open_db {
> >
> > my $db = shift;
> >
> > while(-f ("$datadir/$db".'db.lock')){ select(undef,undef,undef,0.1); }
> >
> > dbmopen(%{"$db".'db'},"$datadir/$db", 0644) or die "dbmopen: $!";
> > link (("$datadir/$db".'.db'), ("$datadir/$db".'db.lock'));
> >
> >
> > }
>
> No, you're doing it wrong. Hard links *have* been used as ersatz
> locks, but the trick is to do the test for existence and the
> creation of the link in a single atomic step.
There are a lot of subtleties with locking. Just get LockFile::Simple
and be done with it.
David
------------------------------
Date: 14 Jun 2001 15:09:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: initialising multi-dimensional array
Message-Id: <9gak2q$lp2$2@mamenchi.zrz.TU-Berlin.DE>
According to Mark Grimshaw <m.grimshaw@salford.ac.uk>:
>
>
> Anno Siegel wrote:
> >
> > According to Mark Grimshaw <m.grimshaw@salford.ac.uk>:
> > >
> > >
> > > Mark Grimshaw wrote:
> > > >
> > > > Hi,
> > > >
> > > > How do I initialise everything in a multi-dimensional array to 0 (or any
> > > > variable for that matter)? Currently, all rows/column elements are
> > > > undef.
> > >
> > > Forgot to add, I don't know the number of rows/columns beforehand.
> >
> > In that case the word "everything" in your question makes no sense.
> > You can't initialize an array of unknown size.
> >
> > You should acquaint yourself with the way Perl treats an undefined
> > value in numeric context, and its interaction with warnings. You will
> > probably find you don't have to initialize the array after all.
> >
> > Anno
>
> It's not exactly a numeric context. I simply print the element value
> back to a browser. If it's undef it prints nothing. I want it to print
> 0. I can do this one of several ways but it's likely to involve a loop
> (or loop within that) hunting out and checking each element for undef.
>
> I was wondering if there was a special variable to do this for me as
> mentioned in my 3rd post.
>
> Perhaps I shouldn't have used the words 'initialise everything' but the
> words 'override the default undef setting for empty array slots'.
There is no such thing. But you can access an element as
$array[ $i] || 0;
or, to be more careful
defined $array[ $i] ? $array[ $i] : 0;
or many similar constructs. These will give you 0 for an undefined
element.
Anno
------------------------------
Date: 14 Jun 2001 17:45:26 +0100
From: nobull@mail.com
Subject: Re: initialising multi-dimensional array
Message-Id: <u9bsnrm3gm.fsf@wcl-l.bham.ac.uk>
Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:
> How do I initialise everything in a multi-dimensional array to 0 (or any
> variable for that matter)? Currently, all rows/column elements are
> undef.
Perhaps a more interesting question than "how" would be "why". As a
rule it is better to write your code to expect the array to start out
empty.
Rather than creating a big array of zerors consider peppering your
code with judicious use of "no warnings 'uninitialized'" or "|| 0".
If you really want to pre-populate a multi-dimensional array then
suppose you want @array to be a 3D array with elements $array[0][0][0]
to $array[5][4][3] all 0.
my @array = map { [ map { [ (0) x 4 ] } 1 .. 5 ] } 1 .. 6;
or if you value symmetry over efficiency:
my @array = map { [ map { [ map {0} 0 .. 3 ] } 0 .. 4 ] } 0 .. 5;
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 14 Jun 2001 10:36:06 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: initialising multi-dimensional array
Message-Id: <m3r8wnhy55.fsf@dhcp9-173.support.tivoli.com>
On Thu, 14 Jun 2001, m.grimshaw@salford.ac.uk wrote:
> It's not exactly a numeric context. I simply print the element
> value back to a browser. If it's undef it prints nothing. I want
> it to print 0. I can do this one of several ways but it's likely to
> involve a loop (or loop within that) hunting out and checking each
> element for undef.
>
> I was wondering if there was a special variable to do this for me as
> mentioned in my 3rd post.
>
> Perhaps I shouldn't have used the words 'initialise everything' but
> the words 'override the default undef setting for empty array
> slots'.
Sounds like the easiest solution would be to just print a literal 0
whenever the value to print is undefined. In fact, in most cases you
can just assume that a false value should be printed as 0:
for (@array) {
print $_ || 0;
}
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 14 Jun 2001 10:26:44 -0700
From: ben-fuzzybear@geocities.com (Ben Okopnik)
Subject: Re: initialising multi-dimensional array
Message-Id: <be30c829.0106140926.6616b004@posting.google.com>
Mark Grimshaw <m.grimshaw@salford.ac.uk> wrote in message news:<3B28D0CF.9878E9B2@salford.ac.uk>...
> I simply print the element value
> back to a browser. If it's undef it prints nothing. I want it to print
> 0. I can do this one of several ways but it's likely to involve a loop
> (or loop within that) hunting out and checking each element for undef.
unless ( defined $h{$x} ) { print 0; } else { print $h{$x}; }
Ben Okopnik
-=-=-=-=-=-
------------------------------
Date: Thu, 14 Jun 2001 16:19:57 +0100
From: "John Imrie" <john.imrie@pa.press.net>
Subject: Re: Memory Issues/File Slurping
Message-Id: <%D4W6.1426$h45.8724@news.uk.colt.net>
Godzilla! <godzilla@stomp.stomp.tokyo> wrote in message
news:3B280045.24D6E856@stomp.stomp.tokyo...
> Doug McGrath wrote:
>
> (snipped)
>
> > I'm open to ideas.
>
> Photonic Fleas have infested your Warp Drive fiber optic cables.
>
>
> Godzilla!
That was almost funny :)
------------------------------
Date: 14 Jun 2001 09:50:24 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Memory Issues/File Slurping
Message-Id: <m366dzjetr.fsf@dhcp9-173.support.tivoli.com>
On 13 Jun 2001, doug.mcgrath@us.telegyr.com wrote:
[snip]
> The main processing is in a package where I've declared the variable
> into which the file is slurped using "my", but outside the routine
> that reads the file. My research indicated that this would improve
> processing by not having to reallocate memory for it each time. I'm
> not pre-extending the variable, although I've tried that, and it
> didn't seem to help overall.
>
> However, as near as I can tell from ps, the memory isn't being
> reused; it just grows. Some judicious print statements revealed that
> slurping 5 files that were a total of about 6 MB increased the
> process space by 100 MB. Eventually, my system starts thrashing, and
> the whole process drags to a crawl.
One thing to watch out for is that you are letting a reference to the
data held by the lexical variable survive the scope of the variable.
When this happens, the lexical is reallocated at the next "my". If
the reference counts never go to zero, then this just keeps happening.
[snip]
> The other possibility that I've considered is that I may be
> accidentally keeping references hanging around, but I can't find
> them. All of my variables are declared with my, and I have "use
> strict" and "-w" on. This particular module returns an object, and
> I've also double-checked to ensure that I'm not accidentally keeping
> references to the hash that encapsulates the object (although the
> behavior looks as if that might be the case).
Ah, so you already thought of that. If the module returns an object,
doesn't that imply that a reference is surviving?
Sounds like we'll need to see at least some of the code.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 14 Jun 2001 11:13:45 -0400
From: "Antoine Beaupre (LMC)" <Antoine.Beaupre@lmc.ericsson.se>
Subject: Multiplexing stdin and stderr to screen and logfile
Message-Id: <3B28D4A9.108@lmc.ericsson.se>
Hi.
[introduction. You can jump to the "problem" section below]
I'm writing a script to analyze compilation output and various scripting
procedures.
The compilation procedure is controlled by a perl script which sometimes
needs to prompt the user for information.
Previously, what I did was to fork (open (LOGPROC, "|-")) to a logger
process which would process the messages given and display them or not
depending on their format. This went smoothly for STDOUT messages, line
per line.
However, when prompting a user, it gets more complex since the output is
*not* \n delemited. So <> doesn't work very well. What's more, there is
no generic way to know when a given "prompt" is complete in a buffer.
So what I did is that I displayed these prompt to STDERR and all went
fine. STDERR was not intercepted by the logger process. However, this
makes another problem: STDERR is not logged.
I considered a few options:
1- sending STDERR to STDIN: this defeats the purpose of sending the
prompts to STDERR in the first place
2- opening pipes duping STDERR and STDIN to the logger process. This is
the venue I'm exploring here.
[problem]
I tried to use the select() interface. Unfortunatly, I wasn't able to do
anything sensible with that. So I tried my luck with IO::Select. Same
results.
I "select" on the streams, and STDERR is *always ready*. I don't get it.
Here is the code that fires up the logger process:
sub openlogfile (;$$) {
my $logfile = shift @_;
$logfile = "logs/patch.log"
unless $logfile; # set a default logfile
# fork child process which will take care of the logging
my $pid;
pipe (LOGINPUT, LOG);
pipe (ERRINPUT, ERR);
if ($pid = fork) { # parent
# from now on, all STDOUT will pass through logger
close LOGINPUT;
close ERRINPUT;
select((select(LOG), $| = 1)[0]); # unbuffer LOG
select((select(ERR), $| = 1)[0]); # and ERR
open(STDOUT, ">&LOG") || # send stdout to logger process
warning "can't dup STDOUT";
open(STDERR, ">&ERR") || # send stderr to logger process
warning "can't dup STDERR";
print "forked logger child successfully";
print "output to logfile $logfile";
return $logfile;
} else { # child
use IO::Select;
close (OUT); close (ERR);
open (LOGFILE, "> $logfile") ||
die "can't open logfile $logfile (\"$!\"), stopped";
syswrite LOGFILE, "logger process $0 started on " . localtime() . "\n";
select((select(LOGFILE), $| = 1)[0]);
select((select(LOGINPUT), $| = 1)[0]);
select((select(ERRINPUT), $| = 1)[0]);
select((select(STDOUT), $| = 1)[0]);
my $log_line = "";
my $err_line = "";
my $log_cnt = 0;
my $err_cnt = 0;
my $plexer = IO::Select->new();
$plexer->add(\*ERRINPUT);
$plexer->add(\*LOGINPUT);
my $cnt = 3;
while ($cnt--) {
my @ready = $plexer->can_read();
foreach my $fh (@ready) {
my $buffer = "";
syswrite STDOUT, "ready: @ready, ".\*LOGINPUT." - ".
\*ERRINPUT."\n";
if ($fh eq \*LOGINPUT) {
syswrite STDOUT, "loginput ready\n";
while (sysread(LOGINPUT, $buffer, 1)) {
syswrite STDOUT, "$buffer";
syswrite LOGFILE, $buffer;
}
} elsif ($fh eq \*ERRINPUT) {
syswrite STDOUT, "errinput ready\n";
while (sysread(ERRINPUT, $buffer, 1)) {
syswrite STDOUT, $buffer;
syswrite LOGFILE, $buffer;
}
} else {
syswrite STDOUT, "unknwon stream ready: $fh\n";
}
}
}
syswrite LOGFILE, "logger process finished on " . localtime() . "\n";
exit; # important!
}
warn "this statement shouldn't have been executed";
exit; # NOT REACHED
}
Here is my test program:
#! /pub/is/bin/perl -w
use strict;
use lib '/vobs/kscm/Scripts';
use Patch::UI;
openlogfile("test.log");
print STDERR 'test\n';
print STDOUT 'test\n';
And here's the output:
lmcabea@tweed:~$ /vobs/kscm/Scripts/Patch/test_zone/test_log.pl
lmcabea@tweed:~$ ready: GLOB(0x1117a4), GLOB(0x11175c) - GLOB(0x1117a4)
errinput ready
test
ready: GLOB(0x1117a4), GLOB(0x11175c) - GLOB(0x1117a4)
errinput ready
ready: GLOB(0x1117a4), GLOB(0x11175c) - GLOB(0x1117a4)
errinput ready
lmcabea@tweed:~$
As you can see, "errinput" is *always* ready, even if the stream does
not have anymore data available, and loginput is *never* ready even
though there is some data ("test\n").
I'm completely off-track here. I've done some multiplexing apps in C
before without problems (a webserver!). I read the select() and
IO::Select doc (note that I converted all my print's to syswrite's and
<> and read's to sysread).
Please help. :)
Thanks
Antoine
--
La sémantique est la gravité de l'abstraction.
------------------------------
Date: Thu, 14 Jun 2001 11:24:53 -0400
From: "Antoine Beaupre (LMC)" <Antoine.Beaupre@lmc.ericsson.se>
Subject: Re: Multiplexing stdin and stderr to screen and logfile
Message-Id: <3B28D745.7000001@lmc.ericsson.se>
[sorry to answer my own message]
Well-well-well.. It seems to be that I haven't looked "deep" enough...
My test program used "print" also. I somehow figured that, being on the
other side of the pipes and in a seperate process, this non-logger
wouldn't have to use syswrite and friends.
This is really annoying! Does that mean that *any* perl program that
uses select() can't read from pipes that are stdio-buffered???
I am confused.
For the curious, the new test program and output:
#! /pub/is/bin/perl -w
use strict;
use lib '/vobs/kscm/Scripts';
use Patch::UI;
openlogfile(undef, "test.log");
syswrite STDERR, "test\n";
syswrite STDOUT, "test\n";
lmcabea@tweed:~$ /vobs/kscm/Scripts/Patch/test_zone/test_log.pl
test
test
lmcabea@tweed:~$
Note that I also have re-written the inner loop because it was stupidly
laid-out:
foreach my $fh (@ready) {
my $buffer = "";
if ($fh eq \*LOGINPUT) {
sysread(LOGINPUT, $buffer, 1);
syswrite STDOUT, $buffer;
syswrite LOGFILE, $buffer;
} elsif ($fh eq \*ERRINPUT) {
sysread(ERRINPUT, $buffer, 1);
syswrite STDOUT, $buffer;
syswrite LOGFILE, $buffer;
} else {
syswrite STDOUT, "unknwon stream ready: $fh\n";
}
}
[btw, is there no way to know how many chars are available on a stream
apart from calling a crazy ioctl? :)]
Thanks.
A.
Antoine Beaupre (LMC) wrote:
> Here is my test program:
>
> #! /pub/is/bin/perl -w
>
> use strict;
>
> use lib '/vobs/kscm/Scripts';
> use Patch::UI;
>
> openlogfile("test.log");
> print STDERR 'test\n';
> print STDOUT 'test\n';
>
> And here's the output:
>
> lmcabea@tweed:~$ /vobs/kscm/Scripts/Patch/test_zone/test_log.pl
> lmcabea@tweed:~$ ready: GLOB(0x1117a4), GLOB(0x11175c) - GLOB(0x1117a4)
> errinput ready
> test
> ready: GLOB(0x1117a4), GLOB(0x11175c) - GLOB(0x1117a4)
> errinput ready
> ready: GLOB(0x1117a4), GLOB(0x11175c) - GLOB(0x1117a4)
> errinput ready
>
> lmcabea@tweed:~$
>
> As you can see, "errinput" is *always* ready, even if the stream does
> not have anymore data available, and loginput is *never* ready even
> though there is some data ("test\n").
>
> I'm completely off-track here. I've done some multiplexing apps in C
> before without problems (a webserver!). I read the select() and
> IO::Select doc (note that I converted all my print's to syswrite's and
> <> and read's to sysread).
>
> Please help. :)
>
> Thanks
--
La sémantique est la gravité de l'abstraction.
------------------------------
Date: 14 Jun 2001 10:29:16 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Negative lookahead not working
Message-Id: <m3vglzhygj.fsf@dhcp9-173.support.tivoli.com>
On Thu, 14 Jun 2001, morgan@hahaha.org wrote:
> I'm having a hard time getting a negative lookahead working for me.
>
> I'm printing lines from a file, some of which look like this:
>
> @thing \w*XYZ
>
> And some look like this:
>
> @thing \w*
>
> (without "XYZ" at the end)
Are those "\w*" literal characters or are you just saying that there
are some word characters there? I'll assume the latter.
> I want to print every line but those that look like @thing \w*,
> i.e. those without the XYZ on the end.
Probably easiest to just do exactly what you want:
print unless /\@thing \w*/ && ! /XYZ$/;
> I tried:
>
> print unless /\@thing\s+\w*(?!XYZ)/;
This is going to be problematic as the "\w*" can match the "XYZ" which
then allows the "(?!XYZ)" to also match. If you don't like the above
solution, or you really need to do it in a single regex, you might get
by with a negative look-behind from the end:
print unless /\@thing \w*(?<!XYZ)$/;
Obviously, if "XYZ" is not really the pattern and the pattern instead
has one or more non-word characters, then this isn't going to work
(though the first example above still will).
> But that results in no lines beginning with @thing being printed at
> all.
>
> What am I doing wrong?
You're making a common mistake with negative lookahead -- forgetting
that it doesn't work very well if you mix it with quantifiers that can
produce at least partial matches.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 14 Jun 2001 13:56:31 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Negative lookahead not working
Message-Id: <m38zivaqsw.fsf@mumonkan.sunstarsys.com>
Morgan Fletcher <morgan@hahaha.org> writes:
> I want to print every line but those that look like @thing \w*,
> i.e. those without the XYZ on the end.
>
> I tried:
>
> print unless /\@thing\s+\w*(?!XYZ)/;
^^^
The greediness of \w* is causing problems with your lookahead. One
way around it is to be more specific about "XYZ on the *end*" -
end of word, or end of string?
print unless /\@thing \s+ \w*XYZ \b/x; # word end
print unless /\@thing \s+ \w*XYZ $/x; # string end (newline friendly)
HTH
--
$.=$[|3*rand;$_=67014523;END{print@_};*UNIVERSAL::AUTOLOAD=sub{&A;pop->();++
$#;*A};$.++,*[=*]=*\=sub{$].=pop.(--$#%2?q: ::qq::)};*#=sub{split m, (?<=^.{2})
(.{$.}),x,shift};@#=qw[just another Perl hacker];*A=*AUTOLOAD=sub{split"::",$A;
&]};map{splice@#,$_,1,&#($#[$_])}3,1;$_="@{[@#[m$.$g]]}";s;P;,p;;eval;$\.="\n"
------------------------------
Date: Thu, 14 Jun 2001 16:01:19 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: new to perl need help with concordance
Message-Id: <3b28df1b.1322307267@news.isholf.is>
On Wed, 13 Jun 2001 18:22:19 -0700, "IlIIllllI1"
<iliilllli1@hotmail.com> wrote:
>I can't figure out how to print the information in @split so that
>$string will be lined up vertically.
A very strange and badly worded question.
The answer may be:
for (@split) { print "$_\n"; }
But then again, it may not.
Regards,
Helgi Briem
------------------------------
Date: Thu, 14 Jun 2001 11:26:28 -0400
From: Korac <korac@dirig.com>
Subject: Re: newbie-- re:win32 system() calls -- rmdir /s/q
Message-Id: <3B28D7A3.FB79F42A@dirig.com>
Jay Tilton wrote:
> On Wed, 13 Jun 2001 15:41:51 -0400, Korac <korac@dirig.com> wrote:
>
> >I'm having trouble using "rmdir /s/q dirname" within the sytem call,
> >I've tried putting it in all one string, using join to jam it into a
> >variable and it still won't execute properly. Is there something
> >critical I'm missing here?
>
> >$remdir_cmd = "rmdir /s/q "; # extra space at end
>
> For its built-in functions, perl can understand forward slashes as
> separating directory names and will translate them into what Win32 expects,
> but it will not do so for calls to external commands.
>
> Win32 will bark about 'invalid switch' if you use forward slashes to
> separate directory names. Use backslashes.
>
> $remdir_cmd = 'rmdir \s\q';
Only problem is, it doesn't work. Even in a windows shell, using "rmdir \s\q
somedir" won't delete the directory, only the /s/q option works, at least in
the commandline. If I preface each / with a \, it only sees "rmdir sq
somedir" which of course fails. I'm sure its a problem that has been addressed
somewhere. Thanks though.
------------------------------
Date: Thu, 14 Jun 2001 15:29:47 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: newbie-- re:win32 system() calls -- rmdir /s/q
Message-Id: <u3d93xeoo.fsf@wrq.com>
tiltonj@erols.com (Jay Tilton) writes:
>On Wed, 13 Jun 2001 15:41:51 -0400, Korac <korac@dirig.com> wrote:
>
>>I'm having trouble using "rmdir /s/q dirname" within the sytem call,
>>I've tried putting it in all one string, using join to jam it into a
>>variable and it still won't execute properly. Is there something
>>critical I'm missing here?
>
>>$remdir_cmd = "rmdir /s/q "; # extra space at end
>
>For its built-in functions, perl can understand forward slashes as
>separating directory names and will translate them into what Win32 expects,
>but it will not do so for calls to external commands.
>
>Win32 will bark about 'invalid switch' if you use forward slashes to
>separate directory names. Use backslashes.
I don't think these are directory paths. /s/q are command line
switches to rmdir which are comparable to rm's -rf options.
>
> $remdir_cmd = 'rmdir \s\q';
>
If you want a portable solution, use the Perl function rmtree() from the
File::Path module
perldoc File::Path
--
-- Steve __
------------------------------
Date: Thu, 14 Jun 2001 11:56:31 -0400
From: Korac <korac@dirig.com>
Subject: Re: newbie-- re:win32 system() calls -- rmdir /s/q
Message-Id: <3B28DEAF.95289B7E@dirig.com>
Steve Allan wrote:
> tiltonj@erols.com (Jay Tilton) writes:
>
> >On Wed, 13 Jun 2001 15:41:51 -0400, Korac <korac@dirig.com> wrote:
> >
> >>I'm having trouble using "rmdir /s/q dirname" within the sytem call,
> >>I've tried putting it in all one string, using join to jam it into a
> >>variable and it still won't execute properly. Is there something
> >>critical I'm missing here?
> >
> >>$remdir_cmd = "rmdir /s/q "; # extra space at end
> >
> >For its built-in functions, perl can understand forward slashes as
> >separating directory names and will translate them into what Win32 expects,
> >but it will not do so for calls to external commands.
> >
> >Win32 will bark about 'invalid switch' if you use forward slashes to
> >separate directory names. Use backslashes.
>
> I don't think these are directory paths. /s/q are command line
> switches to rmdir which are comparable to rm's -rf options.
>
> >
> > $remdir_cmd = 'rmdir \s\q';
> >
>
> If you want a portable solution, use the Perl function rmtree() from the
> File::Path module
>
> perldoc File::Path
>
> --
> -- Steve __
nice! thanks.
------------------------------
Date: 14 Jun 2001 10:03:34 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: newbie-- re:win32 system() calls -- rmdir /s/q
Message-Id: <m31yonje7t.fsf@dhcp9-173.support.tivoli.com>
On Thu, 14 Jun 2001, tiltonj@erols.com wrote:
> On Wed, 13 Jun 2001 15:41:51 -0400, Korac <korac@dirig.com> wrote:
>
>>I'm having trouble using "rmdir /s/q dirname" within the sytem call,
>>I've tried putting it in all one string, using join to jam it into a
>>variable and it still won't execute properly. Is there something
>>critical I'm missing here?
>
>>$remdir_cmd = "rmdir /s/q "; # extra space at end
>
> For its built-in functions, perl can understand forward slashes as
> separating directory names and will translate them into what Win32
> expects, but it will not do so for calls to external commands.
>
> Win32 will bark about 'invalid switch' if you use forward slashes to
> separate directory names. Use backslashes.
>
> $remdir_cmd = 'rmdir \s\q';
Except that "/s" and "/q" *are* switches to the rmdir command on
DOS/Win32.
I expect the actual problem is that rmdir is a built-in command of
cmd.exe, so $remdir_cmd probably needs to be:
$remdir_cmd = 'cmd /c rmdir /s/q ';
--
Ren Maddox
ren@tivoli.com
------------------------------
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 1134
***************************************