[17888] in Perl-Users-Digest
Perl-Users Digest, Issue: 48 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 12 11:10:38 2001
Date: Fri, 12 Jan 2001 08:10:16 -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: <979315816-v10-i48@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 12 Jan 2001 Volume: 10 Number: 48
Today's topics:
Re: Net::Telnet question <neil@alaweb.com>
Parsing the URL for Hidden variables <seppy@chartermi.net>
Re: regex help, please (Eric Bohlman)
Re: Regular Expression (Bernard El-Hagin)
Re: Returning a filename from FILEHANDLE (Martien Verbruggen)
sed (unix) <Per-fredrik.Pollnow@epk.ericsson.se>
Re: sed (unix) (Rafael Garcia-Suarez)
Re: Shall use a reference instead? <michael-a-mayo@worldnet.att.net>
Re: Shall use a reference instead? (Mark Jason Dominus)
Re: Shall use a reference instead? (Anno Siegel)
Re: Win32-Process output <jjgreen@cisco.com>
Re: Win32-Process output dtbaker_dejanews@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 12 Jan 2001 09:57:31 -0600
From: "Neil" <neil@alaweb.com>
Subject: Re: Net::Telnet question
Message-Id: <t5uab7aekqas28@corp.supernews.com>
Thanks Jay ! I appreciate this very much ... I started to think I was going
batty ...LOL!
Sincerely,
Neil
"Jay Rogers" <jay@rgrs.com> wrote in message
news:82lmshhpvq.fsf@shell2.shore.net...
> "Neil" <neil@alaweb.com> writes:
> > I assumed, after reading the Net::Telnet docs, that $core_log_fh would
> > return the filehandle and be non-zero, and therefore no error - and no
error
> > log entry.
>
> Yes, that's a bug in the input_log() and output_log() routines.
>
> It'll be fixed in version 3.03. In the meantime, here's a patch
> for version 3.02. Cut and paste it to a "patchfile", cd to the
> directory containing the Telnet.pm that needs to be patched, and
> execute:
------------------------------
Date: Fri, 12 Jan 2001 09:38:28 -0500
From: "Brian E. Seppanen" <seppy@chartermi.net>
Subject: Parsing the URL for Hidden variables
Message-Id: <3A5F16E4.3FFDA799@chartermi.net>
I'm trying to modify a pre-existing script that provides a guestbook to
users. The only thing I need to do is set it up to pass a hidden
variable so the proper users guestbook is used. The script is very old,
and I don't want to rewrite it (I really don't know enough perl to do so
anyways) using CGI. I'm hoping someone can help me figure out how I can
in parse out the hidden variables from the URL. How does the cgi get
the info from the URL? Is it an ARGV[0] or is it an Environmental
Variable?
Also how would I take the variable that is passed, lets call it username
and strip it to one character. for example.
$username = 'bseppanen'
$initial = 'b'
I'd appreciate any help.
Brian Seppanen
Charter Communications
Regional Data Center 906-228-4226 ext 23
Marquette, MI seppy@chartermi.net
------------------------------
Date: 12 Jan 2001 11:44:11 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: regex help, please
Message-Id: <93mqmb$b6n$4@bob.news.rcn.net>
Stan Brown <stanb@panix.com> wrote:
> In <t5rj26jq5dmq18@corp.supernews.com> gbacon@HiWAAY.net (Greg Bacon) writes:
>> - abcdefghijklmnopqrstuvwxyz
>> - ABCDEFGHIJKLMNOPQRSTUVWXYZ
>> - 0123456789
>> - '_', '-', ' ', '#', '/', '%', '.', '(', ')'
>>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?
In alt.folklore.urban, there's an initialism called "TWIAVBP" that's used
as a response to ethnocentric statements. It stands for "The World Is A
Very Big Place." Get the hint?
------------------------------
Date: Fri, 12 Jan 2001 11:41:47 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Regular Expression
Message-Id: <slrn95trbl.2q0.bernard.el-hagin@gdndev25.lido-tech>
On Fri, 12 Jan 2001 07:30:05 -0000, vidulats@yahoo.co.uk
<vidulats@yahoo.co.uk> wrote:
>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??
Why would you need a regular expression for this? The double quote
interpolates variables so you can just write:
print "The output is x = $Temp[0], y = $Temp[1], z = $Temp[2]";
Cheers,
Bernard
--
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
------------------------------
Date: Fri, 12 Jan 2001 22:24:53 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Returning a filename from FILEHANDLE
Message-Id: <slrn95tqc5.50v.mgjv@martien.heliotrope.home>
On Fri, 12 Jan 2001 04:36:02 GMT,
Dan Sugalski <dan@tuatha.sidhe.org> wrote:
> 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.
But on a Unix file system the answer is meaningless. Any file can have
multiple links. Which of the file names linked to the file are you going
to return?
I don't think I've ever seen this question (the original one) on this
group, but the standard answer on other groups, more related to Unix, is
that you just keep the file name around. In C you'd wrap the file name
and its associated handle in a struct. In perl you'd probably wrap it as
an object.
Martien
--
Martien Verbruggen |
Interactive Media Division | You can't have everything, where
Commercial Dynamics Pty. Ltd. | would you put it?
NSW, Australia |
------------------------------
Date: Fri, 12 Jan 2001 13:15:39 +0100
From: "Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se>
Subject: sed (unix)
Message-Id: <93ms7o$pfq$1@newstoo.ericsson.se>
Hi,
(OS/UNIX)
I was wondering, how do I do this in perl:
sed -e '/^gunde:/s/\*LK\*/tada/' < shadow >shadow.new
This is in a passwd file and on the row gunde it's replays the ":*LK:" with
"tada".
------------------------------
Date: Fri, 12 Jan 2001 13:17:48 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: sed (unix)
Message-Id: <slrn95u10a.ho.rgarciasuarez@rafael.kazibao.net>
Per- Fredrik Pollnow wrote in comp.lang.perl.misc:
> Hi,
> (OS/UNIX)
> I was wondering, how do I do this in perl:
>
> sed -e '/^gunde:/s/\*LK\*/tada/' < shadow >shadow.new
There's a program that comes with Perl that translates sed scripts to
perl. Its name is s2p.
But, if you want a Perl one-liner :
perl -pe '/^gunde:/&&s/\*LK\*/tada/' < shadow > shadow.new
The difference is in only three characters.
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Fri, 12 Jan 2001 12:08:31 GMT
From: "Michael Mayo" <michael-a-mayo@worldnet.att.net>
Subject: Re: Shall use a reference instead?
Message-Id: <3tC76.841$LZ1.52075@bgtnsc05-news.ops.worldnet.att.net>
"Ilmari Karonen" <iltzu@sci.invalid> wrote in message
news:979294357.25187@itz.pp.sci.fi...
> No, not really. The blessed thingy is the object, period.
> bless \@foo, 'Foobar'; # now @foo is an object..
> print "\$bar -> $bar\n"; # ..and $bar points to it
Yes, but you can't call any of the object's methods without using the
reference. Hard to consider it an 'object' when it cannot have methods. It is
really only the object's instance variables.
> 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.
OK, I'll keep my messages within the NG from now on.
-Mike
------------------------------
Date: Fri, 12 Jan 2001 15:19:44 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Shall use a reference instead?
Message-Id: <3a5f208f.4ca1$dc@news.op.net>
In article <3tC76.841$LZ1.52075@bgtnsc05-news.ops.worldnet.att.net>,
Michael Mayo <michael-a-mayo@worldnet.att.net> wrote:
>"Ilmari Karonen" <iltzu@sci.invalid> wrote in message
>news:979294357.25187@itz.pp.sci.fi...
>> No, not really. The blessed thingy is the object, period.
>
>Yes, but you can't call any of the object's methods without using the
>reference.
But if you have the object, you can always make a reference to it.
bless \@a => 'Foo';
(\@a)->Method();
> Hard to consider it an 'object' when it cannot have methods.
I don't know just what it means to 'have methods'. But if the
reference can be said to have methods, I don't see why the object
itself can't be sid to have methods also.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 12 Jan 2001 15:20:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Shall use a reference instead?
Message-Id: <93n7bu$ka8$1@mamenchi.zrz.TU-Berlin.DE>
Michael Mayo <michael-a-mayo@worldnet.att.net> wrote in comp.lang.perl.misc:
>"Ilmari Karonen" <iltzu@sci.invalid> wrote in message
>news:979294357.25187@itz.pp.sci.fi...
>> No, not really. The blessed thingy is the object, period.
>
>> bless \@foo, 'Foobar'; # now @foo is an object..
>> print "\$bar -> $bar\n"; # ..and $bar points to it
>
>Yes, but you can't call any of the object's methods without using the
>reference. Hard to consider it an 'object' when it cannot have methods. It is
>really only the object's instance variables.
It (the thingy) also holds the information which class it is in. This
is stored with the data and not any particular reference, as Ilmari
has demonstrated. In my book that makes the thingy the object proper,
never mind that Perl's syntax obliges you to take a reference to call
any methods. (You can always call a method via the cumbersome
"(\@foo)->method( ...)" if all you have is the array itself.)
That people talk of the references as objects is a convenient shortcut.
It belongs in the same class as calling a list of of array references
a LoL.
Anno
------------------------------
Date: Fri, 12 Jan 2001 09:08:46 -0500
From: John J Green <jjgreen@cisco.com>
Subject: Re: Win32-Process output
Message-Id: <3A5F0FED.89DCF7AA@cisco.com>
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. ;)
I believe this code works, though its been a while since I've used it. The
disadvantage is that any changes to environment variables are not visible
to the new process.
--- Code ---
use strict;
# Turn off strict refs, because file handles might
# have been passed in like '<&STDIN' or '>&STDOUT'
no strict 'refs';
# Core and CPAN modules
use IO::Handle;
use POSIX ();
use Symbol qw(gensym qualify);
use Win32::Process qw(INFINITE);
#---------------------------------------------------------------------------
# _spawn_with_handles
# Create a new process with read and write handles.
# Params:
# $fds - Reference to array of hashes containing information
# on files to open.
# @cmd - Command and arguments to execute.
# Return values:
# Win3::Process object or exits.
#---------------------------------------------------------------------------
sub _spawn_with_handles
{
my $fds = shift; # Fields: handle, mode, open_as
my @cmd = @_; # Remaining arguments are the command to execute
my ($fd, $pid, @saved_fh, $saved, %saved, @errors);
foreach $fd (@$fds) {
$fd->{tmp_copy} = IO::Handle->new_from_fd($fd->{handle}, $fd->{mode});
$saved{fileno $fd->{handle}} = $fd->{tmp_copy};
}
foreach $fd (@$fds) {
bless $fd->{handle}, 'IO::Handle'
unless eval { $fd->{handle}->isa('IO::Handle') } ;
# If some of handles to redirect-to coincide with handles to
# redirect, we need to use saved variants:
$fd->{handle}->fdopen($saved{fileno $fd->{open_as}} || $fd->{open_as},
$fd->{mode});
}
unless (@errors) {
my $cmd_path = _find_path($cmd[0]);
my $rc = Win32::Process::Create($pid, # Process object
$cmd_path, # Full path to command
join(' ', @cmd), # Command line
1, # Inherit,
0, # Create flags
"." # Initial directory
);
push @errors, Win32::FormatMessage(Win32::GetLastError()) unless $rc;
}
foreach $fd (@$fds) {
$fd->{handle}->fdopen($fd->{tmp_copy}, $fd->{mode});
$fd->{tmp_copy}->close or
push @errors, "Can't close: $!";
}
c_io::fatal(join "\n", @errors) if @errors;
return $pid;
}
------------------------------
Date: Fri, 12 Jan 2001 15:10:08 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: Win32-Process output
Message-Id: <93n6o8$eiv$1@nnrp1.deja.com>
In article <3A5D60A2.AAB4293E@hotmail.com>,
Dave E <dave_at_hm@hotmail.com> 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)
-----------------------
have you tried running your process from a system() call? I dont think
you could pipe the results back to the MAIN. but if you write a temp
file or have some other type of results indicator from the forked
process it might work.
...some code...
$SysStatus = system( "start -m perl somescript.pl $args" ) ;
sleep $MaxWait ;
...check for results.... etc.
D
Sent via Deja.com
http://www.deja.com/
------------------------------
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 48
*************************************