[7319] in Perl-Users-Digest
Perl-Users Digest, Issue: 944 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 29 10:17:19 1997
Date: Fri, 29 Aug 97 07:00:29 -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, 29 Aug 1997 Volume: 8 Number: 944
Today's topics:
Re: 'abandon' hope (was: Re: Need help: how to exit a s (M.J.T. Guy)
Re: Convert to hex (Dirge )
Re: Filtering CR & CRLF from text input (Greg Bacon)
Re: Getting next byte of scalar (Greg Bacon)
Re: Here document with FILEHANDLE ? (Bart Lateur)
Re: How can I print the size of a file???? (Jeremy D. Zawodny)
Re: How can I print the size of a file???? <seay@absyss.fr>
Re: How can I print the size of a file???? <SPAMFREEcolmang@ms.com>
Re: How to treat "\n" as "\n" ? <seay@absyss.fr>
Re: How to treat "\n" as "\n" ? <SPAMFREEcolmang@ms.com>
IPC with perl <"pikal"@fhe.tgm.ac[dot]at>
Re: IPC with perl <seay@absyss.fr>
Re: module problems (dmouse)
Re: Online Help for beginners in Perl (Jay Flaherty)
Out of memory problem <dmills@riag.com>
Password verification with a shadow file ?? mgrabenstein@isinet.com
Pattern Matching <joseph@tcs9000.com>
Re: Pattern Matching <tom@mitra.phys.uit.no>
Re: Perl and FTP (I R A Aggie)
Re: Perl for Win32 - Capturing output from backticks <jwilson@ic.ac.uk>
Re: Reading in a file for use... <SPAMFREEcolmang@ms.com>
Searching <dhayden@netcomuk.co.uk>
Re: Searching (Daniel E. Macks)
Re: SSH and Perl (Kyler Laird)
Re: SSH and Perl <Tony.Curtis@vcpc.univie.ac.at.REMOVE-FOR-MAIL>
Re: URL validation (Martin Lee)
Re: Where is the FAQ? Not at "www.perl.com"! <seay@absyss.fr>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 29 Aug 1997 13:32:57 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: 'abandon' hope (was: Re: Need help: how to exit a sub)
Message-Id: <5u6j29$j2u$1@lyra.csx.cam.ac.uk>
Tom Phoenix <rootbeer@teleport.com> wrote:
>
>Not bad, but I'd probably use this.
>
> open FILE, $file or
> (warn "couldn't open file '$file': $!" and return);
You'd be in trouble if the "warn" failed ...
Mike Guy
------------------------------
Date: 29 Aug 1997 09:03:10 GMT
From: mjw101@york.ac.uk (Dirge )
Subject: Re: Convert to hex
Message-Id: <5u638e$2u3$1@netty.york.ac.uk>
Creeping stealthily through the corridors of comp.lang.perl.misc,
I overheard Tom Phoenix say:
: On 28 Aug 1997, Dave Schenet wrote:
: > I have a script that will pass some data to a CGI script, and some of
: > the values need to be escaped, as they might consist of !@#$%^& etc.
: >
: > I looked through the FAQ, and there is a module available, however, it
: > appears to skip over /?&= and maybe some others, as those are "reserved"
: > for URLs... I need to escape ALL non alphanumeric characters.
: There's a module on CPAN which will do that. Or it will merely encode the
: ones required by the standard. :-) Good luck!
URI::Escape by any chance? it will do it but I found it easier to recode
my own:
sub escape {
my $toescape = shift
$toescape =~ s/(\W)/sprintf("%%%02X", ord($1))/eg;
return $toescape;
}
sub unsecape {
my $tounescape = shift;
$tounescape =~ s/%(\w\w)/chr(hex($1))/eg;
return $tounescape;
}
Hope these help!
--
Michael
"May all your dreams - bar one - be fulfilled"
A Sathuli blessing from the Drenai novels by David Gemmel.
------------------------------
Date: 29 Aug 1997 13:33:41 GMT
From: gbacon@adtran.com (Greg Bacon)
Subject: Re: Filtering CR & CRLF from text input
Message-Id: <5u6j3l$4c7$1@info.uah.edu>
In article <3407d26b.15524002@news.tornado.be>,
bart.mediamind@tornado.be (Bart Lateur) writes:
: The problem was how to remove CRLF's from WITHIN a text field, with
: multiline text, where the user used the return key to preformat his
: text. The question was how to turn this back into one single line.
s/\s+/ /g;
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: 29 Aug 1997 13:39:25 GMT
From: gbacon@adtran.com (Greg Bacon)
To: Tom Grydeland <tom@mitra.phys.uit.no>
Subject: Re: Getting next byte of scalar
Message-Id: <5u6jed$4c7$2@info.uah.edu>
[Posted and mailed]
In article <nqopvqyvwnj.fsf@mitra.phys.uit.no>,
Tom Grydeland <tom@mitra.phys.uit.no> writes:
: split "C*", $buf;
Huh? Do you mean
map { ord } split //, $buf
or perhaps
unpack "C*", $buf
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Fri, 29 Aug 1997 13:19:00 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Here document with FILEHANDLE ?
Message-Id: <340acaf7.2339914@news.tornado.be>
"Jerry Xia" <jxia@worldnet.att.net> wrote:
>Howdy,
>
>Is there any way that I can open a file with using here document? What I am
>trying to do is something like:
>
>open (FTP, "ftp -n $hostname <<EOF
> user xxx
> ls -l
> ...
> bye
> EOF
> |") ;
Make that
open (FTP, "ftp -n $hostname ".<<EOF . "|");
and make sure the EOF is on a line on it's own (no spaces!)
You can't expect interpolation of the <<EOF inside the string, so you'll
have to put it outside of it.
BTW I can't check if this will actually work, but the syntax will do
what you expect.
HTH,
Bart.
------------------------------
Date: Fri, 29 Aug 1997 10:38:17 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: How can I print the size of a file????
Message-Id: <3407a64f.49371582@igate.hst.moc.com>
[cc'd automagically to original author]
On Fri, 29 Aug 1997 01:36:53 -0400, "David J. Thomas"
<thomasdj@wam.umd.edu> wrote:
>I have the following line of code in a cgi-script:
>
> $modTime = (stat($fullFilename))[9];
>
>This returns the last modified date and time of the file.
>I also want to return the size of this file to a variable as well.
Check the perlfunc man page and look up the values returned from
stat().
>One more thing... I'd like to be able to print the total disk space and
>the amount that is used under my quota.
You have't told us which operating system you're on. The procedure
varies from one to the next.
Jeremy
--
Jeremy Zawodny
Internet Technology Group
Information Technology Services
Marathon Oil Company, Findlay Ohio
http://www.marathon.com/
Unless explicitly stated, these are my opinions only--not those of my employer.
------------------------------
Date: Fri, 29 Aug 1997 13:50:04 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: How can I print the size of a file????
Message-Id: <3406B76C.7E54BBAA@absyss.fr>
David J. Thomas wrote:
>
> I have the following line of code in a cgi-script:
>
> $modTime = (stat($fullFilename))[9];
>
> This returns the last modified date and time of the file.
> I also want to return the size of this file to a variable as well.
Well then, why don't you read about stat() in the docs (perlfunc -f
stat). Maybe you'll find something there that does the trick. Or you
could look at the -X file test operators.
> One more thing... I'd like to be able to print the total disk space and
> the amount that is used under my quota.
How would you do it from a shell's prompt? How about "df" and "quota".
Think about them and meditate on "how do I caputre the output of a child
process". Actually, there might even be a CPAN module for df, but I
wouldn't think so for quota.
- doug
------------------------------
Date: Fri, 29 Aug 1997 13:38:55 +0100
From: Gary Colman <SPAMFREEcolmang@ms.com>
To: thomasdj@wam.umd.edu
Subject: Re: How can I print the size of a file????
Message-Id: <3406C2DF.308F@ms.com>
hi David
> I have the following line of code in a cgi-script:
> $modTime = (stat($fullFilename))[9];
> This returns the last modified date and time of the file.
This is equivalent to:
time() - (-M $fullFilename) * 86400
> I also want to return the size of this file to a variable as well.
-S $Fullfilename
or as you have above:
$size = (stat($fullFilename))[7];
Combined, you can do:
($size,$modTime) = (stat($fullFilename))[7,9];
> One more thing... I'd like to be able to print the total disk space
> and the amount that is used under my quota.
parse the output from a `df -k .` as and when you need to, and a
`repquota` or `quota` or whatever command your system uses.
Cheers
Gary
--
remove the SPAMFREE from my email address to mail me
------------------------------
Date: Fri, 29 Aug 1997 12:42:47 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: How to treat "\n" as "\n" ?
Message-Id: <3406A7A7.74AB9B7E@absyss.fr>
dave wrote:
>
> FYI, I found another one today, wanting to put a variable reference in an eval.
> How about:
>
> eval "sub{ MySub \\\$myvar }"
>
> Three backslashes!
what about using something other than double quotes? Single quotes
would have cut down on the toothpicks
eval 'sub { Mysub \$var }';
should do the trick.
- doug
------------------------------
Date: Fri, 29 Aug 1997 13:45:00 +0100
From: Gary Colman <SPAMFREEcolmang@ms.com>
To: Charles DeRykus <ced@bcstec.ca.boeing.com>
Subject: Re: How to treat "\n" as "\n" ?
Message-Id: <3406C44C.296C@ms.com>
Hi Charles
> > example:
> > $a= 'This is the first line.\n"Nope!"';
> > print $a
> >
> > results:
> > This is the first line.\n"Nope!"
> >
> >
> > but I want:
> > This is the first line.
> > Yes!
Using single quotes will not evaluate the \n as a single
character. You want:
$a= "This is the first line.\n\"Nope!\"";
print $a;
Since you wish the Nope! to be in double inverted commas,
you need to escape them so they are not interpreted as the
end of the assignment.
Cheers
Gary
------------------------------
Date: Fri, 29 Aug 1997 11:53:37 +0200
From: "franz m. pikal" <"pikal"@fhe.tgm.ac[dot]at>
Subject: IPC with perl
Message-Id: <5u6627$ipi@scesie10.sie.siemens.at>
Hi all!
I' am sure this is an easy one for you.
I use a perlscript (perl 4) to execute a small c program to start a
database query and to build a dyn. HTML page out of it.. The c program
does all the things needed for the query (login, logout a.s.o.) and then
returns the result on standart output (normally the display).
How can I read the %@*?!! query results and perform some operations
with it, like formating or splitting?
I don't nessesarily need a block of code as an answer, a good link to a
FAQ page is also good (and please dont say 'write +perlFAQ at altavista'
==> 8500 hits covering everything but not my problem ;-)).
many thanks in advance
Franz
----
ps: please reply to my email too (no newsgroup access at home)
email: pikal@fhe.tgm.ac[dot]at (substitute [dot] with . )
------------------------------
Date: Fri, 29 Aug 1997 14:00:48 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: IPC with perl
Message-Id: <3406B9F0.688A7EA6@absyss.fr>
franz m. pikal wrote:
>
> Hi all!
>
> I' am sure this is an easy one for you.
> I use a perlscript (perl 4) to execute a small c program to start a
> database query and to build a dyn. HTML page out of it.. The c program
> does all the things needed for the query (login, logout a.s.o.) and then
> returns the result on standart output (normally the display).
>
> How can I read the %@*?!! query results and perform some operations
> with it, like formating or splitting?
You basically want C's popen() or a shell's backticks? In Perl that
would be open() with a '|' to indicate a pipe or backticks (but Perl
doesn't remove the \n like a shell would). Does this do what you want.
> I don't nessesarily need a block of code as an answer, a good link to a
> FAQ page is also good (and please dont say 'write +perlFAQ at altavista'
I say "man perl" and read. In this case "man perlipc" and scan down to
"Using open() for IPC".
- doug
PS - What is "perlscript" Do you mean "perl script" but have used so
much java lately that you like to run the two together.
PS#2 - Perl4 is dead. Let it rest in peace. It was great in its time,
but that time has passed. What you could do in Perl4 can still be done
in Perl5 (often with no syntax changes), plus you gain lots of stuff.
Beat your sysadmin about the head and shoulders with a blunt heavy
object until he upgrades.
------------------------------
Date: 29 Aug 1997 12:41:21 GMT
From: gt1535b@acmey.gatech.edu (dmouse)
Subject: Re: module problems
Message-Id: <5u6g1h$bv@catapult.gatech.edu>
Russ Allbery (rra@stanford.edu) wrote:
: gt1535b <gt1535b@prism.gatech.edu> writes:
: > Can someone please help me out with this module exporting thing? I'm
: > trying to export some subroutines into my main package so I don't have
: > to qualify the name of the subroutine every time I want to use it.
: Umm, unless you're doing something really strange, this is actually an
: extremely simple thing to do. Take a look at man perlmod for lots of
: examples; the basic idea is:
: package Module::Name;
: use Exporter;
: @ISA = qw(Exporter);
: @EXPORT = qw(sub1 sub2 $variable1 $variable2);
I've got this stuff in there. And in the process of typing this reply,
I realized that the 'Module' was 'module' in the .pm file. I changed
it and it seems I've graduated to other problems.
My next question is about variables. I have some variables that are
assigned to (without being previously declared) within Scti::scti. It
was my understanding that those variables would be visible to the
main package as global package variables, which is what I want them
to be. Is this correct?
Here's some code if it'll help:
In showp:
BEGIN { print "One moment please...\n";
unshift(@INC, 'c:\BOWEN\perl\perl5\sct', 'c:\Usr\test\bin'); }
BEGIN { use File::Copy;
use Scti qw(scti ls cat rm md);
use Nvm; }
In Scti.pm:
package Scti;
require Exporter;
BEGIN {
@ISA = qw(Exporter);
@EXPORT = qw(scti);
@EXPORT_OK = qw(ls cat rm md cp);
}
: and that's all there is to it. Then, when someone does a:
: use Module::Name;
: sub1, sub2, $variable1, and $variable2 will automatically show up as
: accessible.
: (BTW, as a side question to other readers, what's the rationale for
: putting the above use, @ISA, and @EXPORT assignments into a BEGIN {}
: block? I've never had any problems with them as is.)
the rationale is included in the post you followed up to.
thanks,
Daryl
--
<>< Daryl Bowen <><
Georgia Institute of Technology
E-mail: gt1535b@prism.gatech.edu
Siemens Stromberg-Carlson Co-op
------------------------------
Date: 29 Aug 1997 12:56:54 GMT
From: fty@hickory.engr.utk.edu (Jay Flaherty)
Subject: Re: Online Help for beginners in Perl
Message-Id: <5u6gum$806$1@gaia.ns.utk.edu>
Song (songtraveler@halcyon.com) wrote:
: Hello,
: I wonder if there is an in-depth web page for beginners in Perl to
: learn it and then be able to apply it to their web page. Please cc: your
: response to sleigh@halcyon.com.
http://reference.perl.com/query.cgi?tutorials+index
Jay
--
**********************************************************************
Jay Flaherty fty@utk.edu
I want to peacefully die in my sleep, like my grandfather did,
not screaming like the passengers in his car did!
**********************************************************************
------------------------------
Date: Fri, 29 Aug 1997 08:51:03 -0400
From: Daniel Mills <dmills@riag.com>
Subject: Out of memory problem
Message-Id: <3406C5B7.6B17@riag.com>
I running the following simple script on on a VMS machine and get
an "Out of Memory" error whenever the input file is very large (> 10M).
open(TXT,"cbgnl\$dump:dot.sgm");
undef $/;
while(<TXT>){
while(/\d+\s/gs){
;
}
}
This "VMS PERL" surely would not have a static buffer size causing a
crash on dig data - would it?
-- Thankya
=========================================================
Dan Mills
RIAG
dmills@riag.com
---------------------------------------------------------
The opinions expressed here are those of the author only.
Sorry to be so uncreative here but I'm just too busy (or
slow) to do anything about it.
=========================================================
------------------------------
Date: Fri, 29 Aug 1997 07:51:32 -0600
From: mgrabenstein@isinet.com
Subject: Password verification with a shadow file ??
Message-Id: <872858724.21137@dejanews.com>
I need to validate a user's password entered from a Web form. (Sound
familar?) Problem is the system has a shadow password file and I do _not_
want the CGI to have, or call a program with special privledges (ie.
root).
I know about crypt(), getpwnam() etc... Not really going to help me with
out root privledge.
I have a work around, but don't like it. :-) I used the:
use Net::FTP;
module and open a FTP session and logon as that user. Fair amount of
overhead, but it gets the job done. My biggest problem is that the FTP
server we run limits the number of logons to 100 (internal specification).
If I use this method and we are at 100 logons I will not be able to tell
the difference between a wrong password and trying to be the 101
concurrent logon.
Are there any other modules that could do the same thing?
I looked at the read me for telnet and it does not seem to be finished.
A proxy to the "su" command would work fine. Tempted to try an open2()
on that... Hope someone has a better idea though.
Thanks,
Mike
Technical Specialist, ISI
mgrabenstein@isinet.com
require 'std.disclaimers';
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Fri, 29 Aug 1997 13:24:47 +0300
From: Joseph Essas <joseph@tcs9000.com>
Subject: Pattern Matching
Message-Id: <3406A36F.33D3099A@tcs9000.com>
Hi
I need to find the first place in a string where certain string is not
included. For example:
$string="abcdeabce";
I need to find the first place where there is: a..something that not
'bcd'..e
I tried $string=~/a[^(bcd)]e/ but it didn't work
Please help...
Joseph Essas
joseph@tcs9000.com
------------------------------
Date: 29 Aug 1997 13:49:18 +0200
From: Tom Grydeland <tom@mitra.phys.uit.no>
Subject: Re: Pattern Matching
Message-Id: <nqoiuwpw6o1.fsf@mitra.phys.uit.no>
Joseph Essas <joseph@tcs9000.com> writes:
> $string="abcdeabce";
> I need to find the first place where there is: a..something that not
> 'bcd'..e
/a(?!bcd).*e/ *might* be what you want. Your question is too unclear.
> I tried $string=~/a[^(bcd)]e/ but it didn't work
man perlre
> joseph@tcs9000.com
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: Fri, 29 Aug 1997 08:49:41 -0400
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: Perl and FTP
Message-Id: <fl_aggie-ya02408000R2908970849420001@news.fsu.edu>
In article <19970828143601.KAA11335@ladder02.news.aol.com>, cowbys@aol.com
(COWBYS) wrote:
+ I am looking for the easiest way to incorporate FTP commands
Take a look at this posting:
<34058D52.44EADBB@ti.com>
James - it showed on my server this morning, under the 'FTP with perl' thread
--
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: 29 Aug 1997 11:05:39 GMT
From: "Jeff Wilson" <jwilson@ic.ac.uk>
Subject: Re: Perl for Win32 - Capturing output from backticks
Message-Id: <01bcb46a$bb495690$d53ec69b@leicester>
Backticks can be used in Win32. You could also use a pipe or, in this
case, readdir which, combined with grep, is very versatile. Try
something like ....
# BACKTICKS
@fred=`DIR C:\\JWILSON\\PERL`;
while(@fred){print shift(@fred),"\n";}
# PIPE
open(DIR,"DIR C:\\JWILSON\\PERL|");
@fred=<DIR>;
close(DIR);
while(@fred){print shift(@fred),"\n";}
# READDIR
opendir(DIR,"C:\\JWILSON\\PERL");
@fred=grep(!/^\.\.?$/, readdir(DIR));
close(DIR);
while(@fred){print shift(@fred),"\n";}
--
Jeff Wilson
London - UK
Greg Ward <greg@bic.mni.mcgill.ca> wrote in article
<5u4r9a$1n3@sifon.cc.mcgill.ca>...
> Chris Dumas (cdumas@ibm.net) wrote:
> : I am trying to calculate the freespace on a directory. The only
way I
> : can think of doing it is to capture the output from the DIR command
and
> : process the output.
>
> : $dir_out = 'dir';
>
> : This however fails. Does anyone know why?????
>
> Two possibilities: first, those aren't backticks. They're forward
> single-quotes.
>
> Second, even if you were using the right syntax, are you sure
backticks
> work under Windoze? Backticks are presumably implemented using
pipes,
> and I don't know if Windoze (even Win32) works like Unix in this
area.
> RTFM. (For your Perl port, that is.)
>
> Greg
> --
> Greg Ward - Research Assistant
greg@bic.mni.mcgill.ca
> Brain Imaging Centre (WB201)
http://www.bic.mni.mcgill.ca/~greg
> Montreal Neurological Institute voice: (514) 398-4965 (or
1996)
> Montreal, Quebec, Canada H3A 2B4 fax: (514) 398-8948
>
------------------------------
Date: Fri, 29 Aug 1997 13:55:25 +0100
From: Gary Colman <SPAMFREEcolmang@ms.com>
To: Rene Rivers <rrivers@co.broward.fl.us>
Subject: Re: Reading in a file for use...
Message-Id: <3406C6BD.41F3@ms.com>
Hi Rene
> Hi, I need a bit of help. I am trying to write a program that
> requires me to read some information from a text file and put
> it's contents into an array for use. How do I do this?
The following will read in a file, storing each line as an
element in @array
$filename='bob'; # set the filename
undef $/; # undefine the input record separator
open(FILEHANDLE,$filename); # open the file for reading
@array=split(/\n/,<FILEHANDLE>); # slurp the file into the array
BTW - you really should get the Llama or Camel book
(Learning Perl, or Programming Perl, published by O'Reilly
and Associates) for such answers...
Best of luck!
Cheers
Gary
--
remove SPAMFREE from my email address before replying.
------------------------------
Date: 29 Aug 1997 08:58:12 GMT
From: "David Hayden" <dhayden@netcomuk.co.uk>
Subject: Searching
Message-Id: <01bcb459$8d7d0100$6502a713@fce04438.jubilee.ford.com>
I am trying to write a 'searching' script which takes a sinlge word input
and looks through a list of report names and prints the report name if that
word appears in it. The code I have written is as follows:-
#!/usr/local/bin/perl
#Web Program
#
#
print"Enter word to search for\n";
$input = <STDIN>;
open(FILE,"doclist.txt");
$c=1;
while($line=<FILE>){
chop($line);
($rname[$c],$type[$c],$down[$c])=split(/,/,$line);
$c++;
}
$c=1;
while ($c<21) {
$test = $rname[$c];
if ($input=~m/$test/i) {
print $rname[$c],"\n";
}
$c++;
}
This does not work can anyone tell me what's wrong
This is only my second script so please excuse the poor structure etc.
Many Thanks
David Hayden
------------------------------
Date: 29 Aug 1997 09:45:42 GMT
From: dmacks@sas.upenn.edu (Daniel E. Macks)
Subject: Re: Searching
Message-Id: <5u65o6$19q$1@netnews.upenn.edu>
David Hayden (dhayden@netcomuk.co.uk) said:
: This does not work can anyone tell me what's wrong
It's a whole lot easier for us if you mention what tells you
something's wrong (compiler error vs. runtime error vs. segfault
vs. system error vs. functionality error vs. CPU smoke).
Fortunately, you included the code, so I ran it. It "worked," but it
didn't do its stated task (it did what you told it to do, not what you
told us you wanted it to do:) See footnotes for numbered comments.
: #!/usr/local/bin/perl
: #Web Program # [1]
: #
: #
: print"Enter word to search for\n";
: $input = <STDIN>; # [2]
:
: open(FILE,"doclist.txt"); # [3]
: $c=1;
: while($line=<FILE>){
: chop($line); # [4]
: ($rname[$c],$type[$c],$down[$c])=split(/,/,$line);
: $c++;
: }
:
: $c=1;
: while ($c<21) { # [5][6]
: $test = $rname[$c];
: if ($input=~m/$test/i) { # [7][8]
: print $rname[$c],"\n";
: }
: $c++;
: }
[1] First I assume you'll get it working from a command prompt:)
Otherwise, one major problem is that you've not included any of
the CGI interfacing routines (not that there's any great trick to
it).
[2] Keyboard entries usually have \n at the end, so should chop/chomp.
[3] Always always always check for errors. If something doesn't work,
error-checking at every open() will tell you exactly what's wrong
if there's something wrong here, or if not than you'll know that
this statement isn't the problem.
[4] Should probably chomp, since text files sometimes have a habit of
losing the final \n.
[5] Will there always be 21 lines of data? Since you already counted
'em in the first loop, why not use a different loop index and run
0..$c?
[6] This loop construct would look much nicer as for().
[7] This'll find cases where the data file is a substring of the
entered string, which seems the opposite of what you want.
[8] You don't need to bother with a temp variable ($test)...just match
$rname[$c] directly.
dan
--
Daniel Macks
dmacks@a.chem.upenn.edu
dmacks@netspace.org
http://www.netspace.org/~dmacks
------------------------------
Date: 29 Aug 1997 12:18:42 GMT
From: laird@freedom.ecn.purdue.edu (Kyler Laird)
Subject: Re: SSH and Perl
Message-Id: <5u6en2$q2a@mozo.cc.purdue.edu>
Steve_Kilbane@cegelecproj.co.uk writes:
>In article <872785193.26062@dejanews.com>, jjune@midway.uchicago.edu writes:
>> I am currently trying to write a perl script that will utilize ssh and scp [...]
>> turning out to be MUCH more tricky then I had anticipated... has anyone
>> seen any script that does this?... Or better yet... can anyone offer any
>> pointers or advice on how to go about writing something like this?
>At the risk of being slightly heretical, Perl ain't the right hammer for
>this particular nail. Don Libe's Expect is. Expect is design for
>exactly this sort of job - driving terminal-based interactive programs
>that would like to remain terminal-based - and it does it well.
I don't see any reason to use a kludge like Expect
for this application. There shouldn't be any need
to treat ssh as a "terminal-based interactive
program."
I use ssh as a general-purpose pipe for lots of
applications. I also use it to run specific
commands and streams to other programs. Perl can
handle such streams about as well as anything.
--kyler
------------------------------
Date: 29 Aug 1997 15:37:33 +0200
From: Tony #352 <Tony.Curtis@vcpc.univie.ac.at.REMOVE-FOR-MAIL>
To: jjune@midway.uchicago.edu
Subject: Re: SSH and Perl
Message-Id: <7xk9h59kki.fsf@vcpc.univie.ac.at>
Re: SSH and Perl, jjune <jjune@midway.uchicago.edu> said:
jjune> 1) Copy files to many different servers
jjune> automatically; 2) Execute commands on many different
jjune> servers automatically;
Wouldn't rdist be better for this?
You can make (at least some versions of) rdist use ssh.
cfengine would also be a solution.
tony
------------------------------
Date: 29 Aug 1997 12:43:27 GMT
From: anat0010@ermine.ox.ac.uk (Martin Lee)
Subject: Re: URL validation
Message-Id: <5u6g5f$5g0$1@news.ox.ac.uk>
Eric Bohlman (ebohlman@netcom.com) wrote:
: Ben Sandler (ben@remove.this.part.samet.com) wrote:
: : How can I look up a URL from a [command line] Perl script to see if it
: : is valid?
:
: Use the head() function in LWP::Simple.
:
Works with http but does not work with ftp or gopher.
If the URL is not http use the 'deal with input as it arrives' routine
detailed in the LWP cookbook. If you have received >1000 bytes then score it
as valid and exit the routine.
Martin
martin.lee@anat.ox.ac.uk
------------------------------
Date: Fri, 29 Aug 1997 13:29:05 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Where is the FAQ? Not at "www.perl.com"!
Message-Id: <3406B281.2EFBA759@absyss.fr>
John Desmond Curry wrote:
>
> I am a newbie, so please have patience! I have spent hours
> trying to find the Perl FAQ at the various places that previous
> messages on this newsgroup (comp.lang.perl.misc) have said that
> it is at, including "www.perl.com", but none of them exist. So,
> where is it?
Have you tried the FAQ that comes with recent perl5 distributions?
Simply "perldoc perlfaq" should be enough. No need to fire up a web
browser, most everything interesting is already spinning on your disk.
- doug
------------------------------
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 944
*************************************