[19492] in Perl-Users-Digest
Perl-Users Digest, Issue: 1687 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 4 06:06:47 2001
Date: Tue, 4 Sep 2001 03:05:14 -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: <999597914-v10-i1687@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 4 Sep 2001 Volume: 10 Number: 1687
Today's topics:
AoH - continued (TuNNe|ing)
Re: AoH - continued <dtweed@acm.org>
Re: AoH - continued (TuNNe|ing)
Re: AoH - continued <goldbb2@earthlink.net>
Re: Calling sub funcs with scalar variables? <goldbb2@earthlink.net>
Clickable Url in 'sendmail' email message (andy theimer)
Re: Clickable Url in 'sendmail' email message <cyberjeff@sprintmail.com>
Re: Clickable Url in 'sendmail' email message nobull@mail.com
Re: email this page script (David Combs)
Re: ENV{'REMOTE_HOST'}; .... does not work ?! <Thomas@Baetzler.de>
Error in Body.pm ? <henry@conlared.com>
Re: Error in Body.pm ? <henry@conlared.com>
Re: Extract the relative sorting of items from multiple (David Combs)
from .pl to .exe on Win2K <tm@kernelconsult.com>
from .pl to .exe on Win2K (TM)
Re: from .pl to .exe on Win2K <wyzelli@yahoo.com>
Getting response from KEA \ Reflection <paul.keirnan@det.nsw.edu.au>
Re: Godzilla DOS Environmental Variables Utility (Malcolm Dew-Jones)
Re: MultiThread with fork? <goldbb2@earthlink.net>
Re: Net::Ping - How to get an IP address back? <jason@thainjm.freeserve.co.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 04 Sep 2001 03:55:55 GMT
From: troll@gimptroll.com (TuNNe|ing)
Subject: AoH - continued
Message-Id: <3b944dd2.22147644@news.coserv.net>
Yo,
Ok. I was able to comprehend all the goodies from my previous post ,
except for Godzilla's stuff...but that's ok, my lurking teaches me
he/she just may be too smart for it's on good.
I am quite sure I need the mapping and sort functions to accomplish my
goal, but I need references to a post or a document. I did a search in
google.groups and walked away feeling spanked.
DATA is a _|_ delimited file with keys directly follwed by it's value.
I would like to be able to use the first line of my DATA as a way to
"sort " the rest of the data. So in this specific example the "print
@goods;" statement should be equivalent to print @goods = ("music",
"very good", "mp3" "video", "too long", "mpeg");
Any ideas or referneces much accepted.
Earth out.
TuNNe|ing
_begin code hera_
#!/usr/bin/perl -w
use strict;
my @data; #nonsorted AoH name space
my @sorted; #sorted anon AoH's name space
my @goods; #sorted anon AoH's values
my $href; #temp variable
while (<DATA>) {
chomp;
push(@data, {split(/\|/,$_)});
}
#CODE HERE TO SORT @data into @sorted
foreach $href (@sorted) {
for (keys %{$href}) {
push(@goods,$href->{$_});
}
}
print @goods;
exit;
__DATA__
category|1|type|3|info|2
category|music|type|mp3|info|very good
category|video|info|too long|type|mpeg
_end code hera_
------------------------------
Date: Tue, 04 Sep 2001 02:48:13 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: AoH - continued
Message-Id: <3B943FD1.D3A8FEFD@acm.org>
TuNNe|ing wrote:
> DATA is a _|_ delimited file with keys directly follwed by it's value.
> I would like to be able to use the first line of my DATA as a way to
> "sort " the rest of the data. So in this specific example the "print
> @goods;" statement should be equivalent to print @goods = ("music",
> "very good", "mp3" "video", "too long", "mpeg");
I have to confess I wasn't following the first go-around.
However, in this iteration it seems that your description of @sorted
is at variance with how you use it in the final foreach loop. And that
loop isn't going to do quite what you think anyway.
The following script produces the desired output (with some liberties
taken with formatting):
#!/usr/bin/perl -w
use strict;
my @data; #nonsorted AoH name space
my @goods; #sorted anon AoH's values
while (<DATA>) {
chomp;
push(@data, {split(/\|/,$_)});
}
#CODE HERE TO SORT @data into @sorted
# pull off the first line of @data to get the sort order
my %sorthash = %{shift @data};
# create an inverted hash that swaps the keys and values
my %invhash;
for my $k (keys %sorthash) { $invhash{$sorthash{$k}} = $k }
# sort the keys of the inverted hash and pull out the values in that order
my @sortkeys = @invhash{sort keys %invhash};
foreach my $href (@data) {
for (@sortkeys) {
push(@goods, $href->{$_});
}
}
print join (', ', @goods), "\n";
exit;
__DATA__
category|1|type|3|info|2
category|music|type|mp3|info|very good
category|video|info|too long|type|mpeg
-- Dave Tweed
------------------------------
Date: Tue, 04 Sep 2001 06:16:29 GMT
From: troll@gimptroll.com (TuNNe|ing)
Subject: Re: AoH - continued
Message-Id: <3b946dcf.30337960@news.coserv.net>
On Tue, 04 Sep 2001 02:48:13 GMT, Dave Tweed <dtweed@acm.org> wrote:
[snipped]
># pull off the first line of @data to get the sort order
>my %sorthash = %{shift @data};
># create an inverted hash that swaps the keys and values
>my %invhash;
>for my $k (keys %sorthash) { $invhash{$sorthash{$k}} = $k }
># sort the keys of the inverted hash and pull out the values in that order
Brilliant, how about I make it even easier for myself and store my
first row like:
1|category|3|type|2|info
I think I was trying to over complicate it.
Thanks.
TuNNe|ing
resulting in:
#!/usr/bin/perl -w
use strict;
my @data; #nonsorted AoH name space
my @goods; #sorted anon AoH's values
while (<DATA>) {
chomp;
push(@data, {split(/\|/,$_)});
}
#CODE HERE TO SORT @data into @sorted
# pull off the first line of @data to get the sort order
my %sorthash = %{shift @data};
# sort the keys of the hash and pull out the values in that order
my @sortkeys = @sorthash{sort keys %sorthash};
foreach my $href (@data) {
for (@sortkeys) {
push(@goods, $href->{$_});
}
}
print join (', ', @goods), "\n";
exit;
__DATA__
1|category|3|type|2|info
category|music|type|mp3|info|very good
category|video|info|too long|type|mpeg
------------------------------
Date: Tue, 04 Sep 2001 01:15:16 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: AoH - continued
Message-Id: <3B946364.43A1119F@earthlink.net>
TuNNe|ing wrote:
>
> Yo,
> Ok. I was able to comprehend all the goodies from my previous post ,
> except for Godzilla's stuff...but that's ok, my lurking teaches me
> he/she just may be too smart for it's on good.
>
> I am quite sure I need the mapping and sort functions to accomplish my
> goal, but I need references to a post or a document. I did a search in
> google.groups and walked away feeling spanked.
>
> DATA is a _|_ delimited file with keys directly follwed by it's value.
> I would like to be able to use the first line of my DATA as a way to
> "sort " the rest of the data. So in this specific example the "print
> @goods;" statement should be equivalent to print @goods = ("music",
> "very good", "mp3" "video", "too long", "mpeg");
>
[snip]
my @data = map {chomp;+{split, /\|/}} <DATA>;
# first line is category=>1, type=>3, info=>2.
# remove it and create 1=>category, 3=>type, 2=>info.
my %sortkeys = reverse %{shift @data};
# sort *numerically*, (1, 3, 2) to get (1, 2, 3).
# then use (1, 2, 3) to get (category, info, type)
my @sortkeys = @sortkeys{sort {$a <=> $b} keys %sortkeys};
# create the sortsub: sub { $a->{category} cmp $b->{category} || ... }
my $sortkeys = join " || ", map "\$a->{$_} cmp \$b->{$_}", @sortkeys;
my $sortsub = eval "sub { $sortkeys )";
my @sorted = sort $sortsub @data;
#my @goods = map values %$_, @sorted; # orig code does this
my @goods = map @$_{@sortkeys}, @sorted; # but what's wanted is this.
> __DATA__
> category|1|type|3|info|2
> category|music|type|mp3|info|very good
> category|video|info|too long|type|mpeg
Be *very careful* about creating $sortsub. Since in your example, the
data is gotten from *DATA, I assume that it is free of malicious
content. In particular, I assume all keys are things which are valid
barewords, and do not contain any spaces or other non-word characters.
If they might contain such things, the code becomes:
my $sortkeys = join " || ",
map "\$a->{\$sortkeys[$_]} cmp \$b->{\$sortkeys[$_]}", 0..$#sortkeys;
If your data comes from outside your script, as it might in the real
world, then use a line like the one above.
If you're generating html, you might want to replace the assignment to
@goods with something like:
print "<TABLE>\n";
print "<TR>", map "<TH>$_", @sortkeys), "</TR>\n";
print "<TR>", map "<TD>", @$_{@sortkeys}, "</TR>\n" for @sorted;
print "</TABLE>\n";
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Tue, 04 Sep 2001 03:24:08 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Calling sub funcs with scalar variables?
Message-Id: <3B948198.25E469B0@earthlink.net>
Anno Siegel wrote:
[snip]
> I just wouldn't advise a newbie to use OO for what "should be simple",
> as they are wont to say. Even the standard advice to use a hash is
> often met with reluctance. I like telling them to do
>
> $age = $value if $name eq 'age';
> $sex = $value if $name eq 'sex';
> $location = $value if $name eq 'location';
>
> or equivalent. That lets them keep the precious variable names while
> being perfectly safe. When it gets tedious, a hash solution is
> probably welcome :)
A mixed solution might be prefered in some cases:
my %hash; @hash{qw(age sex location)} = \(
my ($age, $sex, $location) = @defaults );
${$hash{$name}} = $value;
# use $age, $sex, $location as per normal.
They can use their normal variable names, just as long as they do the
assignment via the hash.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: 3 Sep 2001 19:22:26 -0700
From: atheimer98@yahoo.com (andy theimer)
Subject: Clickable Url in 'sendmail' email message
Message-Id: <caa8eeb3.0109031822.17c67aed@posting.google.com>
I was wondering if anyone has a suggestion as to how to put a
clickable url
in an email that i am sending with sendmail in a cgi script.
The best i can do, is get half, or parts of the long url to be
clickable, because the url is passing information to a differant cgi
it calls, i need the entire url to be clickable.
Thanks
Andy
------------------------------
Date: Tue, 04 Sep 2001 07:28:21 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: Re: Clickable Url in 'sendmail' email message
Message-Id: <3B948223.C52466B5@sprintmail.com>
> I was wondering if anyone has a suggestion as to how to put a
> clickable url
> in an email that i am sending with sendmail in a cgi script.
> The best i can do, is get half, or parts of the long url to be
> clickable, because the url is passing information to a differant cgi
> it calls, i need the entire url to be clickable.
Not a Perl question, ask this in an HTML group like
comp.infosystems.authoring.www.html with an example of what you are
doing.
You'll want to escape the parameters in your query string (URLs can
contain no spaces) and probably wrap it in angle brackets.
<http://some_domain.com/some_page.cgi?some%20parameter=some%20value&some%20other%20parameter=some%20other%20value>
Jeff
------------------------------
Date: 04 Sep 2001 08:18:11 +0100
From: nobull@mail.com
Subject: Re: Clickable Url in 'sendmail' email message
Message-Id: <u9lmjvs9u4.fsf@wcl-l.bham.ac.uk>
atheimer98@yahoo.com (andy theimer) writes:
> I was wondering if anyone has a suggestion as to how to put a
> clickable url
> in an email that i am sending with sendmail in a cgi script.
This is a purely question about the format you are using for the
message body.
It has nothing to do with Perl or, indeed, sendmail.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 4 Sep 2001 07:31:26 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: email this page script
Message-Id: <9n200e$8dj$2@news.panix.com>
In article <slrn9ol2cc.plv.abigail@alexandra.xs4all.nl>,
Abigail <abigail@foad.org> wrote:
>Class Spokesman (galligat@tcd.ie) wrote on MMCMXIV September MCMXCIII in
><URL:news:3B850966.7D1FC124@tcd.ie>:
>^^ Hay
>^^ I'm looking for a freeware perl script that can email a page
>^^ Does anyone where i can find one thanks
>
>
>I'd suggest you go bugger the people in comp.lang.python for such
>a script in Python, then use the following Perl program:
>
> #!/opt/perl/bin/perl -W
> use strict;
> system "email.py" && die $?;
> __END__
>
>
>Assuming the program is in the 'email.py'.
>
Question: why not stick to perl? (You probably
have a very good reason -- please elaborate
a bit.)
Plus, that'd mean you'd have to install and
keep up-to-date Python too.
A hard sell if you're trying to do a turnkey
job for someone, and getting them to let
a perl installation be a prerequisite
was hard enough. Now Python too!
Plus, you'd probably have to *learn* that
language, too, and it's crazy control-structure
via indenting (and thus even the *concept* of an
automatically beautifying "indent"
program being impossible).
Perl, I find, is hard enough. Why Python too?
Especially with Perl-6 coming real soon now,
and for which I'd imagine they've added things
from Python and elsewhere.
Just wondering.
David
------------------------------
Date: Tue, 04 Sep 2001 09:56:08 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: ENV{'REMOTE_HOST'}; .... does not work ?!
Message-Id: <su19ptgtdhoolpdmiq8u9nucfjs8ge0k07@4ax.com>
On Mon, 3 Sep 2001, "Oliver Fietz" <of@abakus-musik.de> wrote:
[...]
>The Problem: customer ip is always missing ! This way the shopping cart is
>always the same for every user .......
>
>
>sub get_host {
>$host = $ENV{'REMOTE_HOST'};
>$reffile = "$tmpdir$delim$storename-$host";
>}
>
>Are some server maybe blocking the lookup command ?
This may be a server configuration issue - i.e. in an Apache server,
"HostnameLookups" needs to be set to "on" for this to work. Besides
that, reverse DNS zones are spotty at best, so you won't get that many
host names resolved.
Finally, there is a general flaw in your logic if you use the remote
host's address to build a unique ID - it just won't work properly
because especially large ISPs route their customers via HTTP proxies,
so you may end up with several customers coming seemingly from the
same IP address. Not good! Instead, use a combination of time stamp
and process id to make your unique identifier.
HTH,
--
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.
------------------------------
Date: Tue, 04 Sep 2001 10:29:21 +0200
From: Enrique =?iso-8859-1?Q?Ochagav=EDa?= <henry@conlared.com>
Subject: Error in Body.pm ?
Message-Id: <3B9490E1.AD260BFF@conlared.com>
I have a problem.
In internet mail, when attachment's filename is large, Body.pm fails:
Content-Disposition: attachment;
filename="=?iso-8859-1?Q?PRESENTACI=D3N_DIGITAL._Ciencia_y_tecnolog=EDa._Noticias._?=
=?iso-8859-1?Q?EL_CORREO_DIGITAL.url?="
get write-open error in line 414. File's name contain a tab (before "EL
CORREO...", line 2)
ActivePerl 5.6.1.626 MSWin32-x86-multi-thread
Any solution?
Sorry my english.
------------------------------
Date: Tue, 04 Sep 2001 11:11:47 +0200
From: Enrique =?iso-8859-1?Q?Ochagav=EDa?= <henry@conlared.com>
Subject: Re: Error in Body.pm ?
Message-Id: <3B949AD3.D430E0A6@conlared.com>
Sorry. Error in :
my($message) = $_[0];
my $parser = new MIME::Parser;
$parser->output_to_core('NONE');
$output_name = $$;
$parser->output_dir("c:/temp/mi") || die "$!";
$parser->parse_nested_messages('REPLACE');
$entity = $parser->parse_data($message) <----- ERROR in Body.pm
line 414
------------------------------
Date: 4 Sep 2001 08:50:42 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Extract the relative sorting of items from multiple lists
Message-Id: <9n24l2$9s5$1@news.panix.com>
In article <slrn9ogc74.em5.abigail@alexandra.xs4all.nl>,
Abigail <abigail@foad.org> wrote:
>David Combs (dkcombs@panix.com) wrote on MMCMXVI September MCMXCIII in
><URL:news:9m7oe0$h0v$1@news.panix.com>:
>,, In article <3B76147C.1FBD0B8B@acm.org>, John W. Krahn <krahnj@acm.org> wrote:
>,, >
>,, >Get the first section of volume four here:
>,, >
>,, >http://Sunburn.Stanford.EDU/~knuth/fasc2a.ps.gz
>,, >
>,,
>,, THANK YOU!
>,,
>,, How did you know this even existed -- unless
>,, you are *at* Stanford?
>
>
>Knuth has been working at Stanford for decades. He has had a website
>for eons. He has announced his plans for Volume 4 and how he will make
>it available for at least 5 years on his website.
>
>It's actually pretty hard to argue you have an interest in algorithms
>while not knowing this and keep a straight face.
>
>
>
>Abigail
Hey, I've met the guy, I was out there visiting
(in late 70's) people in offices just feet from his.
(Not that *I* know anything myself, but I like knowing
people who do. Especially back then, when you could
hire as consultants some truly incredible people
(to teach you algorithms, to develop some,
to hack (uh, world-class hacking, that is)
for very, very little. Not possible these days!)
Heck, this one guy (cs prof) would type in pages
and pages of code, using *ed* (actually, the version
from "Software Tools" (Kermighan's classic book)
that people used as a semi-unix toolset way
back then, when Bell Labs kept unix locked up),
and he'd *turn off the star prompt*!!!!!,
ie no prompt at all!
He'd be typing all this stuff in, then
get out of append-mode (he'd type that dot,
you know), do some substition five lines back,
go insert some stuff between two lines,
all this with no cursor, hardly every doing
a "p" to see where he was (he just *knew*),
working essentially blind -- and making not one
mistake. Incredible. MACHO!
David
---
What I was talking about was his vol 4 -- he
had it listed in vol 1 as (I believe) the 4th out
of a total of 5 this series would constitute.
He did 1, 2, 3 sort of bang bang bang.
Everyone's been waiting *decades* (70's, 80's,
90's) for vol 4.
Anyway, I was surprised, and happy, that it's
finally going to appear.
David
------------------------------
Date: Tue, 04 Sep 2001 06:39:55 +0200
From: TM <tm@kernelconsult.com>
Subject: from .pl to .exe on Win2K
Message-Id: <3B945B1B.B7DC6E13@kernelconsult.com>
Hi,
I'm very confused about getting an compiled version of a perl script on
Win2K.
commands such
perl -MO=CC,-ohi.c hi.pl or perlcc hi.pl abort.
Help welcomed!
TM
------------------------------
Date: 3 Sep 2001 21:55:22 -0700
From: tm@kernelconsult.com (TM)
Subject: from .pl to .exe on Win2K
Message-Id: <9660761b.0109032055.4e7cfefb@posting.google.com>
Hi,
I'm very confused about getting an compiled version of a perl script on
Win2K.
commands such
"perl -MO=CC,-ohi.c hi.pl" or "perlcc hi.pl" abort.
Help welcomed!
TM
------------------------------
Date: Tue, 4 Sep 2001 12:11:52 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: from .pl to .exe on Win2K
Message-Id: <46Xk7.25$Zn5.612@wa.nnrp.telstra.net>
"TM" <tm@kernelconsult.com> wrote in message
news:3B940182.30B71AB3@kernelconsult.com...
> Hi,
> I'm very confused about getting an compiled version of a perl script on
> Win2K.
>
> commands such
> perl -MO=CC,-ohi.c hi.pl or perlcc hi.pl abort.
>
Checkout PerlApp from www.activestate.com or perl2exe from
www.indigostar.com
Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;
------------------------------
Date: Tue, 4 Sep 2001 11:44:13 +1000
From: "Paul Keirnan" <paul.keirnan@det.nsw.edu.au>
Subject: Getting response from KEA \ Reflection
Message-Id: <3b9431ed$1@isuwb1.itbcorpweb.det.nsw.edu.au>
This is a multi-part message in MIME format.
------=_NextPart_000_020A_01C13536.EB6FBFC0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Greetings,
I am new to both Perl (which I like) and also to Unix, although
I have 25yrs experience in other languages and OSes.
I am currently converting some DCL scripts from VMS to
run on TRU64 Unix (on Alphas).
My Perl version is perl, v5.6.1 built for alpha-dec_osf-ld.
The script I am having trouble with takes a filestring as a parameter, =
and
transfers that file from the host to the users PC. It needs to do this
unattended (I.e. no interaction from the user).
This means that it must first determine what Terminal Emulation software
the user is running (in our case, either Reflection or KEA).
For KEA, a control sequence of '<ESC>[ 5;1.z' solicits a response
of '<DCS>5.yKEAterm<ST>'.
And for Reflection, '<ESC>[0;1234c' gives a response of =
'W02-700L456789'.
The problems are:
1. The responses are not terminated by CR or CRLF, so I need a timeout.
2. I am totally unable to get the responses into a variable so that I =
may
test them. If I have 'echo' turned on for the terminal, then the =
responses
are visible, but I can't capture them into the script.
[Note: On VMS the response was captured using a Basic program. I don't =
wish to
use Basic on Unix].
I have tried several things, among them being:
Perl:
use Term::ReadKey;
open(TTY, "</dev/tty");
print "\e[5;1.z";
# `sleep 1`;
ReadMode "raw";
do {
$key =3D ReadKey -1, *TTY;
if ($key) {$string .=3D $key;}
} until (!$key);
ReadMode "normal";
print "\nResponse was |$string|\n";
exit;
KSH:
echo "Trying KEA..."
stty -echo
echo "\033[5;1.z"
## sleep 1
## echo "\n"
##read hoststseq
if read | grep -q 'KEA'
then
stty echo
echo "Found KEA"
exit 3
else=20
stty echo
echo "Rats"
exit 4
fi
exit
Would anyone be able to point me in the right direction?
Thank you,
Paul
Sydney, Australia
------=_NextPart_000_020A_01C13536.EB6FBFC0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV>
<P><FONT size=3D2>Greetings,</FONT></P></DIV>
<DIV><FONT size=3D2>I am new to both Perl (which I like) and also to =
Unix,=20
although</FONT></DIV>
<DIV><FONT size=3D2>I have 25yrs experience in other languages and=20
OSes.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=3D2>I am currently converting some DCL scripts from VMS=20
to</FONT></DIV>
<DIV><FONT size=3D2>run on TRU64 Unix (on Alphas).</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=3D2>My Perl version is perl, v5.6.1 built for=20
alpha-dec_osf-ld.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=3D2>The script I am having trouble with takes a =
filestring as a=20
parameter, and</FONT></DIV>
<DIV><FONT size=3D2>transfers that file from the host to the users PC. =
It needs to=20
do this</FONT></DIV>
<DIV><FONT size=3D2>unattended (I.e. no interaction from the =
user).</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>This means that it must first determine what =
Terminal=20
Emulation software</FONT></DIV>
<DIV><FONT size=3D2>the user is running (in our case, either Reflection =
or=20
KEA).</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>For KEA, a control sequence of '<ESC>[ 5;1.z' =
solicits a=20
response</FONT></DIV>
<DIV><FONT size=3D2>of '<DCS>5.yKEAterm<ST>'.</FONT></DIV>
<DIV><FONT size=3D2>And for Reflection, '<ESC>[0;1234c' gives a =
response of=20
'W02-700L456789'.</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>The problems are:</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>1. The responses are not terminated by CR or CRLF, =
so I need a=20
timeout.</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>2. I am totally unable to get the responses into a =
variable so=20
that I may</FONT></DIV>
<DIV><FONT size=3D2>test them. If I have 'echo' turned on for the =
terminal, then=20
the </FONT><FONT size=3D2>responses</FONT></DIV>
<DIV><FONT size=3D2>are visible, but I can't capture them into the=20
script.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=3D2>[Note: On VMS the response was captured using a =
Basic program.=20
I don't wish to</FONT></DIV>
<DIV><FONT size=3D2> use Basic on Unix].</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=3D2>I have tried several things, among them =
being:</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>Perl:</FONT></DIV>
<BLOCKQUOTE style=3D"MARGIN-RIGHT: 0px">
<DIV><FONT size=3D2>use Term::ReadKey;</FONT></DIV>
<DIV><FONT size=3D2>open(TTY, "</dev/tty");</FONT></DIV>
<DIV><FONT size=3D2>print "\e[5;1.z";</FONT></DIV>
<DIV><FONT size=3D2># `sleep 1`;</FONT></DIV>
<DIV><FONT size=3D2>ReadMode "raw";</FONT></DIV>
<DIV><FONT size=3D2>do {</FONT></DIV>
<DIV><FONT size=3D2> $key =3D ReadKey -1, *TTY;</FONT></DIV>
<DIV><FONT size=3D2> if ($key) {$string .=3D $key;}</FONT></DIV>
<DIV><FONT size=3D2>} until (!$key);</FONT></DIV>
<DIV><FONT size=3D2>ReadMode "normal";</FONT></DIV>
<DIV><FONT size=3D2>print "\nResponse was |$string|\n";</FONT></DIV>
<DIV><FONT size=3D2>exit;</FONT></DIV></BLOCKQUOTE>
<DIV><FONT size=3D2>KSH:</FONT></DIV>
<BLOCKQUOTE style=3D"MARGIN-RIGHT: 0px">
<DIV><FONT size=3D2>echo "Trying KEA..."</FONT></DIV>
<DIV><FONT size=3D2>stty -echo</FONT></DIV>
<DIV><FONT size=3D2>echo "\033[5;1.z"</FONT></DIV>
<DIV><FONT size=3D2>## sleep 1</FONT></DIV>
<DIV><FONT size=3D2>## echo "\n"</FONT></DIV>
<DIV><FONT size=3D2>##read hoststseq</FONT></DIV>
<DIV><FONT size=3D2>if read | grep -q 'KEA'</FONT></DIV>
<DIV><FONT size=3D2>then</FONT></DIV>
<DIV><FONT size=3D2> stty echo</FONT></DIV>
<DIV><FONT size=3D2> echo "Found KEA"</FONT></DIV>
<DIV><FONT size=3D2> exit 3</FONT></DIV>
<DIV><FONT size=3D2>else </FONT></DIV>
<DIV><FONT size=3D2> stty echo</FONT></DIV>
<DIV><FONT size=3D2> echo "Rats"</FONT></DIV>
<DIV><FONT size=3D2> exit 4</FONT></DIV>
<DIV><FONT size=3D2>fi</FONT></DIV>
<DIV><FONT size=3D2>exit</FONT></DIV></BLOCKQUOTE>
<DIV><FONT size=3D2>Would anyone be able to point me in the right=20
direction?</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>Thank you,</FONT></DIV>
<DIV><FONT size=3D2>Paul</FONT></DIV>
<DIV><FONT size=3D2>Sydney, Australia</FONT></DIV></BODY></HTML>
------=_NextPart_000_020A_01C13536.EB6FBFC0--
------------------------------
Date: 3 Sep 2001 20:55:49 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Godzilla DOS Environmental Variables Utility
Message-Id: <3b9450c5@news.victoria.tc.ca>
fvw (fvw+usenet@var.cx) wrote:
: tim@vegeta.ath.cx (Tim Hammerquist) wrote:
: >> it is impossible to set
: >> parent DOS environmental variables via a Perl script.
: >_I_ never said it was impossible. The clpm concensus is that it's
: >impossible on Unix
: Never say never, it's just tricky. But as long as you have ptrace or
: /dev/mem (or even /proc/kmem) (and I'm sure other people can come up
: with other even more fun solutions) it's doable.
If you wanted a shell to support this I think it should be easy.
I imagine defining a fifo that allows a shell to receive "out of band"
input so to speak. At defined times in the command line processing the
shell would check its fifo for input. This way other processes could run
the internal commands of the shell by sending them to the fifo of that
shell. (Most likely you'd want the input to be accepted only from
processes in the same "job").
As for DOS ENV utilities, these have been around for some time, but are
useless in NT, and therefore they are no longer generally useful in most
production situations since you can be sure they work. As soon as you
have to introduce workarounds you may as well bite the bullet and drop
their use entirely. (Heck, the 16 bit programs required to do this sort of
chicanery don't even run on the newest windows.)
------------------------------
Date: Tue, 04 Sep 2001 02:44:42 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: MultiThread with fork?
Message-Id: <3B947859.B1C88BE8@earthlink.net>
MMX166+2.1G HD wrote:
>
> On Thu, 30 Aug 2001 01:40:30 -0400, in comp.lang.perl.misc Benjamin
> Goldberg <goldbb2@earthlink.net> wrote:
> >for( 1 .. $nkids ) {
> > defined(my $pid = fork) or die ...;
> > if( $pid ) {
> > push @kids, $pid;
> > next;
> > }
> > my $start = int( $_ * $size / $nkids );
> I've understanded the fork, but few questions still confuse me. could
> u help me?:
Sure. The first thing to help you with is quoting style: always leave a
blank line between the stuff you're quoting, and the first line of the
stuff you're typing in.
> first: we set the return value to a variable, say $pid, so it'a a
> scalar in program like the others. I know fork clones the current
> process's memory image as a new child process, so the variable are all
> cloned from father's, they shall be the same at the first. but that's
> not the truth. as you wrote, the $pid is 0 inside child, and it's
> child's pid inside the father, why they are different?
Because you otherwise would have no way of differentiating the child
from the parent. In addition, the child has a different value for $$,
which is the variable which indicates the id of the current process.
> second: what steps does fork execute? I found that in my win98:
> when it executes fork, it creates a process, then the control is
> passed to the child, during the child's executing, the father keeps
> waiting until the child exit. it looks like a normal function call not
> a multi-process. for example:
Sounds like it's broken.
> >defined($pid=fork()) || die ;
> >if ($pid==0) {
> > sleep 2;
> > print "I am 0, my pid is ",$$,"\n";
> >}else {
> > print "create a $pid\n";
> >}
> result is: the whole program wait 2 seconds and then prints
> >I am 0, my pid is -225845
> >create a -225845
For some perls, the buffers are not flushed when you fork. Try this
code:
$| = 1;
print "$$ In the parent before fork.\n";
defined($pid=fork()) || die ;
if( $pid ) {
print "$$ I am the parent. My child is $pid\n";
print "$$ sleeping...\n";
sleep 2;
print "$$ done with sleep.\n";
} else {
print "$$ I am the child. My parent is ", getppid, "\n";
print "$$ sleeping...\n";
sleep 2;
print "$$ done with sleep.\n";
}
Run it as is, then see what happens if you comment out the "$| = 1"
line. Umm, the code's untested. If there's a syntax error, I consider
it an exercise for the reader to fix.
> that why I think the father waits for child's execute until the child
> exit.
If it really acts as you say, then it's broken.
> is this true in unix? regardless what unix does, i my win98, if
In unix, fork really and truly creates a new process. It does not wait
for that process to complete, unless/until you call wait or waitpid.
In win, fork simulates the creation of a process, but in actual fact, it
merely a thread. Supposedly, after fork, both the parent thread and
child thread continue executing, simultaneously, unless/until you call
wait or waitpid, or until the program exits.
In most simple cases, it's not possible to tell if your fork really is
making a new process, or if it's simulating proccesses with threads.
> fork executes as a function call, why do I use it? I can write a sub
> and call it simply. so that's a other question: why does perl not
If it really and truly acts as nothing more than a function call, then
it's broken. However, it's possible that you are misinterpreting what
you're seeing, and that it's working as advertised, but just doesn't
look it [due to io buffering].
> support thread directly in win32 platform. portable is not a excuse.
Portability is not the excuse. Stability is. Perl compiled so that
Thread.pm works is not stable. Without it, it is stable [well, mostly].
> Java supports thread and works well. maybe the authors think perl is
Threads were built into java. Threads were not built into perl.
> just a script that don't need multi-thread. sigh
The authors of perl know it's more than "just a script", but it's a lot
of work getting something like that working.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Mon, 03 Sep 2001 23:57:40 +0100
From: Jason Thain <jason@thainjm.freeserve.co.uk>
Subject: Re: Net::Ping - How to get an IP address back?
Message-Id: <SgqUO30rKrYWp1ZR1NxUGagkZAGr@4ax.com>
On Mon, 03 Sep 2001 16:40:45 +0200, Thomas B?tzler
<Thomas@Baetzler.de> wrote:
>Hi,
>
>On Mon, 03 Sep 2001 13:48:00 GMT, Bart Mortelmans <news@bim.be> wrote:
>
>[tofu reformatted and snipped]
>
>>Donald Crowhurst wrote:
>[...]
>>> How can I get it to actually print the IP address in dotted decimal
>>> format? I see that a variable $ip is used in ping.pm, but I'm not good
>>> enough at Perl to pass this back to the calling program.
>
>>If you just want to know the IP-address of a domainname, you should use
>>Net::DNS.
>
>You don't want to use Net::DNS if your host name is not listed in the
>DNS - for stuff that's resolved by WINS, use Socket.pm's inet_ntoa and
>inet_aton, like this:
>
>#!/usr/bin/perl -w
>
>use strict;
>use Socket;
>
>$host="rbos000178";
>
>if( defined( my $packed_addr = inet_aton($host) ) ){
> print inet_ntoa( $packed_addr ) );
>} else {
> print "Can't resolve $host!\n";
>}
>__END__
>
>HTH,
Thanks Thomas, that worked perfectly. I've now finished my first ever
Perl program. looks like Perl will come in very handy in the future.
Don.
------------------------------
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 1687
***************************************