[6897] in Perl-Users-Digest
Perl-Users Digest, Issue: 522 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 23 14:17:20 1997
Date: Fri, 23 May 97 11:00:38 -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 Fri, 23 May 1997 Volume: 8 Number: 522
Today's topics:
Re: $ARGV not working? <rootbeer@teleport.com>
Re: (1+2)**3 == 3! <mark@tstonramp.com>
Re: (1+2)**3 == 3! <dehon_olivier@jpmorgan.com>
Re: (1+2)**3 == 3! (Daniel S. Lewart)
Re: (1+2)**3 == 3! (I R A Aggie)
Re: \b refuses to work properly <mark@tstonramp.com>
Access, ODBC, and the Web (Jared Evans)
Re: Access, ODBC, and the Web (Nic Gibson)
Re: Can't get $! to print ERRORLEVEL value <rootbeer@teleport.com>
Re: CGI-ing <luvisi@andru.sonoma.edu>
Re: changing values in forked subroutine <rootbeer@teleport.com>
Clean #line-numbering xsubpp <jtobey@nfic.com>
Re: Competent Perl Programmer Needed (O'Shaughnessy Evans)
Re: From Unix Perl programming to NT Perl Programming.. <dean@tbone.biol.sc.edu>
Re: get a file at a url PLEASE HELP!!!! <rootbeer@teleport.com>
Re: IIS Server Hangs when executing a perl script <rootbeer@teleport.com>
Re: Just a long shot ... <rootbeer@teleport.com>
Re: Looking for sh to perl convert program <zenin@best.com>
Re: questions about chop <rootbeer@teleport.com>
Reading from a socket <bob.rich@enterprise.globalec.com>
Re: Scripts don't give the output. <rootbeer@teleport.com>
Re: Server side includes to run Perl scripts from web p (Abigail)
Re: Some PERL questions... <rootbeer@teleport.com>
Re: storing the output of commands to perl variables . <williame@leisureplan.com>
Re: Tricky Searching Problem <nnyxcu@ny.ubs.com>
Re: Tricky Searching Problem <rootbeer@teleport.com>
Re: Unusual Sys::Syslog behaviour ? [Even in 5.004 - a (Alan Schwartz)
Using perl and rlogin (Paul Vermette [NiD/BiM])
Re: yet another perl regex Q (Abigail)
Re: yet another perl regex Q <rootbeer@teleport.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 23 May 1997 09:51:21 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Craig M. Votava" <craig@lucent.com>
Subject: Re: $ARGV not working?
Message-Id: <Pine.GSO.3.96.970523094829.28460Q-100000@kelly.teleport.com>
On Thu, 22 May 1997, Craig M. Votava wrote:
> I seem to be confused about how the scalar special variable $ARGV is
> supposed to work. In both the blue camel and Perl5 Desktop Reference, it
> says:
>
> $ARGV - The name of the current file when reading from <>
> foreach $line (<>) {
> print "Current Filename = $ARGV\n";
> }
But you're getting just the name of the last file, right? That's because
the foreach is slurping up all of the lines at once, so that by the time
you get into your loop, you're actually "on" the last file. You almost
certainly want something like this, which also takes up less memory by
processing one line at a time.
while (defined($line = <>)) {
print "Current Filename = $ARGV\n";
}
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Thu, 22 May 1997 19:05:12 -0700
From: Mark Schaal <mark@tstonramp.com>
Subject: Re: (1+2)**3 == 3!
Message-Id: <3384FB58.3651@tstonramp.com>
Carl B. Quillen wrote:
>
> Can someone explain why this happens? I can't believe that
> the perl parser is set up this way:
>
> print (1+2)**3;
> 3
>
> print 3**3;
> 27
>
You betcha the parser is set up that way. However it does look
kind of strange the first time you encounter it. From the perlfunc
man page:
-----------------
Any function in the list below may be used either with or without
parentheses around its arguments. (The syntax descriptions omit
the parens.) If you use the parens, the simple (but occasionally
surprising) rule is this: It LOOKS like a function, therefore it IS a
function, and precedence doesn't matter. Otherwise it's a list operator
or unary operator, and precedence does matter. And whitespace between
the function and left parenthesis doesn't count--so you need to be
careful sometimes:
print 1+2+3; # Prints 6.
print(1+2) + 3; # Prints 3.
print (1+2)+3; # Also prints 3!
print +(1+2)+3; # Prints 6.
print ((1+2)+3); # Prints 6.
-----------------
Hope that help clear things up.
mark
--
Mark J. Schaal TST On Ramp Sysadmin mark@tstonramp.com
------------------------------
Date: 23 May 1997 18:01:01 +0100
From: Olivier Dehon <dehon_olivier@jpmorgan.com>
Subject: Re: (1+2)**3 == 3!
Message-Id: <njzu3judsxe.fsf@jpmorgan.com>
[posted and mailed]
cbq@shore.net (Carl B. Quillen) writes:
>
> Can someone explain why this happens? I can't believe that
> the perl parser is set up this way:
>
> print (1+2)**3;
> 3
>
> print 3**3;
> 27
>
> (Both in perl 4.0pl36, and perl5.003.)
>
> -Carl (cbq@shore.net).
>
This common mistake is referenced in the faq and in the perl manpages:
print (1+2)**3;
is equivalent to
(print(1+2)) ** 3; # The result of print to the power of 3
Try print +(1+2)**3; instead.
Hope this helps.
Olivier Dehon.
------------------------------
Date: 23 May 1997 17:16:39 GMT
From: d-lewart@uiuc.edu (Daniel S. Lewart)
To: cbq@shore.net (Carl B. Quillen)
Subject: Re: (1+2)**3 == 3!
Message-Id: <5m4jdn$h7u@vixen.cso.uiuc.edu>
cbq@shore.net (Carl B. Quillen) writes:
> Can someone explain why this happens? I can't believe that
> the perl parser is set up this way:
> print (1+2)**3;
> 3
What did "perl -w" have to say about this?
Daniel Lewart
d-lewart@uiuc.edu
------------------------------
Date: Fri, 23 May 1997 13:39:00 -0500
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: (1+2)**3 == 3!
Message-Id: <fl_aggie-ya02408000R2305971339010001@news.fsu.edu>
In article <5m4jdn$h7u@vixen.cso.uiuc.edu>, d-lewart@uiuc.edu (Daniel S.
Lewart) wrote:
+ > print (1+2)**3;
+ What did "perl -w" have to say about this?
The following:
print (...) interpreted as function at - line 1.
Useless use of exponentiation in void context at - line 1.
Woohoo!
James - but is there a "useless use of 'cat'" error/warning?
--
Consulting Minister for Consultants, DNRC
Support the anti-Spam amendment <url:http://www.cauce.org/>
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>
------------------------------
Date: Thu, 22 May 1997 18:58:40 -0700
From: Mark Schaal <mark@tstonramp.com>
Subject: Re: \b refuses to work properly
Message-Id: <3384F9D0.62E@tstonramp.com>
Your algorithm doesn't work for multiple terms. As long
as the first term matches, it immediately highlights the
line. My mind's kind of slushy this morning, but I think
the following will do what you want:
line: while ($string = <CITYFILE>) {
foreach $term (@terms) {
if ($string !~ /\b$term\b/i) { next line; }
$string =~ s#$highlight#<B>$&</B>#gio;
}
print "$string";
}
zingbust@montana.com wrote:
>
> Hi, I'm trying to write a search tool for my web site, such that
> if someone searches on some words that are on a line or lines of
> my database, the corresponding lines where a match occurs will be
> returned to their browser. I want all searched words to be
> boolean AND automatically. I don't want partial words to match,
> so I have this snippet of code...
mark
--
Mark J. Schaal TST On Ramp Sysadmin mark@tstonramp.com
------------------------------
Date: 22 May 1997 09:28:13 -0400
From: jared@node6.frontiernet.net (Jared Evans)
Subject: Access, ODBC, and the Web
Message-Id: <5m1hli$1ngm$1@node2.frontiernet.net>
I'm running perl 5 under NT with the ODBC perl module. I can read
Access97 databases and display results on the webpages. What I would like to
do now is allow web surfers to fill in values of some fields and submit it to
be updated in the database.
Is this possible with my current setup above? Or would I have to go
along the lines of a SQL server?
-Jared
------------------------------
Date: 23 May 1997 17:20:58 GMT
From: nic@spider.cocoon.co.uk (Nic Gibson)
Subject: Re: Access, ODBC, and the Web
Message-Id: <slrn5obkrc.bhj.nic@spider.cocoon.co.uk>
On 22 May 1997 09:28:13 -0400, Jared Evans <jared@node6.frontiernet.net> wrote:
> I'm running perl 5 under NT with the ODBC perl module. I can read
>Access97 databases and display results on the webpages. What I would like to
>do now is allow web surfers to fill in values of some fields and submit it to
>be updated in the database.
> Is this possible with my current setup above? Or would I have to go
>along the lines of a SQL server?
>
>-Jared
Whilst I wouldn't necessarily suggest that you should use MS Access on the
web (it isn't designed for large scale multi-user work), there's no
reason why you shouldn't do it. Win32::ODBC is perfectly capable of updating
tables in much the same way as one uses it to read from them.
All you would need to do is write a few update or insert queries and wrap
a forms interface (I use cgi.pm) on top of it.
If this were to be a site that was going to have a large number of hits, I
would really recommend that you consider a decent database engine rather
than MS Access.
My current project has about 10000 lines of perl that sits on top of
Win32::ODBC and works pretty well perfectly. The only things you need to
take care with are timestamp variables (look up and use the ODBC formats -
you can find them in the driver help files) and making sure you quote in
the insert/update queries.
Oh, and I wrote and tested the whole system using MS Access before we upsized
it to SQL Server. For a while it was running live with 50000 hits a week on
MS Access.
Hope tha answers your questions
Nic
--
Nic Gibson, Senior Programmer, VFM(UK) Ltd.
http://www.global-strategist.com/
Email: nic@global-strategist.com
Phone: 0171 831 7704 Mobile: 0976 408436
------------------------------
Date: Fri, 23 May 1997 08:42:28 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Pierre M. Porter" <pierre_porter@compuware.com>
Subject: Re: Can't get $! to print ERRORLEVEL value
Message-Id: <Pine.GSO.3.96.970523084121.28460J-100000@kelly.teleport.com>
On Thu, 22 May 1997, Pierre M. Porter wrote:
> I wish to use Perl to obtain the ERRORLEVEL code which can
> normally be obtained in a .BAT file by %ERRORLEVEL%.
I think you want Perl's built-in variable $? , which is documented in
perlvar(1). Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 23 May 1997 09:59:05 -0700
From: Andru Luvisi <luvisi@andru.sonoma.edu>
To: denis.trcek@ijs.si
Subject: Re: CGI-ing
Message-Id: <m2sozeunty.fsf@andru.sonoma.edu>
DT <denis.trcek@ijs.si> writes:
>
> Is there anybody out-there that knows how to write a response from
> a HTTP server to a file, that was submitted to this server via
> POST method? Is it possible to do it only with shell programming
> (awk etc...) without using PERL? A code example would be of a
> great help.
I use awk + dd to parse everything up, and sh for the actual
scripting. my awk script is cgiparse.awk (available at
http://andru.sonoma.edu/~luvisi/) and a basic use of it would be:
...
<form action=whatever.sh method=post>
your name: <input type=text size=40 name=name><br>
Comments:<br>
<textarea rows=24 cols=80 name=comments>
</textarea>
<br><input type=submit value="Send your comments">
...
#!/bin/sh
eval `/path/to/cgiparse.awk`
cat >> saved.form.data <<-EOT
Connection from: $REMOTE_HOST
User $FORM_name said:
$FORM_comments
EOT
best of luck,
andru
------------------------------
Date: Fri, 23 May 1997 10:09:33 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: user <user@topnet.de>
Subject: Re: changing values in forked subroutine
Message-Id: <Pine.GSO.3.96.970523100644.28460U-100000@kelly.teleport.com>
On 23 May 1997, user wrote:
> I must do some work in the background while the main program does some
> other work. The background program changes a few variables which I want
> to evaluate in the main programm. Best solution is to share all
> variables so the all value changes in the main or sub get immediately
> changes in the other parts, too.
That makes it hard to get any work done, since any of your variables might
be changed at any time! :-) That's why it doesn't work this way; after a
fork, each process has its own copy of each variable. Changes after a fork
can't affect the other process.
On some systems, you can use shared memory to communicate between
processes; this and other methods are documented in perlipc(1). Hope this
helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Fri, 23 May 1997 13:17:04 -0400
From: John Tobey <jtobey@nfic.com>
Subject: Clean #line-numbering xsubpp
Message-Id: <3385D110.41C67EA6@nfic.com>
Having recently discovered the beauties of Perl XS using 5.003, I
noticed an area for improvement in xsubpp (the perl program that parses
file.xs and outputs C code).
The C code lacked #line directives, so compiler errors pointed to line
numbers in the generated file.c, rather than the true "source" file.xs.
I found myself having to look at file.c to find out where to fix
file.xs.
It was pretty simple to add #line support to xsubpp using fork/pipes.
Below is a diff for xsubpp __version 1.935__ which adds it. (xsubpp is
normally in <perllib>/ExtUtils/.)
After I wrote this, I discovered the xsubpp that came with my 5.004
distribution (xsubpp 1.9402) already prints #line directives, but the
support appears to be buggy. For example, after each section of code
copied directly from file.xs, there is no directive pointing back to
file.c.
I haven't developed XS code using the latest xsubpp, so I can't say for
sure, but after building the modules under 5.004 and comparing c files
with the corresponding xs files, I doubt whether the current line
numbering support can be considered complete.
*** xsubpp Wed Dec 4 20:44:30 1996
--- xsubpp Fri May 23 02:27:57 1997
***************
*** 92,97 ****
--- 92,98 ----
$WantPrototypes = -1 ;
$WantVersionChk = 1 ;
$ProtoUsed = 0 ;
+ $WantLineNumbers = 1 ;
SWITCH: while (@ARGV and $ARGV[0] =~ /^-./) {
$flag = shift @ARGV;
$flag =~ s/^-// ;
***************
*** 103,108 ****
--- 104,111 ----
$WantVersionChk = 1, next SWITCH if $flag eq 'versioncheck';
$except = " TRY", next SWITCH if $flag eq 'except';
push(@tm,shift), next SWITCH if $flag eq 'typemap';
+ $WantLineNumbers = 0, next SWITCH if $flag eq 'nolinenumbers';
+ $WantLineNumbers = 1, next SWITCH if $flag eq 'linenumbers';
(print "xsubpp version $XSUBPP_version\n"), exit
if $flag eq 'v';
die $usage;
***************
*** 226,236 ****
--- 229,262 ----
}
+ if ($WantLineNumbers) {
+ $SECTION_END_MARKER = "*/\01 This can't look like C code!\n";
+ my $pid = open(LINES, "-|");
+ if ($pid) {
+ my $cfile = "$pwd/$filename";
+ $cfile =~ s/\.xs$/.c/ or $cfile .= ".c";
+ while (<LINES>) {
+ if ($_ eq $SECTION_END_MARKER) {
+ print ("#line ", $. + 1, " \"$cfile\"\n");
+ } else {
+ print $_;
+ }
+ }
+ &Exit;
+ } elsif (! defined($pid)) {
+ blurt ("Can't open pipe for line numbering");
+ $WantLineNumbers = 0;
+ }
+ }
+
sub print_section {
$_ = shift(@line) while !/\S/ && @line;
+ print ("#line ", $lastline_no - @line - 1, "
\"$pwd/$filename\"\n")
+ if $WantLineNumbers;
for (; defined($_) && !/^$BLOCK_re/o; $_ = shift(@line)) {
print "$_\n";
}
+ print $SECTION_END_MARKER if $WantLineNumbers;
}
sub process_keyword($)
***************
*** 616,621 ****
--- 642,649 ----
EOM
+
+ print "#line 1 \"$pwd/$filename\"\n" if $WantLineNumbers;
while (<$FH>) {
last if ($Module, $Package, $Prefix) =
------------------------------
Date: 23 May 1997 16:52:34 GMT
From: shaug@callamer.com (O'Shaughnessy Evans)
To: staff@zoron.net
Subject: Re: Competent Perl Programmer Needed
Message-Id: <5m4i0i$6kc$1@zinger.callamer.com>
In article <864089070.16009@dejanews.com>,
staff@zoron.net writes:
> Competent perl programmer needed for full time employment with fast
> growing Internet based company. Salary DOE. contact staff@zoron.net for
> additional information, or to submit resumes. HTML, C and UNIX experience
> a big plus!
I think that a competent webmaster would be useful, as well.
Check out www.zoron.net to see what I mean.
--
O'Shaughnessy Evans
UNIX/Internet Systems Administrator, GST Call America; SLO, CA
------------------------------
Date: 23 May 1997 10:45:04 -0400
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: From Unix Perl programming to NT Perl Programming... Help!
Message-Id: <m1zptm458v.fsf@nauplius.psc.sc.edu>
Daniel Schnaider <snaider@galcom.co.il> writes:
> I a Unix Perl programmer.
> I am trying to make a program in Perl for NT that send me mail after it
> checks some things...
> I dowloaded a program called postmail that suppose to send mail using
> pipe.
> It doesn't seem to work! If somebody know how can I send mail trough
> PERL for NT or how to use this product... let me know
If you were sitting at the NT machine and just wanted to send someone
an email message, how would you do it?
Once you know the answer to that question, you can start following the
pathway to figuring out how to get Perl to compose a message and send
it using the same emailing software you'd use outside of Perl.
-Dean
--
N. Dean Pentcheff <pentcheff@acm.org> WWW: http://tbone.biol.sc.edu/~dean/
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-3936)
PGP ID=768/22A1A015 Keyprint=2D 53 87 53 72 4A F2 83 A0 BF CB C0 D1 0E 76 C0
Get PGP keys and information with the command: "finger dean@tbone.biol.sc.edu"
------------------------------
Date: Fri, 23 May 1997 10:27:03 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: CAD-VISIOGRAPH <visiocad@easynet.fr>
Subject: Re: get a file at a url PLEASE HELP!!!!
Message-Id: <Pine.GSO.3.96.970523102331.28460X-100000@kelly.teleport.com>
On Fri, 23 May 1997, CAD-VISIOGRAPH wrote:
> <HTML><BODY>
> I want to open a file at an URL to print it on my PC with the command :
> <BR>
> <BR>open (toto,"<http://URL/toto.txt"
> <BR>@tableau = <toto>
> <BR>print toto
> <BR>
> <BR>it doesn't WORK !!!
> <BR>
> <BR>thanks
>
> </BODY>
> </HTML>
In the second place, the answer is in the FAQ. In the first place, you
seem to be the victim of a protocol mismatch twice over; you're trying to
use a URL in place of a file name, and you're trying to use HTML in place
of text. (And your Perl code, if it is Perl code, has other problems as
well.) Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Fri, 23 May 1997 08:56:41 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Maillet <rmaillet@inigo.us.dg.com>
Subject: Re: IIS Server Hangs when executing a perl script
Message-Id: <Pine.GSO.3.96.970523085556.28460L-100000@kelly.teleport.com>
On Thu, 22 May 1997, Bob Maillet wrote:
> I am trying to get perl to run on IIS server 3.0 I have installed it
> and all works well in the command line..but when I try to execute a
> script from the web server it just hangs.. Does anyone have any idea?
Sounds like a server problem. Have you checked a server newsgroup? Since
IIS isn't written in Perl, we can't help much here. :-)
Good luck!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Fri, 23 May 1997 09:46:43 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Jerry L. Gubka" <jlguru@cris.com>
Subject: Re: Just a long shot ...
Message-Id: <Pine.GSO.3.96.970523093851.28460O-100000@kelly.teleport.com>
On Thu, 22 May 1997, Jerry L. Gubka wrote:
> [ ... ] In the final lines of the report, I'm trying to sum all the file
> sizes and report total bytes in the client's subdirectory. The problem
> I'm having is that the total byte count is off (compared to a DOS "dir"
> listing), apparently because the report file is part of the directory
> and it is still open and being written to at time file sizes are
> acquired.
>
> My question ... is there something obvious I'm missing, or can someone
> suggest a slick way that the summary byte count in the report can be
> made to match the final byte count in the directory?
You want the report to tell how many bytes the files take up, including
the number of bytes that the report takes up? Well, first you use the
ESP::Precognition module to see how big the file will be... :-)
No, seriously, here's one way to do it. When printing to the file, note
the file position (with the tell() function) before printing the size
number. Since you don't know what the size number will really be, put in
some dummy answer for now, making sure to leave enough room for the final
result. Maybe you could print "Total: xxx,xxx,xxx bytes\n".
When the report is finished and all the files have been written, you can
re-calculate the total. (You'll probably need to close the report file and
re-open it, to be sure that the size is accurate.) Now you can seek() to
that same position in the file and re-print that value, being sure to use
the exact same number of characters. (You can use (s)printf to do this,
using leading spaces as needed.)
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 23 May 1997 13:32:00 GMT
From: Zenin <zenin@best.com>
Subject: Re: Looking for sh to perl convert program
Message-Id: <5m468g$7tn$1@nntp2.ba.best.com>
Ken Hargreaves <ken@zadall.com> wrote:
> Is there any kind of utility to convert bourne shell scripts to perl scripts?
> Thanks.
#!/usr/local/bin/perl
system <<"EndOfBourneScript";
your bourne script goes here
EndOfBourneScript
Actually, I got this from Randal when I asked this question. ;-P
<grin>
-Zenin
zenin@best.com
------------------------------
Date: Fri, 23 May 1997 09:59:27 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Scott <Scott@wwide.com>
Subject: Re: questions about chop
Message-Id: <Pine.GSO.3.96.970523095754.28460S-100000@kelly.teleport.com>
On Thu, 22 May 1997, Scott wrote:
> how do I use the chop command (or whatever one is necessary) to remove
> the end of each line?
> Is their a command to chop say 7 lines off of the end of every line?
You probably want to remove the last seven characters from a line. You can
do this with substr(), which is listed in perlfunc(1). You can match and
remove (or substitute) characters with s///, which is in perlop(1). Hope
this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Fri, 23 May 1997 10:36:39 -0400
From: Robert Rich <bob.rich@enterprise.globalec.com>
Subject: Reading from a socket
Message-Id: <3385AB76.399299DC@enterprise.globalec.com>
I couldn't find anything about this in the FAQ...so i guess i'll just
ask.
I'm trying to do some stuff with sockets, and the problem i'm having is
that whenever i try to read from the socket, the function blocks until
it's read the full lenght that i've specified.
Is there a way to find out how much is available on the socket first?
Or leaving the lenght to read ambiguous so as to read what's available
and nothing more?
I'm having a bit of a hard time finding samples of usages of 'read'.
Thanks for any help/pointers/examples!
Bob
------------------------------
Date: Fri, 23 May 1997 08:35:23 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Aya Fall <ayafall@dartmouth.ccfne.ns.ca>
Subject: Re: Scripts don't give the output.
Message-Id: <Pine.GSO.3.96.970523083449.28460I-100000@kelly.teleport.com>
On Thu, 22 May 1997, Aya Fall wrote:
> 1 - I'created CGI-Scripts,for what should a quite simple application,
> with Perl,
> but they don't produce the expected output (HTML pages).
When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to
solving such problems. It's available on the perl.com web pages. Hope
this helps!
http://www.perl.com/perl/
http://www.perl.com/perl/faq/
http://www.perl.com/perl/faq/idiots-guide.html
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Fri, 23 May 1997 15:40:59 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Server side includes to run Perl scripts from web pages
Message-Id: <EAn4wB.22t@nonexistent.com>
On 23 May 97 11:32:06 GMT, Geoffrey Shuetrim (G.Shuetrim@lse.ac.uk) wrote in
comp.lang.perl.misc
<URL: news:01bc676c$36be47a0$1c628f9e@IBM9772.LSE>:
++ Hello,
++
++ I hope this is the right place to post this question. If not please
++ redirect me.
++
++ I am trying to execute a Perl script to generate a counter on my web page
++ using the following comment tag in the webpage itself.
++
++ <!--#exec cgi="http://cep.lse.ac.uk/fm-cgi-bin/counter.pl"-->
++
++ Where counter.pl is the script I wish to execute and fm-cgi-bin is the
++ virtual location from which I am able to execute such scripts. (I am able
++ to execute scripts from this location when using forms so I do not think
++ the problem is coming from the setup of the location of the script.)
++
++ When the webpage comes up on my browser, instead of a counter, I get the
++ message:
++
++ [an error occurred while processing this directive]
Cool. You don't give use the actual error, you don't give use code,
yet you expect an answer? Come on, you got to be smarter than that.
What does your servers error log say?
What did the people in the CGI group say?
What did the people in the server group say?
Did you check the Idiot's Guide to Solving Perl/CGI Problems? [1]
Did you read the Perl/CGI Faq? [2]
Your problem might be a Perl problem, but without telling us what
the problem is, we can't know (and it usually isn't).
Abigail
[1] http://www.perl.com/perl/faq/cgi/idiots-guide.html
[2] http://www.perl.com/perl/faq/cgi/perl-cgi-faq.html
------------------------------
Date: Fri, 23 May 1997 08:53:48 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Doyle Tracy <doyle@teleport.com>
Subject: Re: Some PERL questions...
Message-Id: <Pine.GSO.3.96.970523084355.28460K-100000@kelly.teleport.com>
On Thu, 22 May 1997, Doyle Tracy wrote:
> 1. Does PERL evaluate AND and OR with or without short-circuiting?
It always short circuits for operators in qw( and or && || ).
> 2. Does PERL perform any implicit type conversions?
> If so, what are they?
> 3. What does PERL use for type equivalence, domain, name, or
> declaration?
Those questions are like going into a sushi restaurant and asking whether
you can get fries with that. :-)
Perl automatically converts between strings and numbers. Some people might
say that it converts to boolean values, and between floating point and
integer as well. Most other conversions are explicit, using functions like
sprintf and pack, which are documented in perlfunc(1).
> 4. What is the domain of the allowable intergers?
> What is the domain of reals?
Perl doesn't normally have an explicit integer type. (For that matter, it
doesn't have a real number type either.) But mostly it will use long for
integers and double for reals. You can make integers as large as you would
like with the Math::BigInteger package, and there's also Math::BigFloat
for reals.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 23 May 1997 15:39:47 GMT
From: "William Evans" <williame@leisureplan.com>
Subject: Re: storing the output of commands to perl variables ..... NT specific
Message-Id: <01bc6790$2b272af0$2ec019c4@bwele>
Here is part of a script that parses the output of the netstat command and
then checks for the number of syn_recieved items in the output.
So I gues you can do many things, from simple to complicated. Parse the
output and assign it to a variable. Do a 'netstat -n -p tcp' to get an
idea as to what the data that is being parsed by this script looks like.
Also if you don't have the 'Programming perl 2nd Edition' aka The camel
book. I highly recommend it. Even though there is a lot of stuff related
to UNIX what is applicable to all operating systems is very good, and there
is tons of information in it.
open(CMD, "netstat -n -p tcp |") or die;
$sync = 0;
while ($line = <CMD>) {
if($line =~ /^\s*TCP\s+([\d\.\:]+)\s+([\d\.\:]+)\s+(SYN_RECEIVED)/){
$sync++;
}
}
--
William Evans
e-mail: williame@leisureplan.com
http://www.leisureplan.com
lji@peakaccess.net wrote in article <33837F63.78B9@peakaccess.net>...
> Hello - is there a straight-forward way of storing the
> output of a sub-command into perl variable (a way that works
> accross platforms - even NT). I'm looking for the
> equivalent of the following in korn shell
> VAR="$(cmd line)"
>
> I would like to avoid using system(" ") to dump to
> a file, and then reading in the file ....
>
> Thanks for any pointers.
>
> Louie I.
>
------------------------------
Date: Fri, 23 May 1997 10:34:10 -0400
From: Glen Culbertson <nnyxcu@ny.ubs.com>
To: "Matthew D. Healy" <Matthew.Healy@yale.edu>
Subject: Re: Tricky Searching Problem
Message-Id: <3385AAE2.4A6@ny.ubs.com>
This doesn't look too tricky, actually, unless I am missing something
in your problem. It looks like a fairly straightforward state,
transition task. Supposing I have the open for the handle IN:
while (<IN>) {
$started = 1 if /$STRING_1/;
$group .= $_ if $started;
$found = 1 if $started && /$STRING_2/;
if ($started && (/$STRING_3/ || (++$linesFound > $LINELIMIT))) {
# do your thing with $group, depending of the values
# of $found and /$STRING_3/
$group = '';
$linesFound = $started = $found = 0;
}
}
This approach assumes that a line like
'blah blah STRING_3 blahblahSTRING_2blahblahSTRING_1 blahblah'
would qualify as a group all of its own--that is, that you
do not care about order of the target strings on a given line.
Matthew D. Healy wrote:
>
> Suppose we have a *BIG* text file that is in an unstructured format.
> I want an efficient way of extracting all groups of lines meeting the
> following conditions:
>
> 1. Each group BEGINS with a line containing $STRING_1, and may well
> contain more lines containing that string.
>
> 2. SOMEWHERE within the group of lines can be found a line containing
> $STRING_2
>
> 3. Each group of lines ENDS with a line containing $STRING_3
>
> I cannot figure out how to do this without some incredibly messy
> logic, involving multiple nested loops.
>
> Note that it is condition #2 that has me stonkered. If I just wanted
> every group of lines delimited by $STRING_1 and $STRING_3, then I
> could say something like `sed -n /$STRING_1/,/$STRING_3/,p` or its
> equivalent in pure Perl. It is the added condition that somewhere
> between the begin/end delimiters must be at least one line meeting
> a third condition that has me stonkered. There will most probably
> be multiple chunks beginning and ending with delimiter lines, some
> of which contain the second string and some of which do not. The
> strings in question may or may not be at the beginning of a line,
> but in any case I want to include the entire beginning line and
> the entire ending line.
>
> Also, $STRING_1, $STRING_2, and $STRING_3 are from user input, so
> few assumptions can be made about them. I will filter out all but
> alphanumerics and certain punctuation.
>
> By *BIG* file, I mean, it is not acceptable to slurp the entire
> file, or any significant fraction thereof, into memory at once.
>
> HOWEVER, it CAN be assumed that either (1) any line containing
> $STRING_1 will soon be followed by a line containing $STRING_3
> or else the user has committed an error and should be warned.
> Thus, if there are more than, say, 150 lines not containing
> $STRING_3 following a line containing $STRING_1, then the program
> should die with an appropriate error message instead of continuing
> processing.
> ---------
> As of 21 May 1997, 954 days till Y2K....
> Matthew.Healy@yale.edu
> http://paella.med.yale.edu/~healy
> "But I thought it was pointed at the rabbit *between* my feet!"
> ---------
> Help a victim of severe email harrassment, see
> http://www.geocities.com/~hitchcockc/story.html#fund
> ---------
------------------------------
Date: Fri, 23 May 1997 09:38:01 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Matthew D. Healy" <Matthew.Healy@yale.edu>
Subject: Re: Tricky Searching Problem
Message-Id: <Pine.GSO.3.96.970523085738.28460N-100000@kelly.teleport.com>
On Thu, 22 May 1997, Matthew D. Healy wrote:
> Suppose we have a *BIG* text file that is in an unstructured format.
> I want an efficient way of extracting all groups of lines meeting the
> following conditions:
>
> 1. Each group BEGINS with a line containing $STRING_1, and may well
> contain more lines containing that string.
>
> 2. SOMEWHERE within the group of lines can be found a line containing
> $STRING_2
>
> 3. Each group of lines ENDS with a line containing $STRING_3
You mentioned that each $STRING_1 should be followed by a $STRING_3 within
150 lines, so that helps. Here's the algorithm I'd try.
We'll use a flag ($found) that tells us whether we've found $STRING_2 in
the current section.
The assumption I'm going to make is that when groups of different sizes
might be possible, you want the smallest groups such that you get all
$STRING_2's. (You don't want all the lines from the first $STRING_1 to the
last $STRING_3, I hope!) More precisely, in this algorithm, any $STRING_3
ends the group of lines, and any $STRING_1 starts the group _unless_ we
already found a $STRING_2 earlier in this group.
This is untested code. I have to leave something for you to do, don't I?
:-)
# File is already open for read at the beginning
my $found = 0; # We haven't found $STRING_2 yet
my @buffer = (); # We don't have any lines saved yet
for (<FILE>) {
if (@buffer) { # We're saving lines
push @buffer, $_;
die "Buffer too large" if @buffer > 150;
}
if (index($_, $STRING_1) != -1 and not $found) {
@buffer = $_; # Toss any previous useless buffer
} elsif (index($_, $STRING_3) != -1) {
&process(@buffer) if $found;
# That was the end marker, so...
@buffer = ();
$found = 0;
} elsif (index($_, $STRING_2) != -1 and @buffer) {
$found = 1;
}
}
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 23 May 1997 16:11:39 GMT
From: alansz@mellers1.psych.berkeley.edu (Alan Schwartz)
Subject: Re: Unusual Sys::Syslog behaviour ? [Even in 5.004 - a bug?]
Message-Id: <5m4fjr$rhs@agate.berkeley.edu>
Russ Allbery <rra@stanford.edu> writes:
>Richard Dows <marius@randomc.com> writes:
>
>> I wanted to use Sys::Syslog, and so I tested it with a small script. I
>> get an error like so:
>
>> Undefined subroutine &Sys::Syslog::hostname called at
>> /usr/local/lib/perl5/Sys/Syslog.pm line 92. BEGIN failed--compilation
>> aborted at stest line 3.
>
>This problem is fixed in (the just released) 5.004.
However, 5.004 changed the behavior of Syslog.pm in an icky way.
In 5.003, Syslog called Sys::Hostname to get the name of the
host, and happily used that as the logging host.
Now, Syslog calls Sys::Hostname to get the name of the host,
strips off all the domain info, and uses that as the host:
sub connect {
unless ($host) {
require Sys::Hostname;
my($host_uniq) = Sys::Hostname::hostname();
($host) = $host_uniq =~ /([\w\-]+)/;
}
....etc.....
Was this intentional? It screws up systems which use an FQDN as their
hostname and don't list the stripped-down version in their /etc/hosts
file, because inet_aton fails on the stripped-down name.
Was /([\w\-\.]+)/ what was meant?
- Alan
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Alan Schwartz | Disclaimer: I represent no one
|
alansz@cogsci.berkeley.edu | "Life is what happens to you while
UC Berkeley | you're busy making other plans"
Cognitive Psychology | - J. Lennon
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 23 May 1997 16:50:44 GMT
From: e5ir@jupiter.sun.csd.unb.ca (Paul Vermette [NiD/BiM])
Subject: Using perl and rlogin
Message-Id: <5m4ht4$pbc@sol.sun.csd.unb.ca>
I have been trying to send the password to rlogin through perl
I pass the password as a parameter (don't ask me why thats the way the
wanted it) anyways.. I have been having problems sending the password to
rlogin, as you can pass it has a parameter for obvious reasons..
but I have tried everything I can think of..
you cannot echo password | rlogin machinename
I don't know what else to do.. any suggestionw ould be usefull
all I am passing is the password to login into the machine..
thanks
--
'''
(o o)
.---------oOOO---(_)------------------.
| Paul Vermette [NiD/BiM] |
| e5ir@unb.ca |
| B O D i E S i N M o T i O N |
`----------------------oOOO-----------'
|__|__|
|| ||
ooO Ooo
------------------------------
Date: Fri, 23 May 1997 15:17:03 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: yet another perl regex Q
Message-Id: <EAn3sF.pv@nonexistent.com>
On 23 May 1997 09:06:47 -0400, John L. Allen (allen@gateway.grumman.com)
wrote in comp.lang.perl.misc
<URL: news:5m44p7$9jl@gateway.grumman.com>:
++ In article <EALHoq.ABI@nonexistent.com>, Abigail <abigail@fnx.com> wrote:
++ >On 22 May 1997 15:21:36 GMT, felix k sheng (felix@chance.em.nytimes.com)
++ >wrote in comp.lang.perl.misc
++ ><URL: news:slrn5o8peq.bfc.felix@chance.em.nytimes.com>:
++ >++ On 22 May 1997 11:05:36 -0400, John L. Allen <allen@gateway.grumman.com>
++ >++ wrote:
++ >++ >I know this is probably explained in the Hip Owls book somewhere, but
++ >++ >I don't have it handy, so please suffer my ignorance. Why doesn't
++ >++ >either of the following replace the *last* three blanks in $_ with
++ >++ >'bar'?
++ >++ >
++ >++ > perl -e '$_="foo xxx"; s/ {3}(?=.*)$/bar/; print'
++ >++ > perl -e '$_="foo xxx"; s/ {3}(?=.*?)$/bar/; print'
++ >++
++ >++ you could use this:
++ >++ perl -e '$_="foo xxx"; s/ {3}(?=\S*$)/bar/; print'
++ [...]
++ >
++ >That will fail if there is whitespace after the last 3 spaces.
++ >What you want is to replace 3 spaces not followed 3 spaces.
++ >
++ >$ perl -wle '$_ = "123 45 67"; s/ {3}(?!.* {3})(?! )/XXX/; print;'
++ >123 XXX45 67
++
++ This is meaningless coming from me, I know, but "Brilliant!"
++
++ So this says 'find 3 spaces that aren't followed by 3 spaces anywhere in
++ the remainder of the string _AND_ that aren't immediately followed by a
++ space'. And this is exactly the same as 'find the _last_ three spaces in
++ the string'! Cool.
++
++ I had gotten this far a while after my post
++
++ perl -wle '$_ = "123 45 67"; s/ {3}(?!.* {3})/XXX/; print;'
++ 123 45 XXX 67
++
++ but this will allow matching 3 spaces followed by less than 3 spaces. I
++ couldn't figure out that I needed that trailing (?! ).
++
Yet there is a different way of doing it, which doesn't need the
lookahead. It might be faster for large strings with many spaces:
#!/usr/local/bin/perl -w
$_ = "123 45 67";
$_ = reverse $_; # Reverse the string!
s/ /XXX/; # Change the *first* 3 spaces, note that XXX is in
# reverse order.... ;)
$_ = reverse $_; # Reverse it again!
print $_, "\n";
__END__
123 XXX45 67
Tada!
Abigail
------------------------------
Date: Fri, 23 May 1997 08:34:25 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "John L. Allen" <allen@gateway.grumman.com>
Subject: Re: yet another perl regex Q
Message-Id: <Pine.GSO.3.96.970523083141.28460H-100000@kelly.teleport.com>
On 22 May 1997, John L. Allen wrote:
> Why doesn't either of the following replace the *last* three blanks in
> $_ with 'bar'?
>
> perl -e '$_="foo xxx"; s/ {3}(?=.*)$/bar/; print'
>
> perl -e '$_="foo xxx"; s/ {3}(?=.*?)$/bar/; print'
Several people have pointed out that you could require non-whitespace at
the end, but I think this is what you really wanted.
perl -e '$_="foo xxx"; s/(.*) {3}(?=.*)$/\1bar/; print'
(Perl will always take the first match it finds, but here you can use
greediness to your advantage.) Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
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 522
*************************************