[6863] in Perl-Users-Digest
Perl-Users Digest, Issue: 488 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 16 16:17:22 1997
Date: Fri, 16 May 97 13: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 Fri, 16 May 1997 Volume: 8 Number: 488
Today's topics:
[Q] Non-intermeshing output streams when capturing STDO <david.s.patterson@boeing.com>
Re: A perl routine to fetch an url (Clay Irving)
Re: Databases under Linux, Unix ? ()
for loop ? <eglamkowski@mathematica-mpr.com>
Re: for loop ? (Mike Stok)
Re: gzip/zmore in perl? (Clay Irving)
Re: HELP: Continously Perl script !! <psrc@corp.airmedia.com>
Re: How to stop FOMAT putting space between fields? <chapman@techctr.buddcompany.com>
Re: Ingres data on the Intranet (Bruce Irvin)
internet sales accounts manager <om@technologynet.com>
Re: Migration from perl 4 to perl 5 <psrc@corp.airmedia.com>
More Elaborate XS tutorial/examples available? (felix k sheng)
More Elaborate XS tutorial/examples available? (felix k sheng)
Mystery characters? ()
need perl module to get form input <qiu@software.org>
Re: need perl module to get form input <khaines@oshconsulting.com>
Output directory dennis@bnr.ca
PERL -> NT SQL Server connections ..... jmolino@peakaccess.net
Re: perl, simple syntax problems (Mike Stok)
piping and user input (Mike MacKenzie)
Re: Q: Perl/Cgi under Windows NT (Magnus Bodin)
Re: regrex question - really basic! (John Moreno)
Re: regrex question - really basic! (Tad McClellan)
Re: regrex question - really basic! bowler@eisner.decus.org
Save Programming? <pircher@informatik.tu-muenchen.de>
Small question <lin.293@postbox.acs.ohio-state.edu>
Re: Small question (Tad McClellan)
Re: Spy people on the Net <Chris.King@swindon-fc.demon.co.uk.mars>
Re: Weather Forecasts via perl (Kyzer)
Re: Weather Forecasts via perl <jay@rgrs.com>
Re: What is "socket.ph" and where can I get it? (Kyzer)
what's this ? "stack dump during die..." <jadams@skimmer.fsl.noaa.gov>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 16 May 1997 16:54:03 GMT
From: "David S. Patterson" <david.s.patterson@boeing.com>
Subject: [Q] Non-intermeshing output streams when capturing STDOUT in a pipe
Message-Id: <337C912B.1CFB@boeing.com>
Howdy,
I've been programming in perl since 1994 and this
is the weirdest problem I've ever seen...
I have a small perl program that prints to STDOUT
in between making system calls to other (non-perl)
programs that also print to STDOUT.
As long as I do not try to pipe the output of my
main perl program to another process when I invoke
it from the command line, everything works as expected.
However, if I do try to pipe the output to another
process (perlprog | tee foo.out -for example)
the output of the program(s) invoked by my main perl
program go to STDOUT first, and the prints from the
main perl program are supressed until that program
terminates. Upon termination, all the stored up
prints from the main perl program print out.
This is a problem because the output is no longer
"intermeshed", i.e. the prints are no longer
appearing in the output stream in the expected order.
Here is an example:
Listing of perl program "run1":
#!/bin/perl
print "line 1 from run1\n";
system ("kscript1 2");
print "line 3 from run1\n";
system ("kscript1 4");
print "line 5 from run1\n";
Listing of child program "kscript1":
#!/bin/ksh
print "$1 from kscript1!"
If run1 is invoked from the command line as follows:
$ run1
The following output (as expected) occurs:
$ run1
line 1 from run1
2 from kscript1!
line 3 from run1
4 from kscript1!
line 5 from run1
$
If, however, one attempts to capture the output of
run1 in a pipe, the following (unexpected!) output
occurs:
$ run1 | tee run1.out
2 from kscript1!
4 from kscript1!
line 1 from run1
line 3 from run1
line 5 from run1
$
What is going on here?
I am currently working on an SGI Indy (Unix) with
perl 5.003 compiled on Irix 5.3.
--
"We're going to keep on repeating history until we get a passing
grade..."
David S. Patterson
david.s.patterson@usa.net
------------------------------
Date: 16 May 1997 10:22:32 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: A perl routine to fetch an url
Message-Id: <5lhqj8$h4h@panix.com>
In <337BBDC2.677E@st.ms.mff.cuni.cz> Jan Krynicky <Jan.Krynicky@st.ms.mff.cuni.cz> writes:
>Clay Irving wrote:
>>
>> In <5lehfp$d9p@nntp.hut.fi> mara@0.0.0.0 (mara) writes:
>>
>> >Do you remember any well documented examples of simple and
>> >sophisticated URL checking?
>>
>> This is an example of a basic, simple no-frills URL checker:
>>
>> #!/usr/local/bin/perl -w
>>
>> use LWP::Simple;
>> use LWP::UserAgent;
>>
>> $url = "http://www.perl.com";
>>
>> $ua = new LWP::UserAgent;
>> $ua->agent("$0/0.1");
>>
>> $req = new HTTP::Request 'GET', $url;
>probably 'HEAD' would be better than 'GET'
> $req = new HTTP::Request 'GET', $url;
$req = new HTTP::Request 'HEAD', $url;
(I think you meant to type)
>just to preserve the bandwith.
Yes, I think you're right -- 'HEAD' seems to work fine.
>From lwpcook - libwww-perl cookbook
<http://www.perl.org/CPAN/doc/wwwman/libwww/lwpcook.html>
The head function really returns a list of meta-information about
the document. The first three values of the list returned are the
document type, the size of the document, and the age of the document.
The 'GET' request returns the entire document, and there's no need to
do that if you just need to validate the URL.
Thanks,
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: 16 May 1997 13:27:52 GMT
From: bjepson@Sol2-5.ids.net ()
Subject: Re: Databases under Linux, Unix ?
Message-Id: <slrn5nonvs.8u.bjepson@Sol2-5.ids.net>
In article <33785CD9.69B3@telebyte.nl>, T. de Konink wrote:
>Hi,
>
>I am making database-applications using Perl, in a very primitive way. I
>simply use text-files with field-delimeters, splitting&joining fields.
>Now it's the time for me to apply a more professional way to store my
>data, but I really do not know how to do it. I've got much experience in
>developping MSAccess databases, but I don't think I could handle these
>kinds of databases using Perl under Unix/Linux. Thats the reason I've
>got the next questions.
>
You're right; Microsoft Access is relatively primitive compared
to the freely redistributable and/or shareware databases available
for Unix.
>QUESTIONS
>1) Is it possible to use MSAcces databases under Perl Unix/Linux, using
>a special module or driver ? When soo, what do I need for it.
You don't want to use MS Access, even if you could. To my knowledge,
no one has written a driver for Access that works under anything but
a Windows-like operating system. Access is not good for any sort of
advanced application, since it is an archaic, lan-based single-tier
database like Fox and other xBase engines. Every single client not only
needs to know that it's using an Access database, but it needs to be
able to physically access the file that contains the database. The
modern way to do this is to use a database server, which uses a
socket-based API, so your client software can connect over the network,
without needing to have the database file on a mounted volume.
>2) What kind of databases should I use (Perl Unix/Linux) to get an good
>performance and have standard functions to read, modify, search, write
>and query records ? What do I need for it ?
I can think of three databases that may be of interest to you:
mini-SQL: Shareware in some instances, freeware if you're a qualifying
non-profit or educational institution. Inexpensive, even if
you do have to pay for it. I use it all the time. Great Perl
support, either through MsqlPerl or DBD::Msql. Get it at:
http://www.hughes.com.au
PostgreSQL: Freely redistributable object-relational database engine.
I don't have a lot of experience with it, but you can
find it at:
http://www.postgreSQL.org
mySQL: Mostly freely redistributable, unless you want to bundle it with
a product. I haven't used it myself, but I intend to check it out
soon. Check it out at:
http://www.tcx.se/
>3) Do you have any examples for me of database-usement under Perl/Linux
>?
>
[...]
See my Msql::RDBMS, which requires the MsqlPerl module, some of the
stuff from LWP (CounterFile, etc.), and the CGI module. Msql and
Msql::RBDMS are in:
http://www.perl.com/CPAN/modules/by-module/Msql/
and LWP (libwww-perl) and CGI are in:
http://www.perl.org/CPAN/modules/by-module/CGI/
http://www.perl.org/CPAN/modules/by-module/LWP/
Hope this helps,
--
Brian Jepson * (bjepson@ids.net) * http://www.ids.net/~bjepson
Int(ra|er)net Database Developer, Author, Crypto-Fluxologist
Non-Prophet Arts Technology Flux: http://www.ids.net/~as220
WWW/Database/NT,Java/Database: http://www.ids.net/~bjepson/books
------------------------------
Date: Fri, 16 May 1997 10:03:14 -0400
From: the count <eglamkowski@mathematica-mpr.com>
Subject: for loop ?
Message-Id: <337C6922.396@mathematica-mpr.com>
if you want something like:
for (; $x > 0; $x--)
can you shorten it to:
for ($x .. 1)
?
hmm... probably:
while ($x--)
would be best in that case, but i'd still be curious about
the for loop.
--
Due to continuing problems with my hotmail account, any mail received
from eglamkowski@hotmail.com dated after 5/9/97 should be considered
fraudulent. I am no longer using my hotmail account, and never will
again; due to the fact that I have been unable to logon for several
days in a row, "Invalid login/password combination", I must assume my
account was hacked and the password changed.
-*-*-> Please do not send mail to, nor accept mail from <-*-*-
-*-*-> eglamkowski@hotmail.com <-*-*-
------------------------------
Date: 16 May 1997 14:33:09 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: for loop ?
Message-Id: <5lhr75$22f@news-central.tiac.net>
In article <337C6922.396@mathematica-mpr.com>,
the count <eglamkowski@mathematica-mpr.com> wrote:
>if you want something like:
>for (; $x > 0; $x--)
>
>can you shorten it to:
>for ($x .. 1)
>?
the .. can only generate ascending sequences so you might want to do
for (reverse 1 .. $x)
>hmm... probably:
>while ($x--)
>would be best in that case, but i'd still be curious about
>the for loop.
It depends, you probably want
while ($x-- > 0)
and this would mean that $x has been decremented at the top of the loop,
but in the first for case $x was decremented at the end of each iteration.
So, if you use the value of $x in the loop they're different.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 16 May 1997 10:39:53 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: gzip/zmore in perl?
Message-Id: <5lhrjp$lk2@panix.com>
In <Pine.GSO.3.95.970515130138.22315A-100000@bvsd.k12.co.us> GuideQueue Master <quemast@bvsd.k12.co.us> writes:
> Is there any way to read and write to a gzip file in PERL w/o
>using an external command? (I'd really hate to fork a shell for this, I
>just re-wrote my log manager in PERL to avoid the extra processes).
As others have replied, Compress::Zlib is the way to go. This is an example
from the pod:
use Compress::Zlib ;
die "Usage: gzcat file...\n"
unless @ARGV ;
foreach $file (@ARGV) {
$gz = gzopen($file, "rb")
or die "Cannot open $file: $gzerrno\n" ;
print $buffer
while $gz->gzread($buffer) > 0 ;
die "Error reading from $file: $gzerrno\n"
if $gzerrno != Z_STREAM_END ;
$gz->gzclose() ;
}
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: Wed, 14 May 1997 13:14:31 -0400
From: Paul S R Chisholm <psrc@corp.airmedia.com>
To: "T. de Konink" <konink@telebyte.nl>
Subject: Re: HELP: Continously Perl script !!
Message-Id: <3379F2F7.2695@corp.airmedia.com>
T. de Konink <konink@telebyte.nl> wrote:
> > I've made an script (chatbox) that accepts socket calls from a browser,
> > via ports 2500 - 2513. This script runs continuously,
> > The problem is that the script runs fine, except it doesn't respond
> > after a while of use (+/-5 hours). I've the feeling that the script
> > grows in memory use.
Tom Phoenix <rootbeer@teleport.com> wrote:
> That can happen. :-) Which version of Perl are you using? Many memory
> leaks have been plugged in recent versions. Have you tried using ps to see
> what the memory use is like, every half hour or so?
Excellent advice.
> > For tasks like sending back information
> > (HTML) to the user, I fork childs to do this.
> Are you reaping the child processes properly? There's no chance that
> they're hanging around, is there? If just one process fails to die every
> ten minutes or so, that could cause this problem.
Part of the answer to Tom's question is, are you using the server example
from the 1996 printing (first and so far only printing of the 2nd
edition) of the Blue Camel (Programming Perl) book? Or have you consulted
the errata at:
http://www.perl.com/perl/critiques/camelrata/
which corrects a bug in how the server example reaps its children.
--
Paul S. R. Chisholm, AirMedia, Inc. (formerly Ex Machina)
mailto:psrc@corp.airmedia.com http://www.corp.airmedia.com/~psrc
I'm not speaking for the company, I'm just speaking my mind
------------------------------
Date: Fri, 16 May 1997 09:43:36 -0400
From: Harold Todd Chapman <chapman@techctr.buddcompany.com>
To: Lack Mr G M <gml4410@ggr.co.uk>
Subject: Re: How to stop FOMAT putting space between fields?
Message-Id: <648F176BBFDEAAEB.B8485A9E9182E72E.E74F1656A67C391D@library-proxy.airnews.net>
Lack Mr G M wrote:
>
>
> format =
> GRID@>>>>>>>>>>> @<<<<<<<<<<<<<<<<<<<<<<<
> $node, "$x$y$z"
> .
>
> Would do it (as I recently discovered as a result of perusing
> perlform for a similar desire), but whether it is the "approved" way.....
>
> --
> ----------- Gordon Lack ----------------- gml4410@ggr.co.uk ------------
> The contents of this message *may* reflect my personal opinion. They are
> *not* intended to reflect those of my employer, or anyone else.
This almost works except I want each floating point number to take up exactly 8
characters.
Thanks.
------------------------------
Date: Fri, 16 May 1997 12:22:47 GMT
From: rbirvin@usgs.gov (Bruce Irvin)
Subject: Re: Ingres data on the Intranet
Message-Id: <EA9x20.LIw@igsrsparc2.er.usgs.gov>
In article <5lcbkg$6l0$1@bilbo.reference.com>, <deepa@ril.com> wrote:
>
>We have huge databases on Ingres. We wish to put some
>web applications which will be able to query the Ingres
>database.
>
>Can anyone make any suggestions.
>We are using the Apache Web Server. Using perl extensively
>for CGI development.
DBI and DBD-Ingres can also be used for accessing an Ingres database.
Both are available from the CPAN sites. I've been using that for the
past two months, and Ingperl for the past two years to access our
project's database and make data available for intranet use.
Bruce Irvin
Disclaimer: This is not an official endorsement of a product, nor is it
the USGS's position on database access or anything else. It's just what
has worked for this database admin at this site.
------------------------------
Date: Fri, 16 May 1997 10:41:30 -0400
From: Olga Mandrugina <om@technologynet.com>
Subject: internet sales accounts manager
Message-Id: <337C721A.669E@technologynet.com>
Sales -- Internet Services:
Exciting career opportunities with a National Internet Services Company.
We seek experienced Inside Sales Reps to call on computer resellers, to
sell new business opportunities selling AT&T Internet hosting services.
Experience selling web site services and/or data processing services
desirable.
Requirements: 2-4 years solid sales experience, good working knowledge
of the Internet, and college degree. Salary + commission + benefits.
Fax cover letter, resume, and salary history to: T. Mattson,
TechnologyNet Inc., Bethesda, MD, 301-654-6364.
Or e-mail to tmattson@technologynet.com
------------------------------
Date: Mon, 12 May 1997 14:38:07 -0400
From: Paul S R Chisholm <psrc@corp.airmedia.com>
To: Quentin Fennessy <quentin@remington.amd.com>
Subject: Re: Migration from perl 4 to perl 5
Message-Id: <3377638F.2F19@corp.airmedia.com>
In article <01bc5c91$2c79e2d0$2285cd80@gorman>,
> <jgorman@acsu.buffalo.edu> wrote:
> Any specific constructs or problematic issues with migrating from perl
> 4 to perl 5?
Quentin Fennessy wrote:
> See perltrap(1) for some 4->5 migration issues.
To quote the character Bit in TRON: "Yes yes yes yes yes yes!"
> The most common one I know of is that lists are interpolated
> inside double quoted strings in 5, and were not in 4.
No, that's *not* what it says. (But it's the way I read it, too, until I
got bitten and re-read what it really says.)
> So you used to be able to say:
> print "Email: fred@usa.net\n";
> And now you should escape the @ to prevent it from trying to
> reference a list named @usa:
> print "Email: fred\@usa.net\n";
In Perl 4, you used to be able to say "fred@usa.net" (no escape) ONLY IF
there was no list variable named "@usa". If there was an array variable
named "@usa", it would be expanded in Perl 4 or Perl 5.
In Perl 5, if you say "fred@usa.net" and there is not a "@usa" variable,
it's an error. That's the change.
Saying "fred\@usa.net" is valid and safe in both Perl 4 and Perl 5.
> I suggest you always run perl with a -w switch on the #! line
> to prevent other problems:
>
> #!/usr/local/bin/perl -w
Yes yes yes yes yes yes! And run "perl -cw foo.pl" before running your
program even once.
--Paul S. R. Chisholm, AirMedia, Inc. (formerly Ex Machina)
mailto:psrc@corp.airmedia.com http://www.corp.airmedia.com/~psrc
I'm not speaking for the company, I'm just speaking my mind
------------------------------
Date: 16 May 1997 14:33:40 GMT
From: felix@chance.em.nytimes.com (felix k sheng)
Subject: More Elaborate XS tutorial/examples available?
Message-Id: <slrn5nosd8.bai.felix@chance.em.nytimes.com>
hello all,
i'm looking, these days, at XS and trying to figure out the way things
are. i'm still going through the various relevant manpages, but was
also wondering if there was anywhere w/ a slightly more elaborate or
real world tutorial/example of it (where an example has a great deal
of step by step explanation - not just a "go look at xxx.pm" - which
i will shortly). any pointers are appreciated.
'lx
--- felix sheng pager 800 979 2171
programmer tel 212 597 8069
the new york times electronic media company e felix@nytimes.com
------------------------------
Date: 16 May 1997 14:35:56 GMT
From: felix@chance.em.nytimes.com (felix k sheng)
Subject: More Elaborate XS tutorial/examples available?
Message-Id: <slrn5noshg.bai.felix@chance.em.nytimes.com>
hello all,
i'm looking, these days, at XS and trying to figure out the way things
are. i'm still going through the various relevant manpages, but was
also wondering if there was anywhere w/ a slightly more elaborate or
real world tutorial/example of it (where an example has a great deal
of step by step explanation - not just a "go look at xxx.pm" - which
i will shortly). any pointers are appreciated.
'lx
--- felix sheng pager 800 979 2171
programmer tel 212 597 8069
the new york times electronic media company e felix@nytimes.com
------------------------------
Date: 16 May 1997 17:33:54 GMT
From: mikane@best.com ()
Subject: Mystery characters?
Message-Id: <5li5q2$g9p$1@nntp1.ba.best.com>
The most frustrating part of programming is when you have a situation
where what you see is not what you get.
I have a script that generates a string representing a path to a file.
The string will not open the directory. When I hard code the exact same
string, it does work. I can print the string generated by the script and compare
it with the hard coded one and they look exactly alike.
I have tried removing blanks, tabs etc with $path=~s/\s//;
Still no luck. Is there a way to view or print all hidden characters?
Mike
------------------------------
Date: 16 May 1997 13:35:54 GMT
From: "Eric Qiu" <qiu@software.org>
Subject: need perl module to get form input
Message-Id: <01bc6207$498b99b0$72081c81@banff>
Hi:
Is there any commercially available perl module or some perl module run on
Linux for sale that reads the entries of a form and stores the information
in a plain text file? The information we want to read from the form
include: name, address, phone number and e-mail address, etc.
Thanks for help.
Eric
------------------------------
Date: Fri, 16 May 1997 12:07:28 -0600
From: "Kirk D. Haines" <khaines@oshconsulting.com>
To: Eric Qiu <qiu@software.org>
Subject: Re: need perl module to get form input
Message-Id: <337CA260.75F883F5@oshconsulting.com>
Eric Qiu wrote:
>
> Hi:
> Is there any commercially available perl module or some perl module run on
> Linux for sale that reads the entries of a form and stores the information
> in a plain text file? The information we want to read from the form
> include: name, address, phone number and e-mail address, etc.
>
> Thanks for help.
Use the CGI.pm module available from CPAN. Here's an untested, quick
and dirty script to do what you want. Note that I would not use this
script as is. You need to add file locking when writing to your
datafile so simultaneous uses don't result in data loss. A better
response to the user would also be nice. However, it does give you the
idea.
#!/usr/bin/perl
use CGI;
$parse = new CGI();
$parse->import_names('q');
open(FILE,">>mydatafile.dat");
print FILE
"$q::name;;$q::address1;;$q::address2;;$q::phone;;$q::email\n";
close(FILE);
print $parse->start_html(-title => "Response",
-BGCOLOR => "black",
-TEXT => "cornsilk");
print
"<b>$q::name;;$q::address1;;$q::address2;;$q::phone;;$q::email</b><br>\n";
print "was just added to the datafile.\n";
print $parse->end_html();
Kirk Haines
OSH Consulting
------------------------------
Date: Fri, 16 May 1997 16:14:35 +0300
From: dennis@bnr.ca
Subject: Output directory
Message-Id: <337C5DBB.310E@bnr.ca>
Hi,
I have a script that proceeses a form and put the info into a file
called comments.htm. Now the file goes to c:\Program Files\perl5\bin
-directory. I'd like to put it into a different drive and directory.
What is the syntax I use?
close(TFILE);
`Type $filename > comments.htm`;
$mailstatus = $?;
unlink("$filename");
Thanks
------------------------------
Date: Fri, 16 May 1997 11:06:52 -0400
From: jmolino@peakaccess.net
Subject: PERL -> NT SQL Server connections .....
Message-Id: <337C780C.4448@peakaccess.net>
Hello folks - there seems to be perl-implemented
convenience library for every SQL DBMS except
MS SQL Server. Does anyone know of such a library?
If not, can anyone suggest a reasonable way of
interfacing with the "isql" utility from perl [on NT,
of course] - that is, sending SQL commands & capturing
the results in perl arrays ....
Thanks for any pointers. Please send reply
via email to lji@peakaccess.net
Louie I
==============================
Louis J. Iacona
ICP/MicroAge
Manager, Internet Services
==============================
------------------------------
Date: 16 May 1997 12:41:28 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: perl, simple syntax problems
Message-Id: <5lhklo$oue@news-central.tiac.net>
In article <337BF101.2362F94B@informatik.fh-hamburg.de>,
ms <malcha_s@informatik.fh-hamburg.de> wrote:
>I have some problems with the syntax about perl:
You might want to look at http://www.oreilly.de/o/prog/einperl/index.html
as this book (which is due for a second edition in the English language
soon) is a reasonable introduction to the core concepts of perl.
>1. How can I handle arguments in sub's:
> sub foo() {
> ($A , $B) = @_;
>
> }
> foo("aaa", "bbb"); #It works
> foo(@S, @T); #It doesn't work. I get always one argument.
Perl arguments are put into a single list, in perl 5.xxx you can use
references to pass things more complex than a simple scalar into a
subroutine.
>2. How can I declare local variables:
> sub foo() {
> local $A; # ????
> $B = "test" # Is $B a global variable ?
> }
sub foo {
local $a; # dynamically scoped variable
my $b; # lexically scoped variable (more like C)
$c = 'test'; # by default a global (but depends on context...)
}
>3. How can I replace a "\n" with a " " ?
>
> $A =~ /???/"abc\ndef";
$A =~ s/\n/ /g; # /g gets all the \n in a string, otherwise it
# would just get the first
>4. How can I find "abc" in a string?
>
> $A =~ /abc/ "123abc456";
> $A =~ /abc/ "123 abc 456";
if ($A =~ /abc/) { ... } # tell whether it's there
$pos = index ($a, 'abc'); # character position of substring
unless ($pos == -1) { ...}
>5. How can I avoid an runtime or compile error like that:
>
> $A = eval "0 || 1" # no error
>
> $B = eval "1z && 1" # error, because z is wrong
You can't avoid the error, but you can manage to trap it using
if ($@) { ... }
after the eval (although it seems a little enthusiastic about reporting
errors to stderr.)
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: Fri, 16 May 1997 12:48:49 -0500
From: mmackenz@indiana.edu (Mike MacKenzie)
Subject: piping and user input
Message-Id: <mmackenz-ya02408000R1605971248490001@news.indiana.edu>
I'm working on some automated mail processing scripts for use at my job as
and e-mail computing consultant. The utility that I'm writing is in Perl and it
expects to have a mail message piped to it -- so I can use Elm's '|'
command to pipe some particular message to the script. It works fine as it
is written now,
but I need to add a feature that shows the message on the screen before sending
the message and then prompts the user for confirmation before sending (so
he can cancel it if it is goofed up for some reason).
The problem I'm having is that once standard input is redirected to receive
the mail message piped to it from elm, I can't get the script to switch
back to accept input from the keyboard.
Can some kind soul suggest a way to accomplish this?
Some "environmental" specifics:
OS: SunOS 5.4
Elm: version 2.4 PL25
Perl: version 5.003
Thanks,
Mike MacKenzie
mmackenz@indiana.edu
------------------------------
Date: Fri, 16 May 1997 14:22:51 GMT
From: Magnus.Bodin@tychonides.se (Magnus Bodin)
Subject: Re: Q: Perl/Cgi under Windows NT
Message-Id: <337f6d9c.596843475@news1.telenordia.se>
Per Marstein <per.marstein@hda.hydro.com> wrote:
>I've installed a web server on a NT.
>
>Unix uses the environment variable $QUERY_STRING to get the input from
>the client.
>
>How to get the same information with a perl cgi-script ?
>
>Per
FAQ FAQ FAQ
$ENV{'QUERY_STRING'}
------------------------------
Date: Fri, 16 May 1997 09:25:56 -0400
From: phenix@interpath.com (John Moreno)
Subject: Re: regrex question - really basic!
Message-Id: <199705160925563623985@roxboro-170.interpath.net>
Eli the Bearded <usenet-tag@qz.little-neck.ny.us> wrote:
] phenix@interpath.com (John Moreno) writes:
] >I am trying to do a extract a email address out of a string using a
] >regular expression.
]
] Dangerous proposition. Have *you* read RFC822?
No.
] >I'm using [^ <]+@[^ \r,>]+ which works as a regular expression. The
] >problem is getting this into a perl statement.
]
] You can put that in a perl statement like thus:
]
] $line =~ m/([^ <]+@[^ \r,>]+)/ && $address=$1;
]
] It will extract the first match in line and put it in $address.
] (If there was no match $address retains its previous value.)
] There is more than one way to do this. :^)
Thanks. I got it to work a couple of hours after asking using:
$emailadd = $_;
$emailadd =~ /([^\s<]+@[^\s\r,>]+)/;
] You, unlike me, apparently have never received mail with a space
] in the localpart. I even sent one such today to the SA here pointing
] out that the MTA seems to handle it in a buggy way.
]
] If you can convince your mailer to send it (good luck with that)
] <"jjj jjj"@qz.little-neck.ny.us> is a valid address for me. This
] is rather esoteric, I will conceed, and your regexp will work better
] than many I have seen brandied about because it is overly generous
] in accepting matches.
]
] I would probably use
]
] m/(?:^|[<\s])([^@>]+@[a-z0-9.-]+)(?:[\s,>]|$)/i
]
] And hope for no (comments) in the host or and no @ or > in the local
] part. These are reasonable assumptions for the *vast* majority of
] addresses.
As you said, I haven't yet encountered a space in the address plus I am
getting the address from two different sources - one of which doesn't
enclose it in <>. I can guarantee that every lines HAS a address but
not the exact format. Of course I guess I COULD look for the <> combo
and take it from there. How often do you encounter names with spaces in
them?
--
John Moreno
------------------------------
Date: Fri, 16 May 1997 08:36:00 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: regrex question - really basic!
Message-Id: <0snhl5.lm4.ln@localhost>
David Alan Black (dblack@icarus.shu.edu) wrote:
: Hello -
: tadmc@flash.net (Tad McClellan) writes:
: >Ronald Fischer (rfi@uebemc.siemens.de) wrote:
: >: >>>>> On Thu, 15 May 1997 18:37:57 -0400
: >: >>>>> "John" == John Moreno <phenix@interpath.com> wrote:
: >: John> I am trying to do a extract a email address out of a string using a
: >: John> regular expression.
: >: John>
: >: John> I'm using [^ <]+@[^ \r,>]+ which works as a regular expression. The
: >: John> problem is getting this into a perl statement.
: >: Not sure if I understand your problem, but, provided the regexp is
: >: correct, and the string to be parsed is in $s, and the result should
: >: be put into $r, you could always write something like this:
: >: $s =~ /(YourRegexpGoesHere)/ and $r=$1;
: >: $1 corresponds to the regexp in the first pair of parentheses.
: >It *might* correspond to the regexp in the parens. If it did not match,
: >then it will correspond to the *previous* regexp's successfully matched
: >parens.
: >$r=$1 if $s =~ /(YourRegexpGoesHere)/;
: >is the usual idiom to avoid that problem.
: But wouldn't the 'and' short-circuit, preventing the assignment to
: $r, with much the same effect as the 'if'?
Oh yeah. Sorry.
: I like the 'if' idiom better, anyway, but just wondering about the
: logical difference.
I don't see any difference...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Fri, 16 May 1997 14:56:20 GMT
From: bowler@eisner.decus.org
Subject: Re: regrex question - really basic!
Message-Id: <1997May16.105620.1@eisner>
In article <199705160925563623985@roxboro-170.interpath.net>, phenix@interpath.com (John Moreno) writes:
> Eli the Bearded <usenet-tag@qz.little-neck.ny.us> wrote:
>
> ] phenix@interpath.com (John Moreno) writes:
> ] >I am trying to do a extract a email address out of a string using a
> ] >regular expression.
> ]
> ] Dangerous proposition. Have *you* read RFC822?
>
> No.
please do go read it. It's actually fairly "enlightening". It's interesting
to see just how strange and address is really allowed to be, but there is a
reasonalby concise BNF description in the RFC.
Bruce
------------------------------
Date: Fri, 16 May 1997 16:09:37 +0200
From: Alex `Taker` Pircher <pircher@informatik.tu-muenchen.de>
Subject: Save Programming?
Message-Id: <337C6AA0.69A1@informatik.tu-muenchen.de>
I'm using a perl script as a CGI and within the script I check
if the file the user inputs in the HTML-Form exists ...
-----------------------
if (-d $file) {...}
open(FILE, $file);
-----------------------
But now I'm asking me, if this is really a save method of checking
if a File is there. Shouldn't I remove all special characters first
like ...
$file =~ s/"//g;
$file =~ s/\[//g;
$file =~ s/\|//g;
...
Couse maybe there are some bugs in Perl, which give access to more
files & directories.
And is there a easy way to remove nearly all special characters, so
that the $file contains only: A-Z a-z / _ -
THX,
Taker
------------------------------
Date: Fri, 16 May 1997 11:33:03 +0100
From: Andrew Lin <lin.293@postbox.acs.ohio-state.edu>
Subject: Small question
Message-Id: <337C37DF.978@postbox.acs.ohio-state.edu>
Hi,
Does Perl 5 have some kind of compiler? All I ever use is the
interpreter but I'm going to try to compile instead.
Was it already installed automatically when I installed Perl on my
PC(win32 version of Perl)? If so, what is the exe name?
Or is there somewhere else I can download the compiler from?
Please email or post a response.
thanks. Andrew lin.293@osu.edu
------------------------------
Date: Fri, 16 May 1997 12:12:38 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Small question
Message-Id: <6i4il5.il.ln@localhost>
Andrew Lin (lin.293@postbox.acs.ohio-state.edu) wrote:
: Does Perl 5 have some kind of compiler? All I ever use is the
: interpreter but I'm going to try to compile instead.
: Or is there somewhere else I can download the compiler from?
Search for "compiler" in the Perl FAQ.
I find it hard to believe that you missed it before posting...
: thanks. Andrew lin.293@osu.edu
Uh huh.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Fri, 16 May 1997 11:47:37 +0100
From: Chris King <Chris.King@swindon-fc.demon.co.uk.mars>
Subject: Re: Spy people on the Net
Message-Id: <rNIRmCAJtDfzEwZ3@swindon-fc.demon.co.uk>
On Thu, 15 May 1997 at 23:16:36 in article <337b9390.2878289@bang-olufsen.dk>, Future-
NET <benh@hotmail.com> writes
>I present here my two most recent software which I hope they interest you.
>they are progammed by Turbo C++ and run under Windows(3.11 and 95).
>here is a short description of these two software.
Totally the wrong NG. Still, let's see what he has to offer...
>1-Robot Spy 1.0
>at my knowledge, this software is the first and the unique of its kind.
>This software allow you to spy your friends who are on the net at the same time
>of you, it permits to see exactly what they do on their screen, pixel by pixel,
>anywhere, in the world, at the condition they are connected to the internet.
Ever get the feeling that this guy has a different idea of what a friend is?
Personally, I'd love it if my friends decided to infect my machine and then use most
of the bandwidth of my modem...
>Robot Mailer 1.1
>The message you are reading presently is sent to more then 20,000 newsgroups
>with
>this software. This program automates FreeAgent, and reach with a connection of
>28,8 Kbauds
>5,000 news per hours. It can also find a maximum of 50,000 e-mail adresses from
>internet and
>send a message in 4 or 5 hours. You can obtain with this sofware the most
>powerful tool of
>mass transmittion on the internet.
Don't you just hate bits of software like this?
--
Chris King
The similarity of any fact mentioned within this post and
any in reality, living or dead, is purely coincidental.
Remove 'mars' from address when replying. I hate spam.
I like corned beef though.
------------------------------
Date: 16 May 1997 17:52:34 GMT
From: junkmail@sysc.abdn.ac.uk (Kyzer)
Subject: Re: Weather Forecasts via perl
Message-Id: <5li6t2$3lh@info.abdn.ac.uk>
Eli the Bearded of usenet-tag@qz.little-neck.ny.us wrote in comp.lang.perl.misc:
: Jack Siler <siler@compstat.wharton.upenn.edu> wrote:
: >I went to some trouble to get rid of extraneous matter.
: This is my favorite out-of-context quote of the week.
It's official! EtB is posting off-topic to get on the top 10 by # of posts!
--
Stuart 'Kyzer' Caie - Kyzer/CSG |undergraduate of Aberdeen University |100%
http://www.abdn.ac.uk/~u13sac |My opinions aren't those of Aberdeen |Amiga -
kyzer@4u.net kyzer@hotmail.com |University or AUCC, thankfully.***** |always!
--
Already too far up the #posts top 10, I'll have to cut down.
------------------------------
Date: 16 May 1997 09:46:45 -0400
From: Jay Rogers <jay@rgrs.com>
To: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: Weather Forecasts via perl
Message-Id: <82raf7msvu.fsf@shell2.shore.net>
fl_aggie@hotmail.com (I R A Aggie) writes:
> This script gives me the following error:
>
> Can't locate object method "new" via package "Net::Telnet" at
> forecast.pl line 6
>
> I just installed libnet 1.0502, along with Data Dumper 2.07. Apparently
> no problems where encountered. Did I goof something??
You need to use the latest Net::Telnet which is no longer found in the
libnet distribution. It's found in CPAN with the other "Net" modules.
--
Jay Rogers
jay@rgrs.com
------------------------------
Date: 16 May 1997 18:00:54 GMT
From: junkmail@sysc.abdn.ac.uk (Kyzer)
Subject: Re: What is "socket.ph" and where can I get it?
Message-Id: <5li7cm$3lh@info.abdn.ac.uk>
Michael Levasseur of levass@gdesystems.com wrote in comp.lang.perl.misc:
: I'm trying to do some FTP inside of a Perl script. When
: I try running the script "ftp.pl" in perl 5, I get an
: error that it can't find "socket.ph". I've gone to CPAN
: and read the notes on IPC. Is "socket.ph" part of Perl
: or is it part of my OS? If it's part of perl, does anyone
Both, AFAIK. It's part of your OS's system includes
/usr/include/sys/*.h
which are for C, the program h2ph can convert these to
perl format, .ph
IIRC, this is outdated news, and apparantly you want to do
this instead:
use Socket;
This file is part of the perl distribution. The socket docs say:
----
This module is just a translation of the C socket.h file.
Unlike the old mechanism of requiring a translated socket.ph
file, this uses the h2xs program (see the Perl source distribution)
----
Also, you'll want to use the Perl 5 module 'Net::FTP' instead of
ftp.pl -- it's old news (apparantly)
: know of where I can get it?
See above (oh, this is assuming you're using a unix machine)
--
Stuart 'Kyzer' Caie - Kyzer/CSG |undergraduate of Aberdeen University |100%
http://www.abdn.ac.uk/~u13sac |My opinions aren't those of Aberdeen |Amiga -
kyzer@4u.net kyzer@hotmail.com |University or AUCC, thankfully.***** |always!
--
Random sig of the day:
BONUS: Present this .sig at Tesco for a 15% discount.
------------------------------
Date: Wed, 14 May 1997 15:52:15 -0600
From: James Adams <jadams@skimmer.fsl.noaa.gov>
Subject: what's this ? "stack dump during die..."
Message-Id: <337A340F.1E9B@skimmer.fsl.noaa.gov>
Hello,
I have a message that has started to come up whenever I run my script
in debugger mode (-d switch):
Stack dump during die enabled outside of evals.
Can anyone enlighten me as to what this may be, if it is anything to
worry about, or how I might fix it ?
Thanks in advance for any suggestions !
-James
P.S. - Please email/Cc: a response to me at jadams@fsl.noaa.gov if
possible - THANKS !
------------------------------
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 488
*************************************