[10997] in Perl-Users-Digest
Perl-Users Digest, Issue: 4597 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 8 20:07:28 1999
Date: Fri, 8 Jan 99 17:00:16 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 8 Jan 1999 Volume: 8 Number: 4597
Today's topics:
asm to perl (Randy Jae Weinstein)
Re: calling ksh functions from perl <ljz@asfast.com>
Re: calling ksh functions from perl <cberblin@us.dhl.com>
determining controlling tty <cberblin@us.dhl.com>
Re: HP-UX Install problem <cberblin@us.dhl.com>
Re: Not Quite FAQ: perl for Win32 w/out console (Jeffrey Drumm)
Re: Perl Criticism (Craig Berry)
Re: Perl Criticism <mds-resource@mediaone.net>
Re: Perl Criticism <mds-resource@mediaone.net>
Re: Perl Criticism (Clay Irving)
PERL, CGI environment setup questions <chub@healtheon.com>
Re: utmp / who (Juergen Heinzl)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 9 Jan 1999 00:22:33 GMT
From: rw263@is7.nyu.edu (Randy Jae Weinstein)
Subject: asm to perl
Message-Id: <7767g9$qlh$1@news.nyu.edu>
I'm trying to take the asm code . . .
movsx eax, cx
cdq
sub eax, edx
. . . and convert it to perl code
What I have is:
$eax = decimal integer
$cx = decimal integer
$edx = is binary and has 32 bits either all 1's or
all 0's pending the above operations
What I'm looking for is the ending value of $edx
Thanks so much!
(if possible please email and post. thanks :_)
--
Cheers,
=| __ __ T | Randy Jae
=| | .\/. | O M |
*--\ \/ /--* O A | NYU College of Dentistry
| / __ \ T N | Randy Jae Weinstein Lehigh University
| |_| |_| H | rw263@is7.NYU.EDU
--==>> http://Pages.NYU.EDU/~rw263/
------------------------------
Date: 08 Jan 1999 19:34:59 -0500
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: calling ksh functions from perl
Message-Id: <ltbtk9s2q4.fsf@asfast.com>
Venkatraman Krishnan <kvraman@lucent.com> writes:
> The ksh script has functions like get_changed_values(). I need to call these
> functions from my perl script and get the return values of these
> functions. How do I accomplish this?
This is not possible in the general case. Both ksh and Perl are
language interpreters, and each one knows about its own semantics.
Functions written in the Perl language can be evaluated by the Perl
interpreter, and functions written in the ksh language can be
evaluated by the ksh interpreter (and in many cases, by other
ksh-compatible interpreters such as bash and zsh).
So, in general, there's no way to evaluate a ksh function by an
entirely different interpreter such as Perl.
Here's a way to evaluate ksh functions within Perl, but it's actually
a more of a silly "well, if you want to really stretch a point, I
guess you can sort-of do it" kind of thing thing that isn't very
usable in the real world:
First of all, one highly-restrictive limiting assumption is that
your ksh script only contains function definitions. Suppose you
have a file named "kshfuncs" which looks like this:
#!/bin/ksh
func1 () {
return $1
}
func2 () {
return $2
}
func3 () {
return $3
}
Given this "kshfuncs" file, you can then run the Perl script below
as follows and get the results of each function invocation. Assume
that the Perl script is called "evalKshFuncs" ...
evalKshFuncs kshfuncs func1 101 102 103
evalKshFuncs kshfuncs func2 101 102 103
evalKshFuncs kshfuncs func3 101 102 103
Here's the Perl script itself. Just remember that this is just a
"here's how it could be done" thing that isn't all that useful in the
real world:
#!/usr/bin/perl -w
# -*- perl -*-
my $program = undef;
($program = $0) =~ s:^.*/::;
my $kshDefaultLoc = '/bin/ksh';
my $script = shift(@ARGV);
unless (defined($script) && scalar(@ARGV) > 0) {
usage();
}
unless (open(SCRIPT, "<$script")) {
die "$program: unable to open script file: $script\n";
}
my $firstLine = <SCRIPT>;
unless (defined($firstLine)) {
close(SCRIPT);
die "$program: empty script: $script\n";
}
my $ksh = undef;
if ($firstLine =~ m/^!#\s*(\S+)/) {
$ksh = $1;
}
else {
$ksh = $kshDefaultLoc;
}
unless ($ksh =~ m:/ksh$:) {
close(SCRIPT);
die "$program: interpreter doesn't appear to be the Korn shell: $ksh\n";
}
unless (-x $ksh) {
close(SCRIPT);
die "$program: interpreter isn't executable: $ksh\n";
}
push(@scriptLines, $firstLine, <SCRIPT>);
close(SCRIPT);
my $funcInvocation = join(' ', @ARGV);
# Just use a temp file in this example ... IPC::Open2::open2 would be
# better in the general case.
my $tmp = "/tmp/.x$$";
unless (open(TMP, ">$tmp")) {
die "$program: unable to create temporary file\n";
}
print TMP @scriptLines;
print TMP <<EOD;
$funcInvocation;
result="\$?"
print ">>> function call: $funcInvocation"
print ">>> function result: \${result}"
EOD
close(TMP);
my $result = undef;
if (open(KSH, "$ksh $tmp 2>&1 |")) {
while (defined($line = <KSH>)) {
chomp($line);
# simple-minded test ...
if ($line =~ m/^>>> function call:/) {
unless (defined($line = <KSH>)) {
last;
}
if ($line =~ m/^>>> function result:\s+(\S.*)$/) {
$result = $1;
last;
}
}
}
}
close(KSH);
if (defined($result)) {
print "success: result: $result\n";
}
else {
print "failure\n";
}
unlink($tmp);
exit(0);
sub usage {
die "usage: $program script function [ args ... ]\n";
}
__END__
--
Lloyd Zusman ljz@asfast.com
perl -le '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x"'
------------------------------
Date: Fri, 08 Jan 1999 17:49:30 -0700
From: Craig Berbling <cberblin@us.dhl.com>
Subject: Re: calling ksh functions from perl
Message-Id: <3696A79A.21419AA3@us.dhl.com>
Venkatraman Krishnan wrote:
>
> The ksh script has functions like get_changed_values().
> I need to call these functions from my perl script and get the return values of these
> functions. How do I accomplish this?
>
> venky
>
> Clay Irving wrote:
>
> > In <369676E6.7494240A@lucent.com> Venkatraman Krishnan <kvraman@lucent.com> writes:
> >
> > >How can I call functions implemented in ksh shell scripts from perl?
> >
> > Could it be as simple as:
> >
> > This shell script:
> >
> > #!/bin/ksh
> >
> > echo "Howdy"
> >
> > This Perl program:
> >
> > #!/usr/local/bin/perl -w
> >
> > system("foo.ksh");
> >
> > This output from the Perl program:
> >
> > Howdy
> >
> > --
> > Clay Irving
> > clay@panix.com
Well it's one thing to call a shell script from a perl script (or should I say
program, given the previous 'top' ranking discussion threads of late) and get
its return value, and it's something else to get the return value from a
particular function defined in a shell script that runs in the context of the
shell script.
You might be better off rewriting the functions (or even the whole shell script)
as perl functions or put them in a module. Otherwise, you will need to modify
your shell script to return the value returned by the particular function you
are interested in or break the functions into little scripts themselves, but
that won't work if the functions in the shell script depend on other things the
script does...............
So either way, you are gonna have to either extend your shell script, modularize
it or convert it to perl. Some work any way you look at it.
Hope this helps.
--
Craig
------------------------------
Date: Fri, 08 Jan 1999 17:14:29 -0700
From: Craig Berbling <cberblin@us.dhl.com>
Subject: determining controlling tty
Message-Id: <36969F65.BB1212AD@us.dhl.com>
Greetings,
I want to determine if my perl process is attached to a terminal or not. If not
I will direct STDOUT to a log file, otherwise I will spew to the terminal. I
don't want to rely on the output of the 'tty' command or any other external
command. Is there an internal 'perl thingee' or method of determining this ?
I have searched this news group and the moderated one, but my eyes are now tired
so it's time to post.
Thanks,
--
Craig
------------------------------
Date: Fri, 08 Jan 1999 17:05:51 -0700
From: Craig Berbling <cberblin@us.dhl.com>
Subject: Re: HP-UX Install problem
Message-Id: <36969D5F.8E7C63A7@us.dhl.com>
"J. T. Greenaway" wrote:
>
> Kerry,
>
> Thanks for the advice. It started me on the path I needed. Turned
> out to be a problem with my cc, so I used gcc instead.
>
> Jeff
>
> On Thu, 07 Jan 1999 14:02:24 -0500, Kerry Allsup
> <kerry.allsup@bridge.bellsouth.com> wrote:
>
> >
> >
> >"J. T. Greenaway" wrote:
> ><snip>
> >> ./perl.h: 1259: too much defining - use -H option
> ><snip>
> >
> >
> >This is a common HPUX 9.04 problem. Do man cpp, look for the -H option.
> >
> >HTH,
> >Kerry
I had the same problem and found the answer in the hints directory in the
hpux.sh file...
# If you get a message about "too much defining", you might have to
# add the following to your ccflags: '-Wp,-H256000'
This works using the crappy old cc compiler bundled with hpux version 9 and
such.
--
Craig
------------------------------
Date: Sat, 09 Jan 1999 00:51:11 GMT
From: drummj@mail.mmc.org (Jeffrey Drumm)
Subject: Re: Not Quite FAQ: perl for Win32 w/out console
Message-Id: <3696a559.341049540@news.mmc.org>
[posted and mailed]
On Fri, 08 Jan 1999 09:59:37 -0500, Tripp Lilley <tripp.lilley@perspex.com>
wrote:
(snip)
>This runs the script without spawning a new shell window, but it assumes that
>you've already an instance of cmd.exe from which to run it :-) Since cmd.exe is
>itself a console mode app... Anyway, I don't know if I provided the context,
>but this is a case in which the scripts are being called from another program
>that has its own GUI. Since there's no cmd.exe context from which to 'start',
>and no way I saw in cmd /? to spawn cmd.exe without an actual console, I
>suppose I'm going to write the wrapper.
>
>Grumble.
>
>Thanks for the pointers.
Oops, I assumed that START was an external command (it is on 95/98) and not
a CMD builtin, and that you were running a batch file.
My condolences . . .
--
Jeffrey R. Drumm, Systems Integration Specialist
Maine Medical Center Information Services
420 Cumberland Ave, Portland, ME 04101
drummj@mail.mmc.org
"Broken? Hell no! Uniquely implemented." -me
------------------------------
Date: 9 Jan 1999 00:02:27 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Perl Criticism
Message-Id: <7766ak$qcn$1@marina.cinenet.net>
Michael D. Schleif (mds-resource@mediaone.net) wrote:
: Isn't set theory fun?
:
: C is a subset of programming languages.
: C++ is a subset of programming languages.
: Pascal is a subset of programming languages.
: Java is a subset of programming languages.
: Perl is a subset of programming languages.
Well, technically, these are members. { C } is a subset, or "The set of
all programming languages which have camels as well-known symbols." :)
--
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "The hills were burning, and the wind was raging; and the
clock struck midnight in the Garden of Allah."
------------------------------
Date: Fri, 08 Jan 1999 18:36:00 -0600
From: "Michael D. Schleif" <mds-resource@mediaone.net>
Subject: Re: Perl Criticism
Message-Id: <3696A470.9FB53361@mediaone.net>
Yes, a single, discrete element can also be a subset of a set of
elements. Yes, perhaps the parentheses are more grammatically correct.
Nevertheless, I continue to fail to see the point of such discrimination
-- to what end?
Craig Berry wrote:
>
> Michael D. Schleif (mds-resource@mediaone.net) wrote:
> : Isn't set theory fun?
> :
> : C is a subset of programming languages.
> : C++ is a subset of programming languages.
> : Pascal is a subset of programming languages.
> : Java is a subset of programming languages.
> : Perl is a subset of programming languages.
>
> Well, technically, these are members. { C } is a subset, or "The set of
> all programming languages which have camels as well-known symbols." :)
--
Best Regards,
mds
mds resource
888.250.3987
"Dare to fix things before they break . . . "
"Our capacity for understanding is inversely proportional to how much we
think we know. The more I know, the more I know I don't know . . . "
------------------------------
Date: Fri, 08 Jan 1999 18:48:23 -0600
From: "Michael D. Schleif" <mds-resource@mediaone.net>
Subject: Re: Perl Criticism
Message-Id: <3696A757.E2AE40D4@mediaone.net>
At last, a taker }:-^
topmind@technologist.com wrote:
>
> As poined out in a nearby message, most of us prefer to
> classify movies and music even though there is no clear
> dividing line between them.
>
> Imperfect classifications are often better than no
> classifications. Classifications are a tool.
> Just because we don't have an exact equation does
> not mean the tool is not useful.
But, persuade me of your usefulness . . .
> > This is my absolute favorite unreasonable assertion }:-^
> >
> > The blind cannot see, therefore seeing is not possible.
> > My neighbor's newborn infant cannot drive my car, therefore my car
> > cannot be driven.
> > I do not know how to fly, therefore it is not possible for anybody to
> > travel to the stars.
>
> I don't understand this sarcasm. Does it relate to something I said?
< returned to context ;->
>
> 1. Very tough to mix arrays and scalars unless you have only one array at the end of the list.
>
> 2. "Getting used to" means it is tougher to learn, with little benefits in return.
>
> 3. There is no simple mechanism for passing by-value.
I really do find it amusing that, somebody with *no* substantive
experience in a language, is so vocal about its complexity. If it is
too difficult for you to use, what is so difficult about moving
elsewhere?
Seriously, please, present your alternative language so that we may be
amazed or continue our amusement }:-^
--
Best Regards,
mds
mds resource
888.250.3987
"Dare to fix things before they break . . . "
"Our capacity for understanding is inversely proportional to how much we
think we know. The more I know, the more I know I don't know . . . "
------------------------------
Date: 8 Jan 1999 19:54:35 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Perl Criticism
Message-Id: <7769cb$24s@panix.com>
In <775olp$m66$1@nnrp1.dejanews.com> topmind@technologist.com spews:
>Reply to Tom Christiansen's 1/8 message:
>>> I'm not saying they're the same languages, but that they share with perl
>a generality that is not to be found in these actor-puppet languages
>such as I have demonstrated above. <<
>Where are you getting *your* definition of "scripting" from?
>Is there a Department of Definitions in the World Trade Center?
>I have seen a wide range of language implimentation.
>I have seen actor-puppet modem scripting languages
>start to introduce loops, if's, subroutines, etc.
>You provided no clean cutoff point either. I am not sure
>exactly what your complaint is. You have no formal source
>of info nor opinion surveys to bash my definition of
>scripting. You are unarmed in your attack of my def.
Here's a definition of `script' for you:
Another term for macro or batch file, a script is a list of
commands that can be executed without user interaction. A
script language is a simple programming language with which
you can write scripts.
http://webopedia.internet.com/TERM/s/script.html
>>> Pardon me, but your unfounded accusations of `poor research' on the
>part of these languages' authors is unprofessional in the extreme.
>Can you substantiate your claims? Please list languages, authors,
>and your incontrovertible evidence that these authors engaged in
>`poor research'. Don't forget haskell and dylan. <<
>Since I have no Poor-O-Meter (either do you), it is only an opinion.
>I have never seen language builders publish in the public domain
>a list of reasons, trade-offs, considerations, etc. of why they
>picked what they did for the final version. Sometimes they
>say "I was influenced by a mix of X, Y, and Z." However, X, Y, and
>Z themselves never went thru such a process. Thus, bad ideas are
>taken from other's bad ideas. (Note that what programmers like
>is not necessarily the same as what managers like because
>there is a job-security conflict of interest in many programmers.
>Cryptic = Exclusive)
Nice babble, but you didn't give Tom what he asked for.
You say poor research was involved.
Tom says which langauage? Who was the author?
You say you don't have a "Poor-O-Meter."
You can't substantiate your claims, can you?
>>> Ah, you were there, then? <<
>No, but I am not being selfish by hiding away the decision
>process so that the next language maker has to start from
>scratch and repeat the same mistakes.
You made a statement.
Tom asked how do you know -- were you there?
You reply, "no, but I am not being selfish..."
Eh?
What the hell are you talking about?
>>> More factual errors. You really have no idea how Perl really works,
>do you? Perl is perfectly happy having multiple values for a given key,
>or if you would, non-unique keys. <<
>Being do-able and natural are two different things. With enough cryptic
>hacking, much is possible in any language. The bottom line is
>that Perl is *not* a table-oriented or relational-oriented language.
You say it can't be done.
Tom says it can.
You say, yeah, but its not natural.
Heh, your flipflops are comical.
--
Clay Irving
clay@panix.com
------------------------------
Date: Fri, 08 Jan 1999 16:02:53 -0800
From: Bruce Chu <chub@healtheon.com>
Subject: PERL, CGI environment setup questions
Message-Id: <36969CAD.793FC391@healtheon.com>
1) What is the correct way to setup the environment (library search
paths, environment variables, etc) within a PERL CGI script? The way
that I am thinking about doing this is to have a require within a BEGIN
block.
2) What is the best/correct way to emulate the CGI environment within a
Perl CGI script that I am debugging/running from the command line? We
are using CGI.pm, and are running into various environment related
issues since our debugging environment has a whole bunch of variables
set that won't be present when the script is run in the CGI environment.
Is there a module that takes care of this for me? Or should I just try
to clear out all my non-CGI environment variables in a BEGIN block?
------------------------------
Date: Sat, 09 Jan 1999 00:45:59 GMT
From: juergen@monocerus.demon.co.uk (Juergen Heinzl)
Subject: Re: utmp / who
Message-Id: <slrn79d7va.mh.juergen@monocerus.demon.co.uk>
In article <36967C34.B8FBB14D@uci.edu>, dana watanabe wrote:
>Is there any perl function/module/way to do it that works with utmp?
>
>I'd bassically like to get the same information as doing who.
Easy enough, although the format is somewhat platform dependent. As
an example ...
$recsize = length (pack (IOTEMPLATE,0,0,'','',0,'','',0));
... for a template ...
"s x2 I A12 A4 I A8 A16 L"
... is what I use to read wtmp in a script to cut it down. Works
on Linux as well as on HP. See /usr/include/utmp.h for more (utmp
and wtmp are of the same format).
[...]
>Also, not so perl related, but does the utmp stuff contain IP addresses
>that get tranlated for the host names or just a string?
You can get the IP address (but check your systems documentation,
since I would not rely in general on getting a sensible value there).
[...]
>i'm using iScreen (or screen) and the host comes out as:
>"hostname:S.0" instead of "hostname.domain.foo.bar"
See utmp.h for the size of the ut_host array ... might be too
short, yes.
[...]
Bye, Juergen
--
\ Real name : J|rgen Heinzl \ no flames /
\ EMail Private : juergen@monocerus.demon.co.uk \ send money instead /
\ Phone Private : +44 181-332 0750 \ /
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4597
**************************************