[17886] in Perl-Users-Digest
Perl-Users Digest, Issue: 46 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 12 06:05:42 2001
Date: Fri, 12 Jan 2001 03:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <979297510-v10-i46@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 12 Jan 2001 Volume: 10 Number: 46
Today's topics:
Re: Apply XPath expression to XML::DOM (Eric Bohlman)
Re: Archive::Zip - any user comments? <geoff-at-farmline-dot-com@127.0.0.1>
Re: can I chdir(DIRHANDLE)? (Rafael Garcia-Suarez)
Re: Deleting PDF pages <tward10@jaguar.com>
Re: Finding ranges in a list of integers (Eric Bohlman)
Re: Help this newbie learn please :) <hafateltec@hotmail.com>
Re: Jobs: Senior Software Engineer (Tad McClellan)
Re: Jobs: Senior Software Engineer (Randal L. Schwartz)
kill with SIGTERM not working <nickw@ot.com.au>
Re: match from the end or match the last (Martien Verbruggen)
Re: match from the end or match the last <wyzelli@yahoo.com>
Re: Period problem (Garry Williams)
perl-5.6.0 for Win32 a565a87@my-deja.com
Re: regex help, please <bart.lateur@skynet.be>
Regular Expression <vidulats@yahoo.co.uk>
Re: Regular Expression nobull@mail.com
Re: Returning a filename from FILEHANDLE (Rafael Garcia-Suarez)
Re: Shall use a reference instead? <michael-a-mayo@worldnet.att.net>
Re: Shall use a reference instead? <iltzu@sci.invalid>
Re: variable (Chris Fedde)
Re: Win32-Process output <dave_at_hm@hotmail.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Jan 2001 07:02:51 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Apply XPath expression to XML::DOM
Message-Id: <93ma6r$1op$3@bob.news.rcn.net>
Bjoern Hoehrmann <bjoern@hoehrmann.de> wrote:
> Hi,
> I've got XML::DOM::Document or XML::DOM::Node object and i want to use
> XPath to get some nodes of this node-set. There is XML::XPath on CPAN,
> but it doesn't seem to support this. Is this correct? If yes, why and
> what can I do to reach my goal?
XML::XPath uses its own object model for XML nodes rather than DOM.
XML::XQL, which implements an older language that's basically a subset of
XPath, does work on DOM nodes; if you don't need to use arbitrary XPath
expressions coming from outside your program, it might do the job.
------------------------------
Date: Fri, 12 Jan 2001 10:02:59 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: Archive::Zip - any user comments?
Message-Id: <93mklr$sj8$1@soap.pipex.net>
"brian d foy" <comdog@panix.com> wrote in message
news:comdog-F506A4.13011111012001@news.panix.com...
: In article <93kj9s$sdv$1@soap.pipex.net>, "Geoff Winkless"
: <geoff-at-farmline-dot-com@127.0.0.1> wrote:
:
: > Has anyone any idea how good Archive::Zip is - it's only at 0.09 which
: > doesn't instil huge amounts of confidence, but then it hasn't changed
since
: > May - which probably either means it's working ok or the author has
given up
: > on it (!!)
:
: i always had problems with it creating "inconsistent headers" or
: some such. i ended up using an external zip program to do that
: work. otherwise, i liked the module.
So no problems with decompression? I only want to use it to extract files,
not create archives.
Thanks
G
------------------------------
Date: Fri, 12 Jan 2001 07:52:01 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: can I chdir(DIRHANDLE)?
Message-Id: <slrn95tdte.ugn.rgarciasuarez@rafael.kazibao.net>
Antoine Beaupre (LMC) wrote in comp.lang.perl.misc:
> Hello!
>
> I've read somewhere (???) that instead of doing:
>
> use Cwd;
> $from = cwd;
> chdir ("/somewhere/else");
> # do something
> chdir $from;
>
> I could do something like:
>
> opendir(FROM, ".");
> # do something
> chdir(FROM);
No:
$ perl -e 'opendir B,"." or die $!;' -e 'chdir B or die $!'
No such file or directory at -e line 2.
See 'perldoc -f opendir' for info on dirhandles.
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Fri, 12 Jan 2001 07:48:50 -0000
From: "Trevor Ward" <tward10@jaguar.com>
Subject: Re: Deleting PDF pages
Message-Id: <93mct3$5s010@eccws12.dearborn.ford.com>
If the PDF file is not encrypted then I think you can.
By reading in the PDF file, finding the page markers, then deleting
everything after this.
A good source of reference is the Adobe web site which has a full technical
manual about
PDF files, format and encryption etc.
Have fun sifting.
<mrapropos@hotmail.com> wrote in message news:93l62q$oun$1@nnrp1.deja.com...
> Hi!
>
> Is it possible to delete whole pages from a PDF file using Perl? I've
> found plenty of modules to convert or create PDF files, but not clobber
> whole parts of already created files.
>
> For example, I would like to be able to find out how many pages are in
> the PDF and then be able to delete page 9 and pages 12-15. The content
> of the pages doesn't matter so much, just being able to delete them is
> the key.
>
> Any help would be ... helpful!
>
> Thanks!
>
>
> Sent via Deja.com
> http://www.deja.com/
------------------------------
Date: 12 Jan 2001 06:11:47 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Finding ranges in a list of integers
Message-Id: <93m773$1op$2@bob.news.rcn.net>
Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> I've a list of integers, sorted in ascending numerical order, like this:
> qw/1 3 4 5 6 7 9 11 12 13 15 16 18 19 20 21 23 24/
> and I want to turn it into a string representation : a list of integers
> separated by commas, but where ranges of three or more consecutive
> integers are written like '1-3'. E.g. the solution for the above list
Set::IntSpan does exactly what you want.
------------------------------
Date: Fri, 12 Jan 2001 15:10:15 +1000
From: "Mike McPherson" <hafateltec@hotmail.com>
Subject: Re: Help this newbie learn please :)
Message-Id: <93m497$5h3$1@brokaw.wa.com>
Wyzelli thank you, my end code looks as such and works perfectly.
#!/usr/bin/perl -w
# Little snip I created to convert ASCII to Characters and vice-versa.
if (@ARGV){
$what = (shift @ARGV);
}
else {
die "\nUsage ASCII or CHAR: $!\n";
}
if ($what eq 'ASCII') {
print "\nOption ASCII\n";
print "\nPlease enter the ASCII Number you wish to convert to a
character --->";
$ascii = <STDIN>;
$convert_ascii = chr($ascii);
print "\nYour conversion is chr/($ascii) equals $convert_ascii\n";
}
elsif ($what eq 'CHAR') {
print "\nOption CHAR\n";
print "\nPlease enter the Character you wish to convert to ASCII --->";
$char = <STDIN>;
$convert_char = ord($char);
print "\nYour conversion is $char equals $convert_char\n";
}
Wyzelli <wyzelli@yahoo.com> wrote in message
news:x3S66.22$Mx3.9572@vic.nntp.telstra.net...
> "Mike McPherson" <hafateltec@hotmail.com> wrote in message
> news:93go33$cho$1@brokaw.wa.com...
> You are testing to see if $what eq ASCII without seeing if $what is
> defined first. If the script was called with no arguments, then $what
> will be uninitialised, hence your error.
>
> You should think of a way to only test if $what has been set to be ASCII
> if either $what has been defined, or maybe if @ARGV has been defined.
>
> A common way would be to test for @ARGV first, and if unset, go to the
> sub which reports correct usage immediately, rather than using any
> undefined variables.
>
> if (@ARGV){
> $what = (shift @ARGV);
> }
> else {
> die "\nUsage ASCII or CHAR: $!\n";
> }
>
> and remove the else block from the end of your code.
>
> You also want to start using indenting which will make your code much
> easier to maintain.
>
> Wyzelli
> --
------------------------------
Date: Thu, 11 Jan 2001 22:22:32 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Jobs: Senior Software Engineer
Message-Id: <slrn95su3o.19a.tadmc@tadmc26.august.net>
Terrence Brannon <brannon@lnc.usc.edu> wrote:
>dha@panix2.panix.com (David H. Adler) writes:
>> On Tue, 09 Jan 2001 17:58:14 GMT, jatgal wrote:
>>
>> >Title: Senior Software Engineer / Software Architect
>>
>> >Availability:
>>
>> Irrelevant.
>>
>> You have posted a job posting or a resume in a technical group.
>
>He posted a Perl job posting in a Perl newsgroup. Because this is
>where Perl programmers are. I don't mind that.
Discussing jobs here will bring the Recruiters and their
shotgun-approach machine-posted spam in great teeming
slimey globs.
There will be 1000 posts a day here.
I would mind _that_.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 11 Jan 2001 22:20:24 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Jobs: Senior Software Engineer
Message-Id: <m14rz5uw9j.fsf@halfdome.holdit.com>
>>>>> "Terrence" == Terrence Brannon <brannon@lnc.usc.edu> writes:
Terrence> He posted a Perl job posting in a Perl newsgroup. Because this is
Terrence> where Perl programmers are. I don't mind that.
It's not yours to choose. Policy is established by the people who
bring you the news, and they hang out in news.admin.misc. It's not
anything that can be voted on by the users of this group, so don't
even start.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Fri, 12 Jan 2001 16:15:29 +1100
From: "Nick Wilson" <nickw@ot.com.au>
Subject: kill with SIGTERM not working
Message-Id: <979276513.559877@emissary>
I posted this a couple of days ago but my newsreader was playing
around,
I have a perl script (exec.pl) which creates another process via
$pid= open FH, "runtest.pl |" || die "could not run $cmd\n";
which is eventually killed after a timeout.
kill 15, $pid
Now inside my runtest.pl I set up a sig handler for term (15).
$SIG{TERM} = \&got_signal;
sub got_signal {
print "runtests.pl: got_signal";
.. do other stuff....
}
Trouble is I can't seem to get the signal handler to work. If I use a
command
line to kill -15 runtest.pl then it works, but when called from another perl
script it doesn't work ?
Can anyone point me to what is going on ?
Thanks,
nickwatot.com.au
------------------------------
Date: Fri, 12 Jan 2001 18:40:33 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: match from the end or match the last
Message-Id: <slrn95td7h.50v.mgjv@martien.heliotrope.home>
On Fri, 12 Jan 2001 12:29:47 +0800,
John Lin <johnlin@chttl.com.tw> wrote:
> Dear all,
>
> In regular expression, is there a modifier or any idiomic way to
> match from the end (backward)? Let's say if the modifier is 'b', then
>
> ($_ = 'xyzxyzxyz') =~ s/y/Y/b; print;
>
> results in:
>
> 'xyzxyzxYz' instead of 'xYzxyzxyz'
Is the question really something like : How do I only change the _last_
occurence of a match with s///
Regular expressions in Perl always match forward. But in this particular
case you can make use of the fact that quantifiers, by default, are
greedy:
s/(.*)y/Y/;
or, you can reverse the string, and reverse it back for more complex
cases.
> ($_ = <<EOF) =~ s/<form.*?<\/form>//b; print;
> line1
> line2
><form>in form1</form>
> line3
><form>in form2</form>
> line4
> EOF
You'll need the trick above, and the /s modifier, to make sure that .
matches a newline:
s#(.*)<form.*?</form>#$1#s;
You'll also note that I used a different delimiter, to avoid the leaning
toothpick syndrome.
If this is HTML you're matching, you might be better off using a real
parser, instead of trying to do this with regular expressions. HTML
itself cannot really be parsed with REs, unless there are some
limitations imposed, and the sort of HTML that you normally find out
there certainly won't be parseable easily :)
> P.S. This question is provided by Judy <ckuo03@yahoo.com>
Why doesn't Judy post this question herself?
Martien
PS. Interestingly enough, I couldn't find anything about this in the
FAQ. If no one knows any documentation that talks about this, I might
write one and submit it.
--
Martien Verbruggen |
Interactive Media Division | This matter is best disposed of from
Commercial Dynamics Pty. Ltd. | a great height, over water.
NSW, Australia |
------------------------------
Date: Fri, 12 Jan 2001 18:44:22 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: match from the end or match the last
Message-Id: <oNz76.2$gQ3.851@vic.nntp.telstra.net>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn95td7h.50v.mgjv@martien.heliotrope.home...
> On Fri, 12 Jan 2001 12:29:47 +0800,
>
> s/(.*)y/Y/;
>
Missing $1 is the substitution? :) It aint that late in Sydney yet....
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: Fri, 12 Jan 2001 05:57:09 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Period problem
Message-Id: <V0x76.213$vB3.7442@eagle.america.net>
On Thu, 11 Jan 2001 19:57:38 -0700, John Bickmore
<mrbikejoc@qwest.net> wrote:
>Perl interprets the period between Schema and Table2 as something
>other than a period, causing a compilation error. I have tried every
>way I can think of to hack around this but to no avail.
>
> my $table = 'Schema.Table2';
> my $sql = "select F1 as Field1, F2 as Field2,
> from Table1, $table";
>
>Other attempts:
>
> "Schema\.Table2"
> "Schema"."\."."Table2"
>
>and so on....
No compile error on the code you posted. I guess you're not showing
us the real code. You also failed to copy/paste the error message.
There is nothing special about a period inside of either q// or qq//.
See the perlop manual page.
$ perl -Mstrict -wl
my $table = 'Schema.Table2';
my $sql = "select F1 as Field1, F2 as Field2,
from Table1, $table";
print $table;
print $sql
__END__
Schema.Table2
select F1 as Field1, F2 as Field2,
from Table1, Schema.Table2
$
--
Garry Williams
------------------------------
Date: Fri, 12 Jan 2001 08:53:39 GMT
From: a565a87@my-deja.com
Subject: perl-5.6.0 for Win32
Message-Id: <93mgmi$tlb$1@nnrp1.deja.com>
Hi Everyone,
I'm attempting for the first time to compile the stable Win32 release
of 5.6.0 that I downloaded from CPAN. I've never compiled the source
for perl before and I have a question or two.
My environment is the cmd line in NT4. Using nmake (MSVC 6.0).
In setting up my build area, I isolated all of the Win32 related
material from the stable download and put it into a separate directory
(mywin32perl). Inside mywin32perl, I have the Win32 folder with its
contents, and for good measure I took all the files from the top level
root of the stable download and replicated them inside the Win32
directory as well, so that if there were any files that should have
been in the Win32 from the stable that weren't, they're in there now as
well as outside.
On the command line I bored down into my path C:\perl\mywin32perl\win32
and typed "nmake/a makefile" and the build started in the window pane.
Seemingly so far so good.
After about a minute, the build seizes up:
link -subsystem:console -out:..\miniperl.exe @C:\TEMP\nma00146.
LINK : warning LNK4089: all references to "USER32.dll" discarded
by /OPT:REF
cd .. && miniperl minimod.pl > lib\ExtUtils\Miniperl.pm
The system cannot find the path specified.
NMAKE : fatal error U1077: 'cd' : return code 'ox1'
---
What happened? How do I proceed? What do I need to do in order to
correct the error in this build?
Thank you for any help that you can provide.
-Rob
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 12 Jan 2001 09:28:03 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: regex help, please
Message-Id: <9hjt5t0orgathc84kdie6nonmutiet02jf@4ax.com>
Stan Brown wrote:
>>Note that there are alphabetic characters that aren't present in the
>>above list.
>
> ?? when I was in school the alphabet consisted of a through z, what am
> I missing here?
Accented characters. Look at the characters in ISO-Latin-1.
--
Bart.
------------------------------
Date: Fri, 12 Jan 2001 07:30:05 -0000
From: <vidulats@yahoo.co.uk>
Subject: Regular Expression
Message-Id: <t5tcjt8sttaj91@corp.supernews.com>
Hello,
I'm reading a line from the file which is :
print "The output is x = $x, y= $y,z=$z";
my $Temp[0] contains x=10
$Temp[1] contains y=100
$Temp[2] contains z=110
I want to replace the line in the file as
print "The output is x = 10, y= 100,z=110";
How do i write regular expression for this??
Thanx in advance
-vidula
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: 12 Jan 2001 08:43:20 +0000
From: nobull@mail.com
Subject: Re: Regular Expression
Message-Id: <u9wvc1hy5r.fsf@wcl-l.bham.ac.uk>
<vidulats@yahoo.co.uk> writes:
> Subject: Regular Expression
Huh? That's not a very good explaination of your question. Remeber
that usenet groups are archived as a searchable information resource.
Well thought out subject lines are vital to make this a valuable
resource as thread subject lines are what people see in a list of
search hits.
The fact that you are comming here to receive rather than give does
not mean that you should come here with the mind-set "I only take - I
have nothing to give back". People with that mind-set soon find they
are made to feel unwellcome. They usually react to being made to feel
unwellcome by complaining that this group is unfriendly to newcommers.
They are wrong - this group is unfriendly to freeloaders.
Your question is in essense: "How can I expand variables in text strings?"
Which, BTW, is a FAQ.
> I'm reading a line from the file which is :
> print "The output is x = $x, y= $y,z=$z";
>
> my $Temp[0] contains x=10
> $Temp[1] contains y=100
> $Temp[2] contains z=110
>
> I want to replace the line in the file as
>
> print "The output is x = 10, y= 100,z=110";
>
> How do i write regular expression for this??
You can't. Any more than you can use nails to build a house.
First rearrange @Temp into a more appropriate structure namely a hash
keyed on the LHS of the = and with values containing the RHS.
my %substitutes = map { /(.+?)=(.*)/ } @Temp;
# Now %substitutes = ( x=>10, y=>100, z=>110 )
For the remainder of the solution see FAQ.
In future please consult the FAQ _before_ you post.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 12 Jan 2001 07:43:43 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Returning a filename from FILEHANDLE
Message-Id: <slrn95tdds.ugn.rgarciasuarez@rafael.kazibao.net>
Dan Sugalski wrote in comp.lang.perl.misc:
> Julian Cook/Sherab Gyatso <president@webticker.com> wrote:
> > I found the answer thanks to Deja.com. For anyone else using deja who may
> > have this same
> > question.....
> > The answer is no.
>
> Actually, the answer is "it depends on your platform". Some can, some can't.
> VMS can, and I think if you're really clever with XS code you can get the
> info out of at least some of the unices.
And probably not in all cases. What if the file associated to a
FILEHANDLE is associated to several directory entries (a.k.a.
hardlinks?) What if the file has been renamed, deleted, or moved in
another part of the same filesystem after it was open?
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
use overload '""' => sub { print "Just another Perl hacker,\n" };
$_ = bless {}; print;
------------------------------
Date: Fri, 12 Jan 2001 08:26:37 GMT
From: "Michael Mayo" <michael-a-mayo@worldnet.att.net>
Subject: Re: Shall use a reference instead?
Message-Id: <1dz76.807$LZ1.46766@bgtnsc05-news.ops.worldnet.att.net>
"Ilmari Karonen" <iltzu@sci.invalid> wrote in message
> The point is that you can only use it _as an object_ through a
> reference, since both bless() and method calls require one.
> One can, however, access the object internals directly:
> push @foo, 'four'; # let's change it! look mom, no refs!
After thinking this over for a while, I'm really not sure what to conclude. It
seems that there is some merit for considering the blessed thingie the object,
and some merit for considering the reference to the blessed thingie the object.
Perl takes sort of a hybrid approach between the two.
I suppose the issue is more complicated than I originally realized. Thanks for
bringing this up.
-Mike
------------------------------
Date: 12 Jan 2001 10:23:47 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Shall use a reference instead?
Message-Id: <979294357.25187@itz.pp.sci.fi>
In article <1dz76.807$LZ1.46766@bgtnsc05-news.ops.worldnet.att.net>, Michael Mayo wrote:
>
>After thinking this over for a while, I'm really not sure what to conclude. It
>seems that there is some merit for considering the blessed thingie the object,
>and some merit for considering the reference to the blessed thingie the object.
>Perl takes sort of a hybrid approach between the two.
No, not really. The blessed thingy is the object, period.
my @foo; # not a blessed thingy, yet
my $bar = \@foo; # an ordinary reference..
print "\$bar -> $bar\n"; # ..pointing to an array
bless \@foo, 'Foobar'; # now @foo is an object..
print "\$bar -> $bar\n"; # ..and $bar points to it
my $baz = \@foo; # we can take as many refs..
print "\$baz -> $baz\n"; # ..as we want
bless $bar, 'Barfoo'; # and reblessing the object..
print "\$bar -> $bar\n"; # ..through any of them..
print "\$baz -> $baz\n"; # ..has the same effect
BTW, if you post and mail the same message, please note that in the
message body. Most people, like me, read their mail before news, and
it can be annoying to find that one has already replied privately to a
message before seeing it in the newsgroup.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: Fri, 12 Jan 2001 05:45:09 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: variable
Message-Id: <FRw76.886$B9.192336384@news.frii.net>
In article <slrn95sn8t.jgc.mgjv@verbruggen.comdyn.com.au>,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>On Thu, 11 Jan 2001 23:38:03 GMT,
> Chris Fedde <cfedde@fedde.littleton.co.us> wrote:
>> In article <slrn95sgdr.jgc.mgjv@verbruggen.comdyn.com.au>,
>> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>>>On Thu, 11 Jan 2001 05:11:07 GMT,
>>> Chris Fedde <cfedde@fedde.littleton.co.us> wrote:
>>>> In article <x7n1cy4sln.fsf@home.sysarch.com>,
>>>> Uri Guttman <uri@sysarch.com> wrote:
>>>>>>>>>> "CF" == Chris Fedde <cfedde@fedde.littleton.co.us> writes:
>>>>>
>>>>> CF> $/ = '';
>>>>>
>>>>>why the paragraph mode? it doesn't gain anything when you mung single
>>>>>chars.
>>>>
>>>> avoid an explicit loop.
>>>
>>>$/ = '' puts input in paragraph mode, which will read paragraphs at a
>>>time. I think you wanted to set it to undef, which will return the
>>>whole file in a single call to <>. Correct?
>>>
>>
>> There was only one paragraph after the __END__.
>
>People will read your code, and copy and paste it, change the input,
>and not realise why it suddenly doesn't work as they think it should
>work. After all, Mr. Fedde said that this would avoid the explicit
>loop. Don't see the followups as criticism, but as extra explanations
>of what's going on, if not for your benefit, then for others who are
>reading this thread, and who didn't know about how $/ modifies the
>reading of input.
>
Why do so many people equate a short answer as one that is
defensive? Since my goal could be made by reading one paragraph
that's what my code did. I also used the cutsie technique of using
the OP as data for the code sample. Reading one paragraph as I
did prevented the code from eating up my signature too.
But this is rationalization and off topic. I accept the criticism
leveled by Mr. Guttman. And also to yours, Mr Verbruggen. My
example was not sufficiently general nor sufficiently robust for
use in a mission critical application. It wasn't even correct for
that matter.
chris
--
This space intentionally left blank
------------------------------
Date: Thu, 11 Jan 2001 21:21:46 -0800
From: Dave E <dave_at_hm@hotmail.com>
Subject: Re: Win32-Process output
Message-Id: <3A5E946A.6BA3DC85@hotmail.com>
I've figured this out and am replying to my own post for those searching the
archives. (hopefully sparing them the days I've spent on this)
to use redirection from Win32::Process to a file, you need to invoke a
separate command processor like this:
(well, it doesn't have to be "exactly" like this -- "walk this way", said
Egor with a limp ;)
$cmdinterp = "c:\\winnt\\cmd.exe";
$commandline = "$cmdinterp /c pulist $computer >$tempfile";
unless (Win32::Process::Create($process, $cmdinterp, $commandline, '0',
'NORMAL_PRIORITY_CLASS', '.')) {
&error_stop("Unable to start pulist process");
}
$process->Wait(10000); # wait up to 10s for process to finish
$process->GetExitCode($exit_code );
if ($exit_code != 0) { # if process timed out -- exit codes may vary for
other applications
$process->Kill(0);
&error_collect("pulist killed on $computer, exit code: $exit_code");
} else { # process finished normally
# do whatever here
}
Anyway, this seems to work though I'll not vouch for how well NT deals with
killed processes. Task manager didn't show any extras hanging around after
so I'm guessing they are actually dieing.
If anyone knows how to pipe from the process back into Perl without using a
temp file, or a better way in general, please (PLEASE!) let me know, the
above seems like such a hack.
David....
Dave E wrote:
> Hi,
>
> Anyone know how to pipe the output of a process started via
> Win32-Process back into Perl? Willing to tell me?? ('cause I can't
> figure it out)
>
> I want to do this:
>
> open(PLIST, "pulist |");
> while (<PLIST>) {
> print $_; # okay, I want to do more here but this is a good
> test
> }
> close(PLIST);
>
> EXCEPT -- I want to be able to timeout pulist (an NT resource kit
> utility) if it hangs (which it has a habbit of doing)
>
> so, I'm trying to use Win32::Process to start pulist because I can
> timeout and kill it if it misbehaves. But, the docs don't show any way
> to get the output of the process back into Perl.
>
> Is there anyway to pipe the results of processes started with
> win32-process back into the initiatiing program? Even a way to redirect
> the output to a file that I could later read would be okay (not perfect
> but okay...)
>
> Is there another way to deal with misbehaving external apps called from
> within a Perl script on an NT box?
>
> I'm really stuck here - everything works in my script except for pulist
> hanging once in a while - and I've spent days running around is circles,
> reading docs until my head spins, trying to figure this out.
>
> David...
>
> just a post-newbie crawling and scratching my way to guru -- When I
> get there, I'll have a real tag line. ;)
------------------------------
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 V10 Issue 46
*************************************