[9631] in Perl-Users-Digest
Perl-Users Digest, Issue: 3225 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 22 15:07:20 1998
Date: Wed, 22 Jul 98 12:01:35 -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, 22 Jul 1998 Volume: 8 Number: 3225
Today's topics:
printf syntax? <afox@u.washington.edu>
Re: printf syntax? (Larry Rosler)
Re: question about split <maraism@sterlingdi.com>
regexp vs. split mboedicker@my-dejanews.com
Regular expressions for Perl 5 <shado@uclink4.berkeley.edu>
Save additional data <andy@switchboard.net>
Re: SPLIT help please <jdf@pobox.com>
su function saadiqr@princeton.edu
Re: Telnet problems with connecting to VMS sessions (John Kelly)
Telnet server? <jpm@iti-oh.com>
Re: Telnet server? (Steve Linberg)
the low road <jkramer@primenet.com>
Re: time limit ? <maraism@sterlingdi.com>
Re: Using splice with for (Matt Knecht)
Variable Interpolation (monty hindman)
W32 Port (Bruce Davidson)
Re: What is Value of <HANDLE> ? (M.J.T. Guy)
why won't this post? <file@job.to>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 22 Jul 1998 10:35:43 -0700
From: Aaron Fox <afox@u.washington.edu>
Subject: printf syntax?
Message-Id: <Pine.OSF.3.96b.980722102710.12055B-100000@saul1.u.washington.edu>
I'm attempting to use printf to divide output from a loop into distinct
packages, and I don't appear to be getting the syntax right.
Here's the code example:
---------------------------------------
} else {
($orig_val) = split " ", $_, 2;
$total_nodes = ($nodenumbr + $orig_val);
print TEMP_FILE "$total_nodes\t!n_output_nodes \n";
for($j=0; $j<=$nodenumbr; $j+=10) {
printf TEMP_FILE ("%d %C", $mn_coord[$j], ((j+1)%10)? '\n':' ');
}
print TEMP_FILE " \n";
$in_out_no=0;
--------------------------------------
What I want it to print out $mn_coord[$j] 10 times, print a newline, and
then keep printing on the next line. I'm patching the output into an
existing file for use by another program (LTG) that's pretty finicky about
format.
Right now, the following output is what I get...:
--------------
9 ^A32 ^B38 ^B42
17 31 #<--- These are originally in file, appended to the end of the new
#nodes written in...
------------
Is there a better way to do this than printf, and, if not, where am I
going wrong in the syntax? It compiles fine....
TIA,
d.
Aaron Fox: Geologist, Journalist, Web Designer
afox@u.washington.edu || http://weber.u.washington.edu/~afox
PGP public key available on request
------------------------------
Date: Wed, 22 Jul 1998 11:23:42 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: printf syntax?
Message-Id: <MPG.101fce0693b7bb6f989738@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy sent to Aaron Fox
<afox@u.washington.edu>.]
In article <Pine.OSF.3.96b.980722102710.12055B-
100000@saul1.u.washington.edu> on Wed, 22 Jul 1998 10:35:43 -0700, Aaron
Fox <afox@u.washington.edu> says...
...
> for($j=0; $j<=$nodenumbr; $j+=10) {
> printf TEMP_FILE ("%d %C", $mn_coord[$j], ((j+1)%10)? '\n':' ');
> }
You are thinking C when writing Perl. The newline character is "\n", not
'\n'. If you make that change, and replace %C by %s (a one-character
Perl string, if you wish), this should do what you want.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 22 Jul 1998 14:44:58 -0400
From: Michael Maraist <maraism@sterlingdi.com>
Subject: Re: question about split
Message-Id: <35B6332A.9CC273B7@sterlingdi.com>
> > @b and @c should be the same ("if the PATTERN is also omitted, the function
> > splits on white space, /\s+/, after skipping any leading whitespace"). But the
> > output I get is:
> >
> > -b-- <-- Extra field ?
> > -b-a-
> > -b-b-
> > -c-a-
> > -c-b-
> >
> > Could somebody explain what's happening? Thanks.
> >
> > Giuseppe Vacanti
> >
>
> $a = ' a b ';
> $_ = $a;
> @explicit = split /\s+/;
> @implicit = split;
>
> foreach(@explicit){
> print "-expl-$_-\n";
> }
> foreach(@implicit){
> print "-impl-$_-\n";
> }
>
> print scalar @explicit;
> print scalar @implicit;
>
> @explicit has indeed an extra field, its length is 3, while @implicit
> has two. split on its own gets rid of leading whitespace completely.
> Apparently the first split also splits on the first whitespace, so the
> contents of the first element is ''. Does that make sense? (I don't > know
split by default splits on " ", not ''. " " has special meaning to
split. It ignores all leading and trailing white space, also grouping
all adjacent whitespace together. ( thus emulating awk's default
behavior ). If you were to use '' as the split expression, then it
would split on every character. Note also, that " " is not the same as
/ / which splits on single space characters.
I am paraphrasing O'Reilly's "Programming Perl" book, Pages 220-221.
Additionally 'man perlfunc' mentions the distinctions.
------------------------------
Date: Wed, 22 Jul 1998 17:47:02 GMT
From: mboedicker@my-dejanews.com
Subject: regexp vs. split
Message-Id: <6p58im$4bm$1@nnrp1.dejanews.com>
Does anyone see any reason why these two pieces of code wouldn't do the same
thing?
while(<SEARCH>) {
s/\"//g;
s/.*?\|//;
@fields = split(/\|/);
foreach $field (@fields) {
... etc
--------------
while(<SEARCH>) {
s/\"//g;
@fields = split(/\|/);
$fields[0] = "";
foreach $field (@fields) {
... etc
--------------
I have a file of the format blah|blah|blah|blah and basically I want @fields
to be an array of all the fields except the first one. Right, now I am using
example #2. The first example seems to strip out the first two fields.
Thanks.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Wed, 22 Jul 1998 11:39:41 -0700
From: BJKim <shado@uclink4.berkeley.edu>
Subject: Regular expressions for Perl 5
Message-Id: <35B631ED.DC3BBCC4@netscape.com>
Does Perl 4 not support certain aspects of regular expressions that Perl
5 does.
This is the error I get in Perl 4 but not in Perl 5
/(<TD>(.*?)</TD><TD>(.*?)</TD>){1}?/: nested *?+ in regexp at change.cgi
line 70.
Any suggestions on what I should do?
------------------------------
Date: Wed, 22 Jul 1998 19:58:39 +0200
From: "Andy" <andy@switchboard.net>
Subject: Save additional data
Message-Id: <6p58ui$292$1@news.nordkom.de>
Hi,
I4m writing a script where I have to read out an existing list such a form
like this:
data1,number1
data2,number2
.....
In same cases I have to hitch some information. like that:
data1,number1
data2,number2,further2
.....
When I open the file for read it will be read line by line. then I have to
close it and to work with this information. How can I realise it, that only
this one line will be overwrite with the new information, so that I can
return to it, when I open the file again.
In this content I have an other question. When I split this string at the
first time, I have only two information, data and number. When my program
have to check if there are more information (further) it can be, that there
is nothing, because this information aren4t existing. In pascal I can use
the term NIL. But what about it in Perl. Does it mean // e.g. $further =~
//, means there are no information, empty?
Andy
------------------------------
Date: 22 Jul 1998 12:09:34 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: SPLIT help please
Message-Id: <67gp95ip.fsf@mailhost.panix.com>
horseyride@hotmail.com writes:
> Can someone tell me how to do split commands for weird characters? I have two
> splits, one where I want to split on a '.' (decimal) and one on a '|' (pipe
> character). Thanks
Right near the top of the perlre document it tells you to use the \
character to quote the next metacharacter. So, to match a literal
dot, you say
/\./
Check out perlre and perlfaq6.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf/
------------------------------
Date: Wed, 22 Jul 1998 17:47:55 GMT
From: saadiqr@princeton.edu
Subject: su function
Message-Id: <6p58kb$4c4$1@nnrp1.dejanews.com>
Is there a function that would effectively change the 'user' which the program
is running as? My little "Learning Perl" copy hasn't been that helpful. A
sort of...
su $id pw$;
Thanks.
Saadiq
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Wed, 22 Jul 1998 17:14:05 GMT
From: john.kelly@citicorp.com (John Kelly)
Subject: Re: Telnet problems with connecting to VMS sessions
Message-Id: <35b91dd0.10335491@news.citicorp.com>
In your login.com script you have a line that contains
$ set term/inquire
Either comment out this line or change it to something like
$ set term/device=vt100
Rgds,
John
On 21 Jul 1998 22:41:20 GMT, frostps@aol.com (FrostPS) wrote:
>I'm trying to use the TELNET package to talk to a VMS node that is trying
>to
>inquire about my screen size and the like but I don't know how to respond
>and eventually I
>time out before I get my command line prompt. Is there options I can set to
>have it
>automatically respond or ignore these requests so that I can get logged in?
>
>Scott
>(Please respond to scott.frost@airtouch.com)
>
------------------------------
Date: Wed, 22 Jul 1998 12:32:49 -0400
From: Joshua Marotti <jpm@iti-oh.com>
Subject: Telnet server?
Message-Id: <35B61430.3C0CECAE@iti-oh.com>
Hello,
Does anyone know of a perl module that opens ports and emulates a
telnet server?
Thanks ahead of time,
Josh Marotti
===============================================
Computer Engineer
International TechneGroup Inc.
"Black holes are where God divided by zero"
===============================================
------------------------------
Date: Wed, 22 Jul 1998 13:54:44 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Telnet server?
Message-Id: <linberg-2207981354440001@projdirc.literacy.upenn.edu>
In article <35B61430.3C0CECAE@iti-oh.com>, Joshua Marotti <jpm@iti-oh.com>
wrote:
> Hello,
> Does anyone know of a perl module that opens ports and emulates a
> telnet server?
> Thanks ahead of time,
> Josh Marotti
> ===============================================
> Computer Engineer
> International TechneGroup Inc.
> "Black holes are where God divided by zero"
> ===============================================
Net::Telnet
_____________________________________________________________________
Steve Linberg National Center on Adult Literacy
Systems Programmer &c. University of Pennsylvania
linberg@literacy.upenn.edu http://www.literacyonline.org
------------------------------
Date: Wed, 22 Jul 1998 10:30:19 -0700
From: "John" <jkramer@primenet.com>
Subject: the low road
Message-Id: <6p57kc$mds$1@nnrp02.primenet.com>
Hello,
First of all I would like to say that I am new to the Newsgroup and still in
the learning stages with perl too but I will do my best not to sound
completely ignorant. As to my topic I was creating a database program using
perl cgi when I encountered a problem. It became necessary for form via an
HTML page to pass information from a <textarea>. The problem was I needed
to remove the \n's and replace them with <BR>'s. I opted to use the Split
command to split at the \n's and then run a foreach loop to paste the <BR>'s
in place. True to TIMTOWTDI form after I finished I got to thinking that
there might have been a better way. Is it possible to set the Output Record
Separator ($\) to <BR> and if so how do you get it in before the data is
passed from the form?
I have searched my stack of manuals and browsed till my eyes are falling out
but I can't seem to find the answer. It could be that I am looking in the
wrong area's but I differ to the wisdom of the board.
Thank you,
John
------------------------------
Date: Wed, 22 Jul 1998 14:21:23 -0400
From: Michael Maraist <maraism@sterlingdi.com>
Subject: Re: time limit ?
Message-Id: <35B62DA3.A56BD7B8@sterlingdi.com>
Kamran Iranpour wrote:
>
> Hi
>
> How do I implement a time limit for a process to take place
> in a perl script ?
> I have a list of machines that I try to start similar process
> on each. These could be down or something else could be wrong.
> How do I say that if the "rsh" takes say more than 10 sec, then
> skip this machine and move to the next on the list ?
>
> Thanks in advance
>
> Kamran
One way would be to set an alarm to time out after 10 seconds.
I made a couple attempts, and it doesn't appear to be as easy as I
thought. If you attempt to use system, qx, or a piped open, the
subshell doesn't correctly handle the alarm signal. You have to write
your own shell forker. Here is a rough example:
sub exec_timeout($$) {
my ( $time_out, $shell_cmd ) = @_;
if ( fork ) {
alarm $time_out;
exec "sh", "-c", $shell_cmd;
} else {
wait;
}
} # end exec_timeout
I'm not completely sure this would work for all cases.
------------------------------
Date: Wed, 22 Jul 1998 16:12:13 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: Using splice with for
Message-Id: <xbot1.32$oO4.496574@news2.voicenet.com>
Ronald J Kimball <rjk@coos.dartmouth.edu> wrote:
>> @array = grep { $_ ne 'condition' } @array;
>>
>> But that seems excessive.
>
>Why is that excessive? Isn't that exactly what you want to do? Isn't
>that exactly what grep is meant to be used for?
I've been beaten with the efficeintcy stick one too many times. Which
doesn't go too well after you've been run over by the readable code
truck.
It seems excessive because I know I hvae only one match. Unless it's
the last element that matches there are wasted cycles.
But, after benchmarking various solutions with various arrays, I've come
to the conclusion that the grep method is best, unless this line is
going to be called *many* times. I find that the instances where I'm
stuck searching an array come up very little, so a small performance hit
is OK. Normally I would only need to do this once or twice in a
program so I don't miss the .001 seconds it takes for the elegant
solution.
--
Matt Knecht - <hex@voicenet.com>
"496620796F752063616E207265616420746869732C20796F7520686176652066
617220746F6F206D7563682074696D65206F6E20796F75722068616E6473210F"
------------------------------
Date: Wed, 22 Jul 1998 18:49:21 GMT
From: montyh@umich.edu (monty hindman)
Subject: Variable Interpolation
Message-Id: <Ruqt1.4791$24.28134217@news.itd.umich.edu>
Why does this program compile just fine:
$a = "$b" ;
While this one produces a compiling error:
$a = "@b" ;
In string, @b now must be written as \@b at 2 line 1, near "@b"
Execution of 2 aborted due to compilation errors.
I'm using version 5.004_04 built for sun4-solaris.
------------------------------
Date: Wed, 22 Jul 1998 18:22:26 GMT
From: news@allied.demon.co.uk (Bruce Davidson)
Subject: W32 Port
Message-Id: <901131799.20788.0.nnrp-03.9e982204@news.demon.co.uk>
Using w32 port Pw32i316.exe on 386dx/Win95/PWS, is there a way to use
open (PROC, "| sleep 1; rm -f $basepath/$mydir/$FORM{'myid'}.ext");
I can't use unlink because of the $FORM call which I can't set as a
predefined variable. (Pipe sleep is not really needed as is shown).
Thanks
------------------------------
Date: 22 Jul 1998 16:37:40 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: What is Value of <HANDLE> ?
Message-Id: <6p54gk$1j9$1@pegasus.csx.cam.ac.uk>
Lavoie Philippe <lavoie@zeus.genie.uottawa.ca> wrote:
>
>In my program I get a lot (4) of this message
>
>Value of <HANDLE> construct can be "0"; test with defined() at cppdoc.pl line 65535.
>
>
>My program is not 65535 lines of code, so I'm a bit confused as to why
>I'm receving this error message.
There is a known bug in perl5.004_04 that causes a wrong line number in
this case. This will be mended in the forthcoming perl5.004_05 and
perl5.005 versions.
Meanwhile, to locate the problem, look for a construct like
while ($line = <FH>) { }
and also see the entry in perldiag for this message.
Mike Guy
------------------------------
Date: Wed, 22 Jul 1998 18:10:59 +0200
From: "file" <file@job.to>
Subject: why won't this post?
Message-Id: <6p54f7$94c$1@usenet40.supernews.com>
Hey folks...
can someone please tell me why this will not post... it doesnt give and
error message though...
$r= new HTTP::Request POST 'http://www.siteshack.com/add.phtml', [title =>
'some old title', url => 'http://www.testurl.com', email => 'test@test.com',
descrp => 'describe', key => 'test key word', pass => 'test'];
thanks
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3225
**************************************