[7416] in Perl-Users-Digest
Perl-Users Digest, Issue: 1041 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 17 21:07:17 1997
Date: Wed, 17 Sep 97 18:00:43 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 17 Sep 1997 Volume: 8 Number: 1041
Today's topics:
Re: &&/|| vs. and/or <alex@tkb.lv>
Re: Add a link script - help! <dwsi@fia.net>
Finding out what they typed <temp.ed.vanderbush@bentley.com>
Re: Forms:Variable number of input values <rootbeer@teleport.com>
Getting a String from the User <alex@cadscape.com>
Re: gfind error (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Hint executing passed script fragments? (dave)
Re: homogenous/nonhomogenous list test? <rootbeer@teleport.com>
How do I change a line in a file? <choco@acpub.duke.edu>
Re: How do I change a line in a file? <tanya_quinn@cacsmail.oise.utoronto.ca>
Re: How do I change a line in a file? (Tad McClellan)
How to assign new vals to hash elements? (dave)
Re: HTTP Client Question <rootbeer@teleport.com>
Impossible dbm size <cjaimet@ican.net>
Re: Parsing e-mail folder (newbie) <thoellri@tobias.corp.adobe.com>
Re: Reading from Named pipes (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Re: REGEXP: Quickie Newbie Inquiry <rootbeer@teleport.com>
Re: REGEXP: Quickie Newbie Inquiry (Tad McClellan)
Re: Script to Capitalize HTML Tags (Tad McClellan)
Selena Sol's Classified Ad Script (Crypted)
Re: simple script <rbush@up.net>
Re: simple script (Tad McClellan)
SOFTWARE: Creating Modules From Class Defs (Aaron Sherman)
Text::Wrap bombs on lines with no white space! jase@cadence.com
Re: The CSV format stinks! <chrisl@bp.com>
Re: Value within range? <rootbeer@teleport.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Sep 1997 17:24:00 GMT
From: "Alexander Smishlajev" <alex@tkb.lv>
Subject: Re: &&/|| vs. and/or
Message-Id: <01bcc38f$ea28e6e0$2588f4c3@alex>
Russell Odom <rjo100@york.ac.uk> wrote in article
<341D4569.9834A315@york.ac.uk>...
>
> Is there any difference between using the '&&' and '||' operators as
> opposed to 'and' & 'or'?
precedence only. see perlop page.
best wishes,
alex.
------------------------------
Date: Wed, 17 Sep 1997 13:21:30 -0600
From: Chris Roberts <dwsi@fia.net>
Subject: Re: Add a link script - help!
Message-Id: <34202DBC.63FB@fia.net>
Aitor wrote:
>
> Hi,
>
> I've got a free for all page at:
>
> http://www.dmedia.net/superlinks
>
> (only spanish links)
>
> The script adds the URL, tittle and description.
> Althought, I'm newbie with perl, now it works fine but I want to limit
> the URLs to 100, so the oldest. one gets deleted. I don't know how to
> do it.
>
> The script now adds the new URL directly to index.html
>
> How is the best way to limit them?
>
> Is there any similar script or just some lines of code as freeware to
> learn it from?
>
> Thanx.
Try using a SSI (server side include) in your html
and show a text file that your script makes.
Count the lines in this file and always add to the top of the list and
delete from the end.
This way you do not need to use the HTML page as part of the mix.
all you do is make a portion of the page IE:the link list!
If you wish to have some example code ask in email
<a href="mailto:chris@dragonware.com">chris@dragonware.com</a>
Chris Roberts
DragonWare Internet Solutions
------------------------------
Date: Wed, 17 Sep 1997 17:08:48 -0400
From: Ed Vander Bush <temp.ed.vanderbush@bentley.com>
Subject: Finding out what they typed
Message-Id: <342046E0.4898@bentley.com>
I nned to know what URL a client entered to come to a certain page... If
locally they type www o get to a page my script will not work. They need
to type www.domainname.com. (The full URL) I need to be able to redirect
them. How can this be done thoguh PERL/CGI?
------------------------------
Date: Wed, 17 Sep 1997 16:37:12 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: NOSPAMrgrasser@acm.org
Subject: Re: Forms:Variable number of input values
Message-Id: <Pine.GSO.3.96.970917163619.5344J-100000@julie.teleport.com>
On Mon, 15 Sep 1997 NOSPAMrgrasser@acm.org wrote:
> I am building a form application that takes values from a form
> and builds a file (i.e. a sql script). The first 15 or so values
> are required - that is - they must exist. After that, they do not
> have to exist. However, once one value is null, all the rest
> will be null. I would like to be able to examine the incoming
> values, put the existing ones in a file, and exit on the
> first null value.
>
> I suspect I am missing something obvious - can anyone
> point me in the right direction?
Yes: You have to tell us where you're stuck! I can't see any problem in
what you state you'd like to do. Try again. :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Wed, 17 Sep 1997 19:10:23 -0500
From: Alex McCool <alex@cadscape.com>
Subject: Getting a String from the User
Message-Id: <34206F99.D356D402@cadscape.com>
Hi,
How can I ask a user for a string value.
single chars are working fine with getc, but I can't get it to work with
a string.
HELP,
Alex McCool
--
/\ /\ /\ http://www.cadscape.com
/+\\~~/||\_/\ /||\~~~~~__ mailto:alex@cadscape.com
/+++\ \/||||\/\\|||\~~~~~_______
Cadscape Inc. To while || ! to while
310-265-6650 FAX:310-265-6655
------------------------------
Date: Wed, 17 Sep 97 16:45:00 -0400
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: gfind error
Message-Id: <342041a2$2$ofn$mr2ice@speaker.kf8nh.apk.net>
In <341ED87C.4173@cs.berkeley.edu>, on 09/16/97 at 12:05 PM,
Cathy Huang <cathyh@cs.berkeley.edu> said:
+-----
| system "gfind . -regex '.*\.\(gif\|pnm\)' -exec ls -l '{}' \; > tmp\n";
| why am i getting the above error for this line in my perl script?
+--->8
Perl interprets backslashes in double-quoted strings, so you have to double
them to pass them through.
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) FORZA CREW!
Warpstock '97: OS/2 for the rest of us! http://www.warpstock.org
------------------------------
Date: Wed, 17 Sep 1997 20:43:12 GMT
From: over@the.net (dave)
Subject: Hint executing passed script fragments?
Message-Id: <34203fd8.2397366@news.one.net>
Hi,
How should a running perl script execute perl script fragments that
are received from a shell script? What is the best way to return
values to the shell script?
Thanks,
Dave
|
| Please visit me at http://w3.one.net/~dlripber
|
| For reply by email, use:
| dlripber@one.net
|________
------------------------------
Date: Wed, 17 Sep 1997 13:05:09 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Raymond K. Bush" <rbush@up.net>
Subject: Re: homogenous/nonhomogenous list test?
Message-Id: <Pine.GSO.3.96.970917125546.28240d-100000@julie.teleport.com>
On Wed, 17 Sep 1997, Raymond K. Bush wrote:
> Is there an efficient way i can check to see if a list of names is
> homogenous. A 1-4 liner please. Right now i am using a foreach and an
> if but somehow this seems like the wrong way and slow
It's hard to make it much more efficient than looping over every element,
since you have to examine each one. You could code it in C, if you really
need speed. I don't know that it would be much faster. (You could
potentially make it a tied array which would "know" whether it had more
than one genus of element, but this might not increase the overall speed.)
> (ps i return when i find one entry not like the others)?
Good method.
> ps this link in the faq seems to be broken.
> http://www.perl.com/CPAN-local/doc/FAQs/FAQ/perlfunc.html
Could you please send that note to the FAQ maintenance address? Thanks.
> --- reply to rbush - at - up - dot - net ---
I don't know why you're spelling it out in your .sig, since you included
it properly in the headers... :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Wed, 17 Sep 1997 16:54:58 -0400
From: Chocolate <choco@acpub.duke.edu>
Subject: How do I change a line in a file?
Message-Id: <Pine.SOL.3.91.970917165249.29638A-100000@teer12.acpub.duke.edu>
How do I change a line in a file from a web page? I have this database
file and there is one entry per line. If the password is correct then
the entry appears and you can edit it. The only thing is how do I
replace the old entry with the new one. I don't want to replace the
whole file just the line that matches the password. How do I do this
using perl?
------------------------------
Date: Wed, 17 Sep 1997 22:32:17 GMT
From: Tanya Quinn <tanya_quinn@cacsmail.oise.utoronto.ca>
Subject: Re: How do I change a line in a file?
Message-Id: <34205A71.4CD6@cacsmail.oise.utoronto.ca>
Chocolate wrote:
>
> How do I change a line in a file from a web page? I have this database
> file and there is one entry per line. If the password is correct then
> the entry appears and you can edit it. The only thing is how do I
> replace the old entry with the new one. I don't want to replace the
> whole file just the line that matches the password. How do I do this
> using perl?
You can open the file for reading and writing, find the line you want to
change, seek to that position and overwrite.
For example,
open (MY_FILE, "+<$myfilename");
$filepos = tell (MY_FILE);
while (<MY_FILE>) {
chop; #remove the newline character
if (!found) {
if ($_ =~ /somepattern/) {
$found = 1;
seek (MY_FILE, $filepos, 0);
print $newstuff;
}
}
$filepos = tell (MY_FILE);
}
This will work if the entry is the same size, otherwise you may be
writing over more of the file, and I think you'll have to do it by
echoing the rest of the file to a new file.
------------------------------
Date: Wed, 17 Sep 1997 19:19:51 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How do I change a line in a file?
Message-Id: <73spv5.678.ln@localhost>
[ comp.lang.perl is not a newsgroup. Please do not post to non-newsgroups ]
Chocolate (choco@acpub.duke.edu) wrote:
: How do I change a line in a file
You read what the Perl FAQ (part 5) says about changing a line in a file.
---------------------
=head2 How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?
Although humans have an easy time thinking of a text file as being a
sequence of lines that operates much like a stack of playing cards --
or punch cards -- computers usually see the text file as a sequence of
bytes. In general, there's no direct way for Perl to seek to a
particular line of a file, insert text into a file, or remove text
from a file.
(There are exceptions in special circumstances. Replacing a sequence
of bytes with another sequence of the same length is one. Another is
using the C<$DB_RECNO> array bindings as documented in L<DB_File>.
Yet another is manipulating files with all lines the same length.)
The general solution is to create a temporary copy of the text file with
the changes you want, then copy that over the original.
$old = $file;
$new = "$file.tmp.$$";
$bak = "$file.bak";
open(OLD, "< $old") or die "can't open $old: $!";
open(NEW, "> $new") or die "can't open $new: $!";
# Correct typos, preserving case
while (<OLD>) {
s/\b(p)earl\b/${1}erl/i;
(print NEW $_) or die "can't write to $new: $!";
}
close(OLD) or die "can't close $old: $!";
close(NEW) or die "can't close $new: $!";
rename($old, $bak) or die "can't rename $old to $bak: $!";
rename($new, $old) or die "can't rename $new to $old: $!";
Perl can do this sort of thing for you automatically with the C<-i>
command-line switch or the closely-related C<$^I> variable (see
L<perlrun> for more details). Note that
C<-i> may require a suffix on some non-Unix systems; see the
platform-specific documentation that came with your port.
# Renumber a series of tests from the command line
perl -pi -e 's/(^\s+test\s+)\d+/ $1 . ++$count /e' t/op/taint.t
# form a script
local($^I, @ARGV) = ('.bak', glob("*.c"));
while (<>) {
if ($. == 1) {
print "This line should appear at the top of each file\n";
}
s/\b(p)earl\b/${1}erl/i; # Correct typos, preserving case
print;
close ARGV if eof; # Reset $.
}
If you need to seek to an arbitrary line of a file that changes
infrequently, you could build up an index of byte positions of where
the line ends are in the file. If the file is large, an index of
every tenth or hundredth line end would allow you to seek and read
fairly efficiently. If the file is sorted, try the look.pl library
(part of the standard perl distribution).
In the unique case of deleting lines at the end of a file, you
can use tell() and truncate(). The following code snippet deletes
the last line of a file without making a copy or reading the
whole file into memory:
open (FH, "+< $file");
while ( <FH> ) { $addr = tell(FH) unless eof(FH) }
truncate(FH, $addr);
Error checking is left as an exercise for the reader.
---------------------
It is MUCH easier to copy it to a temp file and then move the temp file
over the original.
That is how the Unix filesystem operates. It is not a perl thing...
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Sep 1997 20:38:42 GMT
From: over@the.net (dave)
Subject: How to assign new vals to hash elements?
Message-Id: <34203fcf.2388303@news.one.net>
I use references a lot and wish to assign new values to hash elements
without "moving" the "location" of the element.
For example:
%hash = ( 'key1' => 'fred', 'key2' => 'wilma' );
$valref = \$hash{key1};
If I then do:
%hash = %similarHash;
$valref is nolonger valid.
while if I do:
foreach $k ( keys %similarHash ) {
$hash{$k} = $similarHash{$k};
}
$valref remains valid.
I keep thinking there must be a perl func or core library call that's
shorter than the foreach loop, but I'm about ready to give up trying
to find it. Is there anything?
Thanks,
Dave
|
| Please visit me at http://w3.one.net/~dlripber
|
| For reply by email, use:
| dlripber@one.net
|________
------------------------------
Date: Wed, 17 Sep 1997 13:10:28 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: David Lawrence <dontspam_davidla@inquo.com>
Subject: Re: HTTP Client Question
Message-Id: <Pine.GSO.3.96.970917130906.28240f-100000@julie.teleport.com>
On Wed, 17 Sep 1997, David Lawrence wrote:
> The response indicates that the page has been scheduled for indexing.
> It even gives a URL to go to in order to check on the status of
> indexing. When I go to that URL, however, it appears as though the
> server has never heard of that URL at all.
Does the same happen when you don't use Perl? If so, it's not Perl's fault
- it's something at the remote site. If using your browser makes it work,
find out what the browser is doing, and make sure you do the same. :-)
> There has to be some way to completely emulate a browser with my Perl
> socket routine.
When you use Perl to access a web page, Perl _is_ the browser! :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Wed, 17 Sep 1997 15:28:12 -0400
From: Charles Jaimet <cjaimet@ican.net>
Subject: Impossible dbm size
Message-Id: <34202F4C.66B2FDBA@ican.net>
My server says my dbm database file takes up 4,800 GB!
The server doesn't have nearly that much storage space and when I dump
the file to text it's only 239 kB.
The database and all the scripts I use to add/display/modify records
work fine. There are 1067 records and no duplicates.
What's wrong? I've racked my brain and pored through books and online
guides but I can't find the error.
Anybody? Please...
--
Charles Jaimet
cjaimet@ican.net
http://home.ican.net/~cjaimet/
------------------------------
Date: 17 Sep 1997 13:50:13 -0700
From: Tobias Hoellrich <thoellri@tobias.corp.adobe.com>
Subject: Re: Parsing e-mail folder (newbie)
Message-Id: <yjz4t7jd5ru.fsf@tobias.corp.adobe.com>
"David W. Wong" <hmw-dave@pplus.best.com> writes:
> In the next few days I will need to create (or help create) a script
> that will parse the e-mail folder file on a UNIX (actually, SGI IRIX)
> system to get the most recent message and output that message to an
> external text file. The file will be inserted (via server-side include)
> into an HTML file.
>
> To better illustrate the situation, here it is: the crew of a yacht on
> an ocean voyage will be e-mailing their status, messages, etc. to an
> e-mail account on our central server. The most recent message will be
> posted to the HTML page, where visitors of the site can read the
> message.
>
> I'm not looking for a complete solution, but if anyone has/can explain
> how to create a script that will parse the mail folder file and extract
> the most recent message, it would be tremendous help.
>
> Thanks in advance,
>
> Dave
> dave@hmw.com
Looks like you should get "procmail" and process the incoming mail on
your SGI box, filter out the message and simply generate a HTML from
it.
"procmail" is available from:
ftp://ftp.informatik.rwth-aachen.de/pub/packages/procmail/procmail.tar.gz
Hope that helps
Tobias
------------------------------
Date: Wed, 17 Sep 97 20:24:25 -0400
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: Reading from Named pipes
Message-Id: <34207650$1$ofn$mr2ice@speaker.kf8nh.apk.net>
In <874441216.14339@dejanews.com>, on 09/16/97 at 03:23 PM,
tim.feeney@fmr.com said:
+-----
| The read and parse would be in a infinite loop but with the read "blocking"
| on a new line each loop. It will block the first time but not
| subsequest times. I am sure this can be done but have not seen anything
| in CPAN or the FAQ's.
+--->8
It's not a Perl issue, it's a named pipe issue. Namely, unless some process
has it open for write at all times, the script will block until the first
writer opens it, read what is written, then get a persistent EOF when the
writer goes away. The usual way to avoid this is for the reader script to
open the named pipe for read+write, but this leaves you unable to determine
when each client is done (unless it's handled within whatever protocol you're
using to communicate).
| Another question I have is a bit out of the Perl realm but... Will the
| pipe that is created be able to handle multiple writes without having the
| data munged.
+--->8
No. Depending on the specific OS's named pipe implementation, atomic writes
of less than some size may work, but this is neither portable nor reliable if
the named pipe's kernel-side buffers get full.
Two possible solutions:
(1) implement some kind of locking/mutex protocol for access to the named
pipe;
(2) use AF_UNIX sockets instead, so you can process each connection
independently.
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) FORZA CREW!
Warpstock '97: OS/2 for the rest of us! http://www.warpstock.org
------------------------------
Date: Wed, 17 Sep 1997 16:42:21 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: SPIRE demo account <dj_soler@pnl.gov>
Subject: Re: REGEXP: Quickie Newbie Inquiry
Message-Id: <Pine.GSO.3.96.970917163841.5344K-100000@julie.teleport.com>
On Wed, 17 Sep 1997, SPIRE demo account wrote:
> How do I search for a line that contains only capital letters?
/^[A-Z]*\Z(?!\n)/
... is one way, but beware of capital letters other than A-Z. There's a
way to allow for localities, but it's more complex and slower. Hope this
helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Wed, 17 Sep 1997 19:04:14 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: REGEXP: Quickie Newbie Inquiry
Message-Id: <u5rpv5.568.ln@localhost>
SPIRE demo account (dj_soler@pnl.gov) wrote:
: I've delved into 'man perl', read Learning Perl, and listened to 90
: straight minutes of Pearl Jam, and I still can't figure this out.
: How do I search for a line that contains only capital letters? So far
: I'm pointing to this:
: while <FETCH> {
: ..
: ..
: ..
: if (/[^a-z0-9/./?/!/& /r/t/f/n]/) {
: print "All the world is a stage...\n";
: $First_line = $_;
: }
: }
1) most of those slashes should be backslashes
2) some of those that should be backslashes are not needed at all.
(the first four are escaping chars that don't need escaping...)
: Now, if the program was working right, it would print to STDOUT "All the
: world..." only once, but it's printing it for every line that has any
^^^^^^^^^^
Then every line in your data set has at least one upper case character
in it.
: text in it!
: I'm sure the answer to this is obvious, but if anyone can lend a hand
: (and a correct REGEXP), I'd really appreciate it.
The obvious answer is that your pattern must match one character,
anywhere on the line ;-)
It is nearly always better to say what you *do* want to match, rather
than what you do not want to match (and anchor both ends if you want
the entire line to match):
if ( /^[A-Z]$/ ) {
You've left out a bunch of punctuation characters too.
If you want to match only if all letters are upper case, then you
might want to try:
if ( $_ eq "\U$_") {
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Sep 1997 18:34:18 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Script to Capitalize HTML Tags
Message-Id: <qdppv5.e28.ln@localhost>
Nigel Reed (nigelr@convex.hp.com) wrote:
: While this works, it's not foolproof though...consider this tag
: <IMG SRC="graphics/myimgage.gif" ALT="this alternate tag=my picture">
: ends up as
: <IMG SRC="graphics/myimgage.gif" ALT="this alternate TAG=my picture">
: You could just add \" after the = on the #do the attributes line, but
: still not 100% foolproof either. It's a tricky one because of so many
: varibles in the creation of HTML!
: Not critising, just pointing out a potention problem that someone might
: face if they take it "as is"!
Yeah, I knew it was broken when I posted it, but most HTML types
aren't really interested in the completely correct foolproof way
that will work every single time. I just wrote something that
would work on the limited sample data provided in the post.
That way would be to use 'sgmlnorm' (SGML Normalizer, from the SP
package http://www.jclark.com), with a real DTD.
That's problematic, in that the browser manufacturers don't use the
W3 DTD, and do not publish the DTD that they do use (probably
because they do not really do SGML at all).
Trying to do real parsing of a grammer with only regular expressions
is a silly thing to try anyway...
: Tad McClellan (tadmc@flash.net) wrote:
: > s!(</?[a-zA-Z0-9.-]+)!\U$1!g; # do the tags
: > s!([a-zA-Z0-9.-]+\s*=)!\U$1!g; # do the attributes
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Sep 1997 20:31:50 GMT
From: crypted@hotmail.com (Crypted)
Subject: Selena Sol's Classified Ad Script
Message-Id: <34203e22.24407210@news.earthlink.net>
Ok, I really need some help with a problem I am having. I need to
have this script that I am modifying do two things at once. When it
posts the information that a person submits as a new ad I need it to
also send the admin a comfirmation of the ad that was placed. Can
anyone help me figure this one out? Here is a snippet of the code
involved in the ad section of the script. If you can help me please
drop me a line at crypted@crypted.com.
Thanks so much for your help!
Guy
print <<" end_of_html";
<HTML><HEAD><TITLE>Add a Classified Ad - $database</TITLE></HEAD>
<BODY BGCOLOR = "FFFFFF" TEXT = "000000">
<CENTER><H2>Add a Classified Ad </H2><BR>
<FONT SIZE=\"6\" COLOR=\"\#990000\"><B>$database </B></FONT><BR>
<HR WIDTH=\"50%\"></CENTER>
<FORM METHOD = "POST" ACTION = "$database_manager_script_url">
<CENTER>
end_of_html
&create_input_form;
print <<" end_of_html";
</TABLE><CENTER><P>
<INPUT TYPE = "hidden" NAME = "first_name" VALUE =
"$session_first_name">
<INPUT TYPE = "hidden" NAME = "last_name" VALUE =
"$session_last_name">
<INPUT TYPE = "hidden" NAME = "email" VALUE = "$session_email">
<INPUT TYPE = "hidden" NAME = "time" VALUE = "$date">
<INPUT TYPE = "hidden" NAME = "database" VALUE =
"$form_data{'database'}">
<INPUT TYPE = "hidden" NAME = "session_file"
VALUE = "$session_file">
<INPUT TYPE = "submit" NAME = "submit_addition"
VALUE = "Submit Addition">
</form>
<FORM METHOD = "get" ACTION = "$database_manager_script_url">
<INPUT TYPE = "submit" NAME = "return_to_frontpage"
VALUE = "Return to Frontpage">
</CENTER></FORM></BODY></HTML>
end_of_html
exit;
}
------------------------------
Date: Wed, 17 Sep 1997 15:50:17 -0400
From: "Raymond K. Bush" <rbush@up.net>
Subject: Re: simple script
Message-Id: <34203479.1CD9@up.net>
Jiri medlen wrote:
>
> Hi,
>
> Does anybody know, how make assignmet work??
> $num = system ('grep -c \'GET /HTTP\'
> c:\netscape\server\httpd-80\logs\access');
Maybe this will work, dont think you want system for this
open(HD,"grep -c \'GET /HTTP\'
c:\netscape\server\httpd-80\logs\access|"):
while(<HD>){$num=$_;}
close(<HD>);
or even this should work:
$num = 'grep -c \'GET /HTTP\' c:\netscape\server\httpd-80\logs\access' ;
not sure how efficient this is though ... seems like a slow way ...
Anyone else?
> Platform Windows NT 4.0
> Perl 5
>
> simple perl scrip
>
> #!
> print "content-type: text/html\n\n";
> $num = system ('grep -c \'GET /HTTP\'
> c:\netscape\server\httpd-80\logs\access');
> $num += system ('grep -c \'GET /index.html\'
> c:\netscape\server\httpd-80\logs\access');
> print "$num\n";
>
> result
> variable num = 0
>
> Thanks,
>
> -Jiri-
--
--Ray
.70~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~07.
--- reply to rbush - at - up - dot - net ---
--- please include indication of past correspondence ---
--- in order to receive a faster response ---
------------------------------
Date: Wed, 17 Sep 1997 19:13:06 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: simple script
Message-Id: <imrpv5.678.ln@localhost>
Jiri medlen (jmedlen@lpd.sj.nec.com) wrote:
: Does anybody know, how make assignmet work??
I expect somebody does ;-)
Your problem is not the assignment at all. The assignment IS working.
It is assigning the return value from the system call.
That is what you asked it to do.
You probably want to ask it to do something else ;-)
I expect you want to assign the *output* of the grep, not the return
value.
So, a quick look at the documentation for system() in the perlfunc
man page is in order:
------------------------
=item system LIST
Does exactly the same thing as "exec LIST" except that a fork is done
first, and the parent process waits for the child process to complete.
Note that argument processing varies depending on the number of
arguments. The return value is the exit status of the program as
returned by the wait() call. To get the actual exit value divide by
256. See also L</exec>. This is I<NOT> what you want to use to capture
the output from a command, for that you should use merely backticks or
qx//, as described in L<perlop/"`STRING`">.
------------------------
(note that last sentence)
So, a quick look at qx/STRING/ in the perlop man page seems in order ;-)
(i.e. use backticks, not system)
: $num = system ('grep -c \'GET /HTTP\'
: c:\netscape\server\httpd-80\logs\access');
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Sep 1997 19:23:45 -0400
From: ajs@lorien.ajs.com (Aaron Sherman)
Subject: SOFTWARE: Creating Modules From Class Defs
Message-Id: <5vpoq1$6iv@lorien.ajs.com>
This is classparse, a simple script I wrote after getting too tired of
the startup time involved in writing a basic class/package in
perl. The code that it generates will pass -w -Mstrict, but others may
disagree with everything from my way of building a constructor to
indentation style. If you want to take over development of this tool,
let me know. I will not be posting many updates.
YMMV.
Find docs using "perldoc classparse".
----------------------CUT HERE-------------------
#!/usr/bin/perl -w
#
# Parse and regurgitate a class definition file as a set of perl modules.
use strict;
use IO::File;
$0=~s/^.*\///;
my $usage = "Usage: $0 [-d <output dir>] files....\n";
my $outdir = '.';
while(@ARGV && $ARGV[0] =~ /^-/) {
my $arg = shift;
if ($arg eq '-d') {
die $usage unless defined($outdir = shift);
} else {
die $usage;
}
}
my $ident = '[a-z_]\w*(::[a-z_]\w*)*';
my %class;
my $classname;
while(<>) {
# Parse the class definition file
s/^\s+//; s/\s+$//;
next if /^\s*($|\#)/;
if (/^class\s+($ident)/io) {
$classname = $1;
} elsif (/^isa\s+($ident(\s*,\s*$ident)*)/io) {
die "$ARGV:$.: Need classname.\n" if !defined $classname;
my $isa = $1;
@{$class{$classname}->{isa}} = split(/\s*,\s*/,$isa);
} elsif (/^(pure\s+virtual\s+)?method\s+($ident)\s*\(([^\)]*)\)/io) {
die "$ARGV:$.: Need classname.\n" if !defined $classname;
my $virt = $1;
my $method = $2;
my $proto = $4;
my @v;
if ($method eq 'init' || $method eq 'new') {
if (defined($virt) && length($virt)) {
die "Cannot delcare virtual constructor.\n";
}
$class{$classname}->{construct_proto} = $proto;
next;
}
@v = (pure_virtual => 1) if defined($virt) && length $virt;
push(@{$class{$classname}->{methods}},{ name => $method,
proto => $proto,
@v
});
} elsif (/^infile\s+($ident)/io) {
die "$ARGV:$.: Need classname.\n" if !defined $classname;
my $file = $1;
die "$ARGV:$.: Must define \"$file\" before infile.\n"
if !exists $class{$file};
$class{$classname}->{infile} = $file;
} else {
die "$ARGV:$.: Syntax error: unknown command.\n";
}
}
my $class;
my %done = ();
my @classes = sort keys %class;
my $date = `date`;
chop $date;
while(defined($class = shift @classes)) {
# Spit out the module files
my $file = $class;
next if $done{$class};
my $infile = $class{$class}->{infile};
# Do infiles last
if (defined $infile) {
if (!defined($done{$infile})) {
push(@classes,$class);
next;
}
$file = $infile;
}
$done{$class} = 1;
$file =~ s/::/\//g;
$file .= '.pm';
mksubdirs($file,$outdir);
my $fh = IO::File->new();
if (defined $infile) {
open_infile($fh,$outdir,$file);
} else {
$fh->open("> $outdir/$file")||die("Cannot open $file: $!\n");
}
print $fh "\n#\n# $class definition file, written by Classparse.\n";
print $fh "# $date\n#\n\npackage $class;\n\n";
if (!defined($infile)) {
print $fh "require Exporter;\n";
}
my $isa = $class{$class}->{isa};
if (defined($isa)) {
my $base;
foreach $base (@$isa) {
if (!defined($infile) || $base ne $infile) {
print $fh "require $base;\n";
}
}
}
print $fh "use Carp;\n\nuse strict;\n";
print $fh "use vars qw(\@ISA ";
if (!defined($infile)) {
print $fh "\@EXPORT \@EXPORT_OK ";
}
print $fh "\$VERSION);\n\n";
if (defined($isa)) {
$isa = join(' ',@$isa)
} else {
$isa = '';
}
print $fh "\@ISA=qw(Exporter $isa);\n\n";
if (!defined($infile)) {
print $fh "\@EXPORT = qw();\n\@EXPORT_OK = qw();\n\n";
print $fh "\$VERSION = \"0.1\";\nsub VERSION{\$VERSION}\n\n";
}
print $fh "# Constructor for $class.\n";
print $fh "# Add initialization code to init(), not new()\n";
print $fh "sub new {\n";
print $fh " my \$class = shift;\n";
print $fh " my \$obj = bless {}, \$class;\n";
print $fh " # Call base constructors if required.\n";
print $fh " return \$obj->init(\@_);\n";
print $fh "}\n\n";
print $fh "# Initialize data structure, and return self\n";
print $fh "sub init {\n";
print $fh " my \$self = shift;\n";
my $p;
if (defined($p = $class{$class}->{construct_proto})) {
parse_proto($fh,$p,$class,'new');
}
print $fh " return \$self;\n";
print $fh "}\n\n";
output_methods($fh,\%class,$class);
print $fh "# Destructor, called whenever an object is undefed or\n";
print $fh "# goes out of scope.\n";
print $fh "sub DESTROY {\n";
print $fh " my \$self = shift;\n";
print $fh "}\n\n";
print $fh "# ** End of $class\n\n";
print $fh "1; # To keep require happy.\n__END__\n\n";
print $fh "Documentation should go here....\n";
close $fh;
}
sub output_methods {
my $hand = shift;
my $clinfo = shift;
my $class = shift;
my $method;
foreach $method (@{$clinfo->{$class}->{methods}}) {
my $name = $method->{name};
my $proto = $method->{proto};
if ($method->{pure_virtual}) {
print $hand "# Pure virtual method\nsub $name;\n\n";
next;
}
print $hand "sub $name {\n";
print $hand " my \$self = shift;\n";
parse_proto($hand,$proto,$class,$name);
print $hand "}\n\n";
}
}
# Create the subdirectories that the module will go into
sub mksubdirs {
my $file = shift;
my $outdir = shift;
my @subdirs = split(/\/+/,$file);
pop @subdirs;
if (@subdirs || !-d (join '/', @subdirs)) {
my $dir;
my $path = "$outdir";
foreach $dir (@subdirs) {
$path .= '/' if length $path;
$path .= $dir;
-d($path)||mkdir($path,0755)||die("mkdir($path): $!");
}
}
}
# Open an existing module, and prepare to add onto the end
sub open_infile {
my $hand = shift;
my $outdir = shift;
my $file = shift;
$hand->open("+<$outdir/$file")||die("Cannot open $file: $!\n");
my $tmp;
my $where = 0;
while(defined($tmp = <$hand>) && $tmp) {
$where += length($tmp);
if ($tmp =~ /^\# \*\* End of /) {
$tmp = <$hand>;
$where+=length($tmp);
# Seek because of buffering paranoia
seek($hand,$where,0);
last;
}
}
}
# Handle prototypes
sub parse_proto {
my $hand = shift;
my $proto = shift;
my $class = shift;
my $name = shift;
my $param;
my $args = 0;
my $opt_after = -1;
my $opt = '';
foreach $param (split//,$proto) {
if ($param eq "\$") {
$args++;
} elsif ($param eq ';') {
if ($opt_after != -1) {
warn "Only one ; allowed in prototype.\n";
die "In $class\::$name.\n";
}
$opt_after = $args;
} elsif ($param eq '@') {
$opt = 'list';
last;
} elsif ($param eq '%') {
$opt = 'hash';
last;
} else {
die "Unknown prototype char: \"$param\" in $class\::$name\n";
}
}
print $hand " croak(\"Usage: $class\->$name($proto)\") unless ";
if ($opt eq '') {
if ($opt_after == -1) {
print $hand "\@_==$args;\n";
} else {
print $hand "\@_>=$opt_after&&\@_<=$args;\n";
}
} elsif ($opt eq 'list') {
$args = $opt_after if $opt_after != -1;
print $hand "\@_>=$args;\n";
} elsif ($opt eq 'hash') {
my $a = $args;
$a = $opt_after if $opt_after!=-1;
print $hand "\@_>=$a && ";
print $hand "(\@_-$args)/2==int((\@_-$args)/2);\n";
}
print $hand " # Name arguments, here....\n";
}
__END__
=head1 NAME
classparse - Parse a class definition file and produce perl modules.
=head1 SYNOPSIS
classparse classfile.pcd
classparse -d /usr/lib/perl5/site_perl classfile.pcd
=head1 DESCRIPTION
B<classparse> reads a simple class definition file, and produces perl
modules that implement those classes. No implementation details go into
the definition file, the user must add that to the modules after running
classparse.
=head1 DEFINITION FILE
The definition file is a line-oriented file. Blank lines, and lines
beginning with an octothorpe (pound or hash mark) are ignored.
Whitespace is simplified, so indent or space out words as you like.
A command line begins with a keyword, which must be one of the following:
=over 5
=item class
This keyword takes a class name (i.e. package name) as a parameter, and
must exist at the beginning of each class definition, within the file.
=item isa
After this keyword, give a list of all packages which implement base-classes
of this class. This will become the basis of the @ISA list, and will also
control the addition of require statements at the top of the module.
=item infile
If a class is not to be defined in its own file, but in the module file
of another class, list that other classes name after the infile keyword.
=item method
List the name of a method, followed by a perl-style prototype listing
(see B<PROTOTYPES>, below) in parentheses, like so:
method foo($$)
The prototype does not include the object itself, which is always passed
as the third parameter.
=item pure virtual method
Declare a placeholder method by using the "C<sub name;>" syntax. The
syntax of pure virtual method is the same as method, above. The prototype
is ignored.
This is a form of notation, so that the definition files can indicate the
nature of an abstract class. Perl does not have as much of a need for
abstract classes as a language like C++, because it is not as strongly
typed. However, when this notation is used, a class definition may
be easier to read for someone who is not as familiar with Perl.
=back
=head1 CONSTRUCTORS
The definition file is not required to list the constructor as a method.
A sample constructor (C<new>) will be generated by default. If C<new> is
listed as a method, then the prototype will be applied, not to the C<new>
function itself, but to the C<init> function. C<init> is called by new,
once the empty object has been created. C<init>'s job is to construct
the contents of the new object, and perform any other initialization that
is required.
=head1 PROTOTYPES
The prototypes used in the definition file are similar to perl's
prototypes. C<$> indicates a scalar value (be it a regular scalar, reference,
glob, etc). C<@> indicates a list. C<%> indicates a hash. Both C<@> and
C<%> terminate the prototype parsing, as they will suck up any arguments
left on the stack. C<;> may be used to indicate the end of required arguments.
These prototypes are not used to generate perl prototypes, as perl does
not use prototypes in method calls. Instead, they are used to insert run-time
checks into each method for correct calling conventions.
=head1 EXAMPLE
Here is a sample input file:
# Foo is a base class
class Foo
method push($)
method pull()
method click($@)
# Bar is defined inside of Foo.pm
class Bar
infile Foo
method whir(%)
# Foo::Sponge is a derived class of Foo, and overrides click
class Foo::Sponge
method click($@)
method vroom()
=head1 BUGS
It should be possible to re-run B<classparse> on an existing set of
modules, which would be doable if classparse dropped some syntax into
the modules to indicate where it left off, and user code began. But, that
would be ugly.... Hmmmm.
Brace and indentation style of the generated code should be controllable
from command-line switches.
=head1 AUTHOR
Written out of sheer Laziness by Aaron Sherman <ajs@ajs.com>, (c) 1997.
Classparse may be distributed under the same terms as perl itself.
=cut
------------------------------
Date: Wed, 17 Sep 1997 17:51:09 -0600
From: jase@cadence.com
Subject: Text::Wrap bombs on lines with no white space!
Message-Id: <874535872.12703@dejanews.com>
I have a Perl script that reads in a file of text, and then displays that
text wrapped to 80 columns. Text::Wrap works most of the time, except when
there's a line that contains 80 non-white-space characters all in a row.
In that special case, the call to wrap() causes the script to exit with
the error:
couldn't wrap 'blablabla...' /usr/local/lib/perl5/Text/Wrap.pm line 87.
What I need is something that will insert a newline at the last whitespace
character on a line before the wrap column, *or* if no such character is
found the newline should simply be placed at the wrap column position. Is
there such a function?
Thanks,
jase
--
/\ Jase P Wells, Scopus Administrator Email: jase@altagroup.com
/- \ Alta Business Unit of Cadence Direct: 408.523.8706 ____
/-- \ 555 North Mathilda Avenue Main: 408.733.1595 \ /
/______\ Sunnyvale, California 94086 Fax: 408.523.4601 \/
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Thu, 18 Sep 1997 08:49:14 +1000
From: Chris Leach <chrisl@bp.com>
Subject: Re: The CSV format stinks!
Message-Id: <34205E6A.5B5A@bp.com>
In article <5vkofi$dpr$1@wn.aksi.net>,
daniel@aksi.net (Daniel Freeman) writes:
>
> We can even have quotes inside our quotes, oddly, like so:
>
> "MY 3.5" DISK","MY 5" INCH FLOPPY","MY 10" RECORD"
>
> Now the parser for this was a real pain in the butt to write.
If you CVS file was not broken I'd suggest using the CVS module
to parse your file.
I suggest you get whatever produces this file fixed the use
the CVS.
--
Chris Leach Mail: leachcj@bp.com or chrisl@oakton.com.au
Oakton Computing Phone: +61 3 92684771 Fax: +61 3 92684466
------------------------------
Date: Wed, 17 Sep 1997 16:48:50 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Terry Michael Fletcher - PCD ~ <tfletche@pcocd2.intel.com>
Subject: Re: Value within range?
Message-Id: <Pine.GSO.3.96.970917164320.5344L-100000@julie.teleport.com>
On 17 Sep 1997, Terry Michael Fletcher - PCD ~ wrote:
> Craig M. Votava (craig@lucent.com) so eloquently and verbosely pontificated:
> > ---------------------------------------------------------------------
> > #!perl -w
> >
> > my $range = "1..20";
> > my $number = 35;
> >
> > if($number =~ /[$range]/) {print "yes\n"} else {print "no\n"};
> > ----------------------------------------------------------------------
>
> in that regular expression, you have a character class inside the []
> square brackets. remember that it is a giant single-character OR. your
> code creates [1234567891011121314151617181920] which is effectively the
> character class [0-9] or [\d] or simply \d.
Actually, no. That code creates the character class [1..20] which is
effectively [.012] . Which isn't what the author intended, of course!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
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 1041
**************************************