[9443] in Perl-Users-Digest
Perl-Users Digest, Issue: 3038 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 1 13:07:24 1998
Date: Wed, 1 Jul 98 10:00:26 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 1 Jul 1998 Volume: 8 Number: 3038
Today's topics:
Re: access time (Joel Coltoff)
Adding to listserv on remote machine w. no httpd <rwatkins@springer-ny.com>
Re: array of objets (Chris Russo)
Associative arrays and LISTS. <wao@aluxs.micro.lucent.com>
Re: Associative arrays and LISTS. <rootbeer@teleport.com>
Re: Associative arrays and LISTS. (Aaron B. Dossett)
Can't kill telnet process with Comm.pl close_it() routi <Brett.W.Denner@lmco.com>
Dejanews/closed lists/moderated groups/lists [Was: Re: birgitt@my-dejanews.com
Re: Dereferencing Anonymous Hash? <rootbeer@teleport.com>
Re: find a number with regular expression <rootbeer@teleport.com>
Re: find a number with regular expression (Craig Berry)
Re: How do you pre-append using "open" (Josh Kortbein)
I can't nail down the uninitialized value :( <quednauf@nortel.co.uk>
Re: I can't nail down the uninitialized value :( <bowlin@sirius.com>
Re: I can't nail down the uninitialized value :( <rootbeer@teleport.com>
Re: i've got a forking problem (Mike Wescott)
Re: Need to plot charts (gif format ?) from ascii data (Josh Kortbein)
perl and secured payment online? <abcdm@wanadoo.fr>
Re: perl and secured payment online? <rootbeer@teleport.com>
Problem setting break points after *while* statements i <Brett.W.Denner@lmco.com>
Re: problems with script (Matt Knecht)
Re: question about objects <jdporter@min.net>
Re: question about objects <jdporter@min.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 1 Jul 1998 16:21:31 GMT
From: joel@wmi0.wmi.com (Joel Coltoff)
Subject: Re: access time
Message-Id: <6ndnlg$qo9@netaxs.com>
In article <Pine.GSO.3.96L.980701112711.12562A-100000@unixs-eval.cis.pitt.edu>,
Optimist Prime <pwhst+@pitt.edu> wrote:
>
>I guess my question is this:
>
> Is there any way to change the access time of a file, without
> having write access to it.
Seems like a good guess to me. ;-)
Yes you can. Modify the inode. This only requires access to the directory
and not the file. Here's one way to do it.
#! /usr/local/bin/perl
die "Usage: cptime filename file1 [file2 ... filen]\n" unless @ARGV;
die unless ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime, $blksize,$blocks) = stat(shift);
utime $atime, $mtime, @ARGV;
--
Joel Coltoff
I'd explain it, but there's a lot of math. -- Calvin
------------------------------
Date: Wed, 01 Jul 1998 12:30:07 -0400
From: Robert Watkins <rwatkins@springer-ny.com>
Subject: Adding to listserv on remote machine w. no httpd
Message-Id: <359A640F.B0D5933E@springer-ny.com>
One of my marketing people wants a web interface to allow people to sign
up for a listserv. Unfortunately, the listservs run off a machine with
no web server and, as I see it, there are only two ways to solve the
problem, neither of which I know how to do:
1] Have a web-based form on one machine pass data to and start a script
on a remote machine with no web server (which sounds like it might be a
security nightmare), or
2] Have Perl send an e-mail using data from the web form with a faked
header (such that the "From" field contains the individual's e-mail
address rather than the machine's), perhaps using LWP::Protocol::mailto
or something similar?
Yes, I know, another solution would be to install a web server on the
remote machine and have the form's ACTION be "http://www....", but I
really would like to avoid having to maintain another web server!
Any help pointing me in the right direction would be appreciated.
Robert Watkins
Supervising Web Developer
Springer-Verlag New York, Inc.
rwatkins@springer-ny.com
www.springer-ny.com
www.copernicus-ny.com
www.telospub.com
journals.springer-ny.com/chedr/
(amongst others ...)
------------------------------
Date: Wed, 01 Jul 1998 09:39:01 -0700
From: news@russo.org (Chris Russo)
Subject: Re: array of objets
Message-Id: <news-0107980939020001@buzz.hq.alink.net>
In article <3599F4F6.9D9E52A8@emw.ericsson.se>,
Robert.Rehammar@emw.ericsson.se wrote:
>How do I create an array of objects ??
>
>\\Robert Rehammar
I noticed that you have a couple of very basic questions posted to
comp.lang.perl.misc today. Not that there's anything wrong with being new
and all, but could you please take some time to read the documentation
that comes with perl before posting a bunch of questions that you could
just as easily solve yourself?
You might also take a look at the FAQ and other resources available from
www.perl.com & www.perl.org:
<http://language.perl.com/faq/>
After you've taken a look at those resources, you'll find that there are
plenty of people here who would be happy to help you past any major
hurdles.
Regards,
Chris Russo
--
Chris Russo
news@russo.org
http://www.russo.org
------------------------------
Date: Wed, 01 Jul 1998 12:02:35 -0400
From: Bill Oswald <wao@aluxs.micro.lucent.com>
Subject: Associative arrays and LISTS.
Message-Id: <359A5D9B.72B15C26@aluxs.micro.lucent.com>
I have an associative array and I want it to contain a list.
How do I create/operate on this array. I've tried:
$assoc{"foo"} = (); Create an empty list
$assoc{"foo"} = ($name);
...
foreach $tmp ($assoc{"foo"})
{
}
This works. But I really want
$assoc{"foo"} = ();
push ($assoc{"foo"} , $name);
...
foreach $tmp($assoc{"foo"})
{
}
The push would allow me to grow the list that is associated
with $assoc{"foo"}. How do I assign a list to an associative
array and how do I use the associative array so that its
content is considered a list?
Thanks in advanve
Bill
--
We have enough youth. What we need is a fountain of smart!
------------------------------
Date: Wed, 01 Jul 1998 16:34:28 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Associative arrays and LISTS.
Message-Id: <Pine.GSO.3.96.980701093155.8511H-100000@user2.teleport.com>
On Wed, 1 Jul 1998, Bill Oswald wrote:
> I have an associative array and I want it to contain a list.
I think you mean you want an element of the hash to hold a reference to an
array. (I'm not pointlessly griping about your terminology - a hash is
different than an elemenet of a hash, and a reference to an array is
different than a list.)
> $assoc{"foo"} = (); Create an empty list
That comment is misleading; that is not an empty list! (That's not even a
comment! :-)
You should see the perlref, perllol, and perldsc manpages. Hope this
helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 1 Jul 1998 16:46:22 GMT
From: aarond@alpha.ewl.uky.edu (Aaron B. Dossett)
Subject: Re: Associative arrays and LISTS.
Message-Id: <6ndp4u$q2f$1@service3.uky.edu>
Bill Oswald (wao@aluxs.micro.lucent.com) wrote:
> This works. But I really want
>
> $assoc{"foo"} = ();
> push ($assoc{"foo"} , $name);
> ...
> foreach $tmp($assoc{"foo"})
> {
> }
You probably want something like this:
$assoc{"foo"} = []; #Create a reference to an anonymous array
push @{$assoc{"foo"}}, $name;
Once you explicitly dereference the reference, you can treat it like
a normal array. The 'perlref' manpage provides a more complete description
of references and their functionality.
-Aaron
--
Aaron B. Dossett | Finger aarond@london.cslab.uky.edu for PGP key
dossett@bigfoot.com|
| http://www.ewl.uky.edu/~aarond
University of Kentucky 1996 & 1998 NCAA Basketball Champions
------------------------------
Date: Wed, 01 Jul 1998 10:59:49 -0500
From: Brett Denner <Brett.W.Denner@lmco.com>
Subject: Can't kill telnet process with Comm.pl close_it() routine
Message-Id: <359A5CF5.D92DD80E@lmco.com>
I'm trying to use Net::Telnet and Comm.pl to build a script that
will log on another computer with telnet, then hand over the telnet
session to me so I can work interactively on the other computer.
I don't like using rlogin because rlogin doesn't propagate much
of my current session to the other computer (the man page for rlogin
says that only the TERM variable is propagated).
I've cobbled together a script using documentation for Net::Telnet
and Comm.pl, and this is what I have:
===============================================================
use Net::Telnet;
my $hostname = "target"; # target machine name
my $username = 'user'; # user name
my $passwd = 'mydoghasfleas'; # password
my $comm_pty;
my $pty;
## Start the telnet program so we can talk to it via a
## pseudo-terminal.
{
local ($^W) = 0; # Comm.pl isn't warning clean
require "Comm.pl";
&Comm::init ('close_it', 'interact', 'open_proc',
'stty_raw', 'stty_sane');
$comm_pty = open_proc("telnet $hostname") or die "open_proc failed";
## Unfortunately the Comm package doesn't
## return us a fully qualified filehandle. We
## must keep the filehandle Comm returned for
## its use and we must build another filehandle
## qualified with the current package for our
## use.
$pty = "main::$comm_pty";
}
## Obtain a new Net::Telnet object that does I/O to the
## pseudo-terminal attached to the running telnet
## program. The "Telnetmode" is "off" because we're
## not talking directly to a telnet port as we normally
## do, we're talking to a pseudo-terminal. The
## "Output_record_separator" is now a carriage-return
## because that's what you'd normally hit when you get
## done typing a line at a terminal.
my $host = new Net::Telnet
(
Fhopen => $pty,
Timeout => 10,
Prompt => "/^\$: \$/",
Telnetmode => 0,
Output_record_separator => "\r"
);
## login
$host->login($username, $passwd) or die "Couldn't login";
## Allow the user to interact with telnet program until
## they exit.
{
no strict 'subs'; # so we can refer to STDIN
no strict 'refs';
local ($^W) = 0; # Comm.pl isn't warning clean
stty_raw(STDIN);
interact($comm_pty, "exit"); # exit is needed to make interact() finish
properly
print "Exited interact()\n";
stty_sane(STDIN);
close_it($comm_pty);
close $pty;
}
close $host;
===================================================================
Everything works okay, except that when the script is finished there
are still two telnet sessions remaining (they can be seen with ps). If I
use the script several time, I max out the number of allowable telnet
sessions and telnet won't work any more. Can anyone suggest ways to
improve this script?
By the way, the "exit" argument in the interact() routine is necessary to
keep the session from hanging when interact() is finished. If I don't
put the "exit" argument there, when I exit out of the telnet session the
entire session hangs up and I have to kill the X window it was run in.
Thanks,
Brett
--
Brett W. Denner Lockheed Martin TAS
Brett.W.Denner@lmco.com P.O. Box 748
(817) 935-1144 (voice) Fort Worth, TX 76101
(817) 935-1212 (fax) MZ 9332
------------------------------
Date: Wed, 01 Jul 1998 16:10:33 GMT
From: birgitt@my-dejanews.com
Subject: Dejanews/closed lists/moderated groups/lists [Was: Re: Is perl5-porters closed to subscription?
Message-Id: <6ndn1p$f2m$1@nnrp1.dejanews.com>
In article <3599c375.0@news.one.net>,
mikeh@minivend.com (Mike Heins) wrote:
>
> Jeremy D. Zawodny <jzawodn@wcnet.org> wrote:
> > Quentin Fennessy <quentin@shaddam.amd.com> writes:
>
> >> Is perl5-porters closed to subscription?
>
> > I don't think so.
>
> I could see why someone might think so. I tried to subscribe a few
> months ago and never was passed through.
>
> I find mailing to perlbug@perl.com and a DejaNews subscription
> to perl-porters.gw a good alternative, though.
First, I apologize that my questions end up being posted here in
c.l.p.m, but I couldn't find (besides may be news.groups) a place
where to put it and the question is triggered by the above question and
the ongoing change of an open to a moderated c.l.p.misc/mod group.
I am a bit confused about the mechanism the way mailing lists
versus a news groups are open or closed to the public and the role
dejanews has in keeping an objective record of posts made.
Groups:
For news groups I understand there is the mechanism available
to turn an open group into a moderated/closed group by way
of a democratic mechanism, whereby people choose deliberately
a "benevolent dicatorship" model to be ruled by.
The moderated group remains open in the sense that anyone
can read it, posting is under a registration and review process
of the moderators, changing the name, format or removing
a moderated group or the moderator of the group is not open, or
not defined, or in the state of being discussed and defined in
news.groups.
The _guarantee_ of all posts being openly accessable for reading
is given by the current dejanews archiving mechanism, yes or no ?
Lists:
I thought mailing lists are generally open for registration
and posting for anybody in the public.
If that is wrong:
Is a mailing list in general _owned_ by ONE person ?
If so, is the owner in general automatically moderator ?
If so, can the owner/moderator of a mailing list decide not
to maintain mailing-list archives or decide arbitrarily
not to pass through subscription requests without announcing
such a possible policy ?
If so, is it guaranteed that all posts ever made are archived
by dejanews ?
If that archiving mechanism is guaranteed:
Is the mechanism under a sort of democratic supervision ?
If that archiving mechanism in _not_ guaranteed:
What would we have to do to make it so ?
Dejanews:
Who owns dejanews ? How is it guaranteed that ALL posts are
archived ? Who pays for dejanews ? If I pay for dejanews
in one way or another indirectly, where is my share of control
I should have over the way it is functioning ?
Thanks for any response in advance.
Birgitt Funk
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Wed, 01 Jul 1998 15:33:56 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Dereferencing Anonymous Hash?
Message-Id: <Pine.GSO.3.96.980701083057.8511F-100000@user2.teleport.com>
On Wed, 1 Jul 1998, John Call wrote:
> @uniq = sort keys %{ { map {$_,1} @list } };
> What I don't know is why the second set of {} couldn't be the arguement
> for keys. Why do I have to dereference the anonymous hash?
Perl "never" implicitly dereferences a ref; you always have to do it
yourself.
> Why does it sort?
Only 'cause someone wanted it sorted. :-) You could omit the word 'sort'
if you wish.
> Does this destroy the duplicates?
No, the hashing ensures that dupes will be listed only once.
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 01 Jul 1998 16:28:18 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: find a number with regular expression
Message-Id: <Pine.GSO.3.96.980701092743.8511G-100000@user2.teleport.com>
On Wed, 1 Jul 1998, Jim Bowlin wrote:
> m/^\s*[\+\-]?(\d+\.?\d*|\.\d+)(e[\+\-]?\d+)?$/i;
>
> This should be true if and only if $_ will convert to a number successfully.
$number = "1000 "; # :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 1 Jul 1998 16:40:43 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: find a number with regular expression
Message-Id: <6ndoqb$4ct$1@marina.cinenet.net>
Robert Rehammar (Robert.Rehammar@emw.ericsson.se) wrote:
: How do I find out if a srtring contains a number with $string[0]=~/???/.
You read the faq.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 1 Jul 1998 16:18:56 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: How do you pre-append using "open"
Message-Id: <6ndnhg$467$3@news.iastate.edu>
Earl Hood (ehood@geneva.acs.uci.edu) wrote:
: In article <Pine.GSO.3.96.980618195259.17544J-100000@user2.teleport.com>,
: Tom Phoenix <rootbeer@teleport.com> wrote:
: >On Fri, 19 Jun 1998, Nick Forte wrote:
: >
: >> I'm trying to pre-append a record to a flat file. I want the record to
: >> be inserted on the first line everytime instead of appending it to the
: >> end. Can someone help me?
: >
: >Section five of the FAQ has an entry on this oxymoronic notion of
: >"appending to the beginning" of a file. Hope this helps!
: Actually, it is not oxymoronic. "append" means to attach or affix.
: There is no notion of location. So making the statement, "append to
: the beginning" is okay since it explicitly states where the data
: should be attached.
That may be the "actual" denotation, but "append" is commonly
understood to refer to attaching at the end.
Josh
prefers prepend or pre-pend for the other
--
_________________________________________________________
I do not trust your bitch.
- Frederich Nietzche, in _Also Sprach Zarathustra_
------------------------------
Date: Wed, 01 Jul 1998 16:44:22 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: I can't nail down the uninitialized value :(
Message-Id: <359A5956.1B1335DF@nortel.co.uk>
Here is some work I have been doing today. It is hard to program RAM friendly...
I call the following method with an argument to search for in a file. This
method calls another one once it encounters the thingy it is looking for:
sub search {
my $self = shift;
my $arg = {@_};
my ($fh, $marker, $line, @messages);
my $search = $arg->{what} || "*.";
$fh = $arg->{output} || \*STDOUT;
open ME, "< $self->{infile}" or die "Cannot open infile: $!";
while (<ME>) {
if (/^From.*1998/) {
$marker = tell(ME); #remember where I encountered start of last message
}
if (/$search/io) {
push @messages, $self->make_message(\$marker, \*ME);
}
}
close ME;
return \@messages;
}
make_message actually creates the thing that shall be pushed into @messages:
sub make_message {
my $self = shift;
my $start = shift;
my $handle = shift;
my $click = 0;
my %message = ();
seek $handle, $$start, 0;
SLURP: while (<$handle>) {
if (/^Subject: (.*)/) {$message{subject} = $1; next SLURP;}
if (/^Sender: (.*)/) {$message{sender} = $1; next SLURP;}
if (/^Date: (.*)/) {$message{date} = $1; next SLURP;}
if (/^X-Mozilla-Status:/) {$click = 1; next SLURP;}
if (/^From.*1998/) {
$click = 0;
seek $handle, -length($&)-4, 1;
last SLURP;
}
if ($click == 1) {$message{body} .= $_; next SLURP;}
}
return \%message;
}
The VERY offending line is this:
*** if ($click == 1) {$message{body} .= $_; next SLURP;} ***
Use of uninitialized value at Netscape.pm line 50, <ME> chunk 65.
Use of uninitialized value at Netscape.pm line 50, <ME> chunk 147.
Use of uninitialized value at Netscape.pm line 50, <ME> chunk 201.
The culprit isn't the $click, It seems to have to do with .= . But WHY ?
If I just assign, say, a word, to $message{body}, no complaints seem to come.
Also, the complaints stop after a while and the proper stuff gets into
$message{body}.
Maybe someone knows what is happening.
PS
I know that right now all hash references in @messages will have the same value,
but that's another story and shall be told at another day :)
--
____________________________________________________________
Frank Quednau
http://www.surrey.ac.uk/~me51fq
________________________________________________
------------------------------
Date: Wed, 01 Jul 1998 09:19:21 -0700
From: Jim Bowlin <bowlin@sirius.com>
To: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: I can't nail down the uninitialized value :(
Message-Id: <359A6189.FF15E64F@sirius.com>
F.Quednau wrote:
>
[much code snipped]
>
> seek $handle, $$start, 0;
> SLURP: while (<$handle>) {
# ...
> if ($click == 1) {$message{body} .= $_; next SLURP;} # line 50
> }
> Use of uninitialized value at Netscape.pm line 50, <ME> chunk 65.
The solution is to initialize $message{body} = ''; before the SLURP loop.
You would get a similar warning if you try to contatenate an undefined
value to a string:
my $a;
print $a . 'xyz';
HTH -- Jim Bowlin
------------------------------
Date: Wed, 01 Jul 1998 16:49:07 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: I can't nail down the uninitialized value :(
Message-Id: <Pine.GSO.3.96.980701094741.8511K-100000@user2.teleport.com>
On Wed, 1 Jul 1998, Jim Bowlin wrote:
> > if ($click == 1) {$message{body} .= $_; next SLURP;} # line 50
> > Use of uninitialized value at Netscape.pm line 50, <ME> chunk 65.
>
> The solution is to initialize $message{body} = ''; before the SLURP loop.
I don't know that that's _the_ solution. Using a recent version of perl
would be my preferred solution. :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 01 Jul 1998 12:25:48 -0400
From: wescott@cygnus.ColumbiaSC.NCR.COM (Mike Wescott)
Subject: Re: i've got a forking problem
Message-Id: <x4soklk06r.fsf@cygnus.ColumbiaSC.NCR.COM>
In article <6nbja3$qs7$1@csnews.cs.colorado.edu> Tom Christiansen
<tchrist@mox.perl.com> writes:
> In comp.lang.perl.misc, dperez@blue.seas.upenn.edu (Dan Perez) writes:
>> while (<F>) {
>> fork && next;
>> print;
>> exit;
>> }
> You're duplicating stdio buffers. Tsk.
Yes, but why does the child touch the shared seek pointer (for F) at all?
That's the real question.
On 2 local machines, one running linux, the other NCR's MP-RAS, the programs
work as expected.
On Solaris x86 2.6, each of the children pushes the seek pointer back a little
just prior to the (implicit) close of F. This, of course, confuses the parent.
--
-Mike Wescott
mike.wescott@ColumbiaSC.NCR.COM
------------------------------
Date: 1 Jul 1998 16:38:31 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: Need to plot charts (gif format ?) from ascii data
Message-Id: <6ndom7$467$4@news.iastate.edu>
Vinit Jindal (vjindal@qualcomm.com) wrote:
: Hello,
: I am writing Perl scripts that query Oracle database for data, and
: then plot charts from that data. These charts would then be posted on
: the web.
: Is there a freeware / shareware utility available that I can use to
: plot charts from ascii data.
: Any other suggestions for posting charts on the web prepared from
: ascii data.
gnuplot, available at least on unix and winders systems, worked
fine for me. Just do what you will with your data and then feed it
to gnuplot with a system call.
Josh
--
_________________________________________________________
I do not trust your bitch.
- Frederich Nietzche, in _Also Sprach Zarathustra_
------------------------------
Date: 1 Jul 1998 15:56:27 GMT
From: "DUTOIT" <abcdm@wanadoo.fr>
Subject: perl and secured payment online?
Message-Id: <01bda509$0184a1c0$a894fcc1@SIT.wanadoo.fr>
Hello,
I'ld want to use an https protocol in a form.
I know it's necessary to put , after the Content-type of this HTML page a
command wich permits to secure the payment (not broken blue left key of
the screen).
What is the command to do that in Perl?
Thank you
Mr DUTOIT
------------------------------
Date: Wed, 01 Jul 1998 16:36:13 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: perl and secured payment online?
Message-Id: <Pine.GSO.3.96.980701093438.8511I-100000@user2.teleport.com>
On 1 Jul 1998, DUTOIT wrote:
> I know it's necessary to put , after the Content-type of this HTML page a
> command wich permits to secure the payment (not broken blue left key of
> the screen).
>
> What is the command to do that in Perl?
If you're trying to produce certain output, the print function, documented
in the perlfunc manpage, is probably the one you want. (Of course, if
you're not sure what to print, you'll want to check elsewhere for that
information.) Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 01 Jul 1998 11:33:54 -0500
From: Brett Denner <Brett.W.Denner@lmco.com>
Subject: Problem setting break points after *while* statements in debugger
Message-Id: <359A64F2.F2C3ED1B@lmco.com>
I've noticed a problem in the perl debugger with recognizing break
points after a while loop. I'm running version 5.004_04 under IRIX 6.2.
Consider this script:
================================
$n=1;
print "A,";
while (1) {
print "B,";
last if $n++ >= 2;
}
print "C,";
print "D\n";
================================
This script prints "A,B,B,C,D". If I start the script with "perl -d"
and set a break point on the last print statement, the debugger stops
on that line after printing "A,", and fails to stop on the
'print "C\n"' line after exiting the while loop. Here's the output
of the debugger when I step through the code with 'n' commands:
=================================================================
(prompt lines that read " DB<1> n" are omitted)
main::(./test.pl:3): $n=1;
main::(./test.pl:4): print "A,";
A,main::(./test.pl:9): print "C,";
main::(./test.pl:6): print "B,";
B,main::(./test.pl:7): last if $n++ >= 2;
main::(./test.pl:5): while (1) {
main::(./test.pl:6): print "B,";
B,main::(./test.pl:7): last if $n++ >= 2;
main::(./test.pl:9): print "C,";
C,main::(./test.pl:10): print "D\n";
D
DB::fake::(/usr/local2/lib/perl5/perl5db.pl:2083):
2083: "Debugged program terminated. Use `q' to quit or `R' to restart.";
=========================================================
Notice that the 'print "C\n"' line is displayed after the 'print "A\n"'
line instead of the 'while (1)' line the first time the while loop is
reached. If I set a breakpoint on the 'print "C\n"', the debugger
stops on the line only the first time it is reached (after the
'print "A\n"' line, not after the while loop).
If I replace the while command with a foreach (1..10) command, the
debugger stops correctly on the foreach line after the 'print "A,"'
line and also on the 'print "C,"' line after the foreach loop.
Is this a bug in perl, or is my understanding of the debugger a bit
suspect?
Thanks,
Brett
--
Brett W. Denner Lockheed Martin TAS
Brett.W.Denner@lmco.com P.O. Box 748
(817) 935-1144 (voice) Fort Worth, TX 76101
(817) 935-1212 (fax) MZ 9332
------------------------------
Date: Wed, 01 Jul 1998 16:11:01 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: problems with script
Message-Id: <pctm1.16$Du.105291@news2.voicenet.com>
Abigail <abigail@fnx.com> wrote:
>Good for obfuscating?????? I use that construct all the time, in any
>language that has arrays, and I never use parens for that. Are you
>really suggesting that it should be written as:
>
> $foo = ($bar [3]) + 3; ????
No, I don't find the lack of parentheses distressing. I find the extra
space objectionable. I would write that as:
$foo = $bar[3] + 3;
>Oh, ok. Let me give some C examples then:
>
> foo = bar [3] + 3; /* Parens? */
> foo = *bar + 3; /* Parens? */
> foo (3) || bar (3); /* Parens? */
No in all three cases. I see your point when you use simple
expressions. In fact, excepting the spaces, I write the exact same way.
I wasn't trying to advocate the use of parentheses in _every_ expression
where precedence comes up. However, I do think their use in anything
other than basic expressions does help, even if they are redundant.
This holds especially true if you're trying to write maintainable code.
While I don't have a hard fast rule, I think when you get to more than 3
or so conditionals, it's a good idea to start bracing things the way you
want them.
--
Matt Knecht - <hex@voicenet.com>
"496620796F752063616E207265616420746869732C20796F7520686176652066
617220746F6F206D7563682074696D65206F6E20796F75722068616E6473210F"
------------------------------
Date: Wed, 01 Jul 1998 16:15:28 GMT
From: John Porter <jdporter@min.net>
Subject: Re: question about objects
Message-Id: <359A6258.2AD7@min.net>
Charlie Stross wrote:
>
> In the name of Kibo the Compassionate, the Merciful,
> on Mon, 29 Jun 1998 01:39:44 -0400,susurrus <rob@intr.net> implored:
>
> >require "./point.pm";
>
> You used require() instead of use() to load your module. Consequently
> stuff you put in it shows up in the namespace point, as opposed to MAIN.
Wrong. Please don't post nonfactual blather. You're only going to
screw up an impressionable newbie even worse. For shame.
(And you meant "main" anyway, not "MAIN".)
> (I think you need to get hold of the Camel book and read chapters 4 and 5
> before you go on.)
Good advice for all of us, eh, Charlie?
> >*P = "point::new";
> >
> >$x = P(1, 2);
> >$y = P(-1, -2);
>
> I don't know what you're trying to assign a scalar string to a
> typeglob for in here; either I'm being particularly stupid, or you're
> attempting to use a glob as a symbolic reference?
"Particularly stupid" is probably a bit strong. But yes, his syntax
works, creating a sub in the current package (main) which is an alias
to the sub new in package point. Not that this is advisable, really...
> >$quadrant = $x->quadrant; print "$quadrant\n";
> >$quadrant = $y->quadrant; print "$quadrant\n\n";
>
> Hmm. You're trying to keep the x and y coordinates as separate objects,
> with methods defined in the point.pm package, aren't you?
No. You're getting confused by the names. $x and $y are simply
(intended to be) two objects of class point.
> When you're writing a module, the object (called
> $self here) is a reference to an anonymous hash (although arrays or
> scalars _can_ be used if you're particularly sick and twisted :) ...
Um, there is absolutely nothing twisted or even unusual about using
references to arrays for objects. Scalars, though rather more uncommon,
are still legit. Don't forget that references are scalars too.
Code refs can be used for objects too, quite nicely.
> sub x {
> # set or get the X axis coordinate; return zero if coordinate is zero
Why would you do this? Should the caller never be allowed to set x to
zero? Come on.
Fixed:
> my $self = shift;
> if (@_) {
> $self->{x} = $_[0];
> }
> return $self->{x};
> }
> sub quadrant {
> # return the quadrant this point is in
> my ($self) = shift @_;
> if (($self->x() > 0) && ($self->y() > 0)) {
> return 1;
> } elsif (($self->x() < 0) && ($self->y() < 0)) {
> return 3;
> } elsif (($self->x() < 0) && ($self->y() > 0)) {
> return 2;
> } elsif (($self->x() > 0) && ($self->y() < 0)) {
> return 4;
> } else {
> return 0; # eeek!
> }
> }
> NB: Yes: this is verbose and bulky, and half those if statements could be
> replaced by the ternary operator, and a version where new() accepts x,y
> coordinates as an initializer would be shorter. But I'd like to think it's
> also clear and readable. If it isn't, please tell me why.
Holy crow.
Rob's original version of quadrant() was MUCH more concise and readable!
Rob also had
my $self = shift;
which is standard, correct perl idiom.
Also, why bother with elsif's when each block does a return?
That gives:
sub quadrant {
my $self = shift;
if (($self->x() > 0) && ($self->y() > 0)) {
return 1;
}
if (($self->x() < 0) && ($self->y() < 0)) {
return 3;
}
if (($self->x() < 0) && ($self->y() > 0)) {
return 2;
}
if (($self->x() > 0) && ($self->y() < 0)) {
return 4;
}
return 0; # eeek!
}
Which in turn leads to the further simplification:
sub quadrant {
my $self = shift;
return 1 if ($self->x() >= 0) && ($self->y() >= 0);
return 2 if ($self->x() < 0) && ($self->y() >= 0);
return 3 if ($self->x() < 0) && ($self->y() < 0);
return 4;
}
(Here I've also modified to include the zeros with the positives.)
--
John Porter
------------------------------
Date: Wed, 01 Jul 1998 16:21:09 GMT
From: John Porter <jdporter@min.net>
Subject: Re: question about objects
Message-Id: <359A63BB.2EF4@min.net>
susurrus wrote:
>...
> *P = "point::new";
>
> $x = P(1, 2);
> $y = P(-1, -2);
That's bizarre. Is there any reason to prefer that over
$x = point->new( 1, 2 );
???
> package point;
> sub new{
>...
> return "X: $x, ref: $refx\nY: $y, ref: $refy\n\n"
Here's a tip: if your constructor won't returned a properly blessed
reference, have it call warn, and return undef.
> sub quadrant{
Here's a nifty little version:
sub quadrant {
my $self = shift;
my $y = $self->{"y"} < 0 ? 1 : 0;
my $x = $self->{"x"} < 0 ? 1 : 0;
(($y<<1)|($x^$y))+1;
}
Hope this helps,
Good luck,
--
John Porter
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 3038
**************************************