[6570] in Perl-Users-Digest
Perl-Users Digest, Issue: 195 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 28 10:14:13 1997
Date: Fri, 28 Mar 97 07:00:31 -0800
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, 28 Mar 1997 Volume: 8 Number: 195
Today's topics:
Re: Adding to @INC for module installation? <eric@nettown.com>
Re: chat script <alanbond@sky.net>
Re: Checking a '/' chr. is not present <Jan.Krynicky@st.ms.mff.cuni.cz>
Concurrency Issues. (Fred Van Andel)
Re: Counter Help <Jan.Krynicky@st.ms.mff.cuni.cz>
Re: dereferencing an object in a hash? <Jan.Krynicky@st.ms.mff.cuni.cz>
Re: Does perl have constants? <rootbeer@teleport.com>
Re: finding out which user added modules are installed <dmi1@ra.msstate.edu>
Re: finding out which user added modules are installed <dmi1@ra.msstate.edu>
Re: Fork & Memory Allocation Question <Jan.Krynicky@st.ms.mff.cuni.cz>
Re: Functions and operators <rootbeer@teleport.com>
Re: Getting filedates in perl <Jan.Krynicky@st.ms.mff.cuni.cz>
Re: getting year from localtime (I R A Aggie)
Re: Has anyone heard the rumour that Microsoft have bou <Jan.Krynicky@st.ms.mff.cuni.cz>
Re: Newbie asks how do I format a numeric output? <sveerara@cisco.com>
Re: Opening file for reading and writing simultaneously (Nathan V. Patwardhan)
Re: Opening file for reading and writing simultaneously <rra@stanford.edu>
Re: PARADOX <Jan.Krynicky@st.ms.mff.cuni.cz>
Re: Parsing file problem (Mark Katz)
Perl mishandles some multidimensional array references? (Patrick Duff)
Re: Please repost Answer: Re: Q: How to search _VERY_ l <dbenhur@egames.com>
Re: printing associative arrays in order (Michael Constant)
Re: Q: tr (Tad McClellan)
Re: regular expression for check lower case <Jan.Krynicky@st.ms.mff.cuni.cz>
Re: Server Error-what's up? <eric@nettown.com>
Re: Small Database <anirvan@crl.com>
Re: TPJ: Nukes (Brian L. Matthews)
Re: Unix and ease of use (WAS: Who makes more ...) (Pompeo Silingardi)
where can I get oearl for OS/2 (Christian Ascheberg)
Wrapping text in perl <alanbond@sky.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 27 Mar 1997 21:26:06 +0000
From: Eric Poindexter <eric@nettown.com>
To: Jack Siler <siler@compstat.wharton.upenn.edu>
Subject: Re: Adding to @INC for module installation?
Message-Id: <333AE5ED.17975E37@nettown.com>
Jack Siler wrote:
>
> A box on which I use perl has 5.003 installed but not the CPAN
> modules. I'm trying to install some of them in MYHOME/CPAN. libwww,
> IO and CGI go in ok but libnet looks for IO socket in @INC during the
> perl Makefile.PL step and can't find it. It ain't there, it's
> in CPAN. I know one can use PREFIX= to specify an alternate place to
> install modules, I wonder if there's a similar parameter for
> Makefile.PL to add additional places to look for pre-requisite
> modules. I remember (installing on a different machine) using such
> a parameter to point to the perl libs when they were in my home
> directory.
>
> Close to the above subject: Is there a doc/faq that explains the
> module library structure; I can't figure out what goes where- lib/ or
> /lib/site_perl or ...
>
> Thanks very much.
> Jack
>
> siler@wharton.upenn.edu
So you mean like...
perl -include http://www.perl/com/CPAN yourfile
(this is kind of a wish/joke :-)
--
Eric
<mailto:eric@nettown.com>
[http://nettown.com/perl/]
have a good day! (yes, Poindexter is Really my name :-)
------------------------------
Date: Thu, 27 Mar 1997 22:04:12 -0600
From: Alan Bond <alanbond@sky.net>
Subject: Re: chat script
Message-Id: <333B433C.3B02@sky.net>
Selena Sol has has a shareware chat script available at her site
http://www.eff.org/~erict/
M wrote:
>
> can anyone provide me with a chat cgi script?
>
> Thanks.
------------------------------
Date: Mon, 24 Mar 1997 19:42:24 -0800
From: Jan Krynicky <Jan.Krynicky@st.ms.mff.cuni.cz>
To: Kriang Lerdsuwanakij <lerdsuwa@scf.usc.edu>
Subject: Re: Checking a '/' chr. is not present
Message-Id: <333749A0.89E@st.ms.mff.cuni.cz>
Kriang Lerdsuwanakij wrote:
>
> Paul Denman wrote:
> :
> : Hello,
> :
> : I have written a username/password script, and need to check that
> : the following characters are not in either; ":", "/" and " "
> : space).
> :
> : I am using the syntax:
> :
> : if (($FORM{username} !~ /:/) && ($FORM{username} !~ / /)) {
> : ...
> : }
> :
> : I can't work out how to check for the '/' character. (!~ /// doesn't
> : work).
> : Can anyone help me on this?
> :
> : Thanks,
> :
> : Paul Denman
> : pdenman@ims.ltd.uk
>
> Try !~ /\// . The '/' to be checked must be escaped by the prefix '\'
> to distinguish it from the enclosing /.../ .
>
> Kriang
>
Have you both ever try to read the manpage (man perlre) ?
!- m(/| |:)
1) | means or
2) If you use m (for match) you can use almost any delimiter you want.
If the delimiter is a kind of braces you may use them so, (),[],<>,{}
othervise you use it as you would use the slash.
!- m./| |:.
Jenda
------------------------------
Date: Fri, 28 Mar 1997 06:30:56 GMT
From: vanandel@intergate.bc.ca (Fred Van Andel)
Subject: Concurrency Issues.
Message-Id: <333c6563.1939437@news>
How do I create perl code that will allow for simultanous reading and
writing of files by 2 different processes. Ie. I want to use perl to
create *.htm files, but I have no control of when the web server will
try to read those files. Simply locking the files before writing will
mean that the server will fail in its attempted read and send an error
message back to the user and I dont want that. Do I write to a
temperary file and do a rename to minimize the length of time that the
file is unavailable or is there a better way?
Thank you
Fred Van Andel
------------------------------
Date: Mon, 24 Mar 1997 11:40:59 -0800
From: Jan Krynicky <Jan.Krynicky@st.ms.mff.cuni.cz>
To: Arthur Merar <amerar@unsu.com>
Subject: Re: Counter Help
Message-Id: <3336D8CB.1142@st.ms.mff.cuni.cz>
Arthur Merar wrote:
>
> Hello,
>
> I am fairly new to Perl and I am hoping that someone can help me out.
>
> I am trying to write a homepage counter that will display .GIF images.
> I know there are a lot of ready-made counters out there, but this one
> will be different. The .GIF files will not be regular numbers. They
> will be the numbers in Korean. Therefore, some special coding is
> necessary for some extra characters.
>
> Writing the code should not be to hard. What I am having trouble doing
> is displaying the .GIf in the HTML document. How do I display the .GIF
> in an HTML document from within a Perl script?
>
<IMG SRC="counter.pl?page_url">
<!-- This is the real counter. You will update the variable here, and
then generate the image. -->
or, if generating the page on the fly :
<IMG SRC="img_generator.pl?number" ALT="number">
<!-- This script will just make an image of that number. -->
and you have to update the counter variable when generating the page.
> Also, if I have a Perl script that does not give any output, how do I
> call it from an HTML document?
I would recomend.
<IMG SRC="the_cgi.pl" width=0 height=0>
but anyway you should send at least the header, so that the server will
not send an error response.
>
> Thank you,
>
> Arthur
> amerar@unsu.com
> http://www.unsu.com
------------------------------
Date: Mon, 24 Mar 1997 18:48:28 -0800
From: Jan Krynicky <Jan.Krynicky@st.ms.mff.cuni.cz>
To: Arpad Geller <arpad@tezcat.com>
Subject: Re: dereferencing an object in a hash?
Message-Id: <33373CFC.3E0A@st.ms.mff.cuni.cz>
Arpad Geller wrote:
>
> I'm have question about accessing a method as the value
> field when assigning a hash.
>
> I can access $query->param($key) as a scalar value
> properly in the print statement below but I can't
> (no matter how I try to dereference it) get the value
> into the value field of %Quest in the line after that.
>
> Can someone help me with the proper syntax for this to
> help me on my way to fully understanding Perl referencing?
>
> No matter what I've tried, I always get "key=school value=HASH(0x1068fc)"
> and not "key=school value=UIC".
>
> Thanks. CODE:
>
> $query = new CGI;
>
> tie (%Quest, GDBM_File, "filename", &GDBM_WRCREAT, 0640);
>
> @names = $query->param;
>
> foreach $key (@names) {
> print "key = $key value = ", $query->param($key), "\n";
> $Quest{$key} = {$query->param($key)};
^ ^
Why do you use the curly braces here ?
Try
$Quest{$key} = $query->param($key);
> }
>
> untie (%Quest);
>
> --
> Peace,
>
> David Geller
Jenda
------------------------------
Date: Thu, 27 Mar 1997 18:00:56 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Robb Shecter <rshecter@faculty.ed.umuc.edu>
Subject: Re: Does perl have constants?
Message-Id: <Pine.GSO.3.96.970327175327.15008E-100000@kelly.teleport.com>
On 27 Mar 1997, Robb Shecter wrote:
> For the life of me, I can't find out how to declare (and use) constants
> in perl.
You can't do it today. Maybe tomorrow. :-)
Okay, I'll tell you. I've been developing a pragma (basically, a special
kind of module) to give Perl constants. The bad news is that it won't work
for current release versions of Perl, but it works (as far as I know) with
developers' versions 5.003_20 and later, and possibly a few subversions
earlier. If all goes well, it will be part of the upcoming 5.004 release.
For now (and for any time your code might need to run on a machine with
5.003 or earlier) you have some other methods. Here's my favorite.
*pi = \3.14159; # Black magic with typeglobs
print "It's $pi!\n"; # Use it like any scalar
$pi = 4; # Gives a run-time error.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 28 Mar 1997 00:07:27 -0600
From: David Ishee <dmi1@ra.msstate.edu>
Subject: Re: finding out which user added modules are installed
Message-Id: <m3g1xgeehs.fsf@gsubc.dot.edu>
nvp@shore.net (Nathan V. Patwardhan) writes:
> Yes. If you're root, install CPAN.pm, or have your administrator do it.
Cool. I'll check it out.
> : I looked at perllocal.pod on my machine but it doesn't contain info on
> : the module name: only version, install directory, etc.
>
> ??? My perllocal.pod has entries like the following, which seem to show
> the module name: Would it be possible that pod2text/html/whatever is
> having problems with =head3 (I ask this, because mine does)?
Well I'll be a possum in a gum tree! I guess it does have the module
name! It must have hid from me before.
Thanks,
David
+--------------------------------------------------------------------+
| David Ishee |
| Mechanical Engineer, MS grad student dmi1@ra.msstate.edu |
| Mississippi State University |
| |
+------------- http://www2.msstate.edu/~dmi1/index.html -------------+
------------------------------
Date: 28 Mar 1997 00:09:18 -0600
From: David Ishee <dmi1@ra.msstate.edu>
Subject: Re: finding out which user added modules are installed
Message-Id: <m3end0eeep.fsf@gsubc.dot.edu>
Eric Poindexter <eric@nettown.com> writes:
> Web page addresses for below.
> http://nettown.com/perl/Search.cgi?s=CPAN
> http://nettown.com/perl/Search.cgi?s=perllocal
Thanks, I'll get to them momentarily.....
--
David
+--------------------------------------------------------------------+
| David Ishee |
| Mechanical Engineer, MS grad student dmi1@ra.msstate.edu |
| Mississippi State University |
| |
+------------- http://www2.msstate.edu/~dmi1/index.html -------------+
------------------------------
Date: Tue, 25 Mar 1997 22:18:45 -0800
From: Jan Krynicky <Jan.Krynicky@st.ms.mff.cuni.cz>
To: Simon Twigger <simont@post.its.mcw.edu>
Subject: Re: Fork & Memory Allocation Question
Message-Id: <3338BFC5.12BF@st.ms.mff.cuni.cz>
Simon Twigger wrote:
>
> Hi there,
>
> I have a Perl 5 CGI script which creates a sound file from scratch. As
> it goes through creating the sound file it writes the various parts of
> the file to a buffer file [buffer.au]. Having done this I work out the
> sound file header informtion (length of file etc.) and print this to the
> final file and follow it up by opening up the buffer.au file and
> printing that to the final file as well. I do this because the header
> has to be at the start of the file and I dont know how big the file is
> until I've made it! Consequently I have to store it somewhere before
> assembling it into the final .au format.
>
> This all works fine, however, it creats rather large files (4Mb) and asI
> dont want these on my server for ever, I fork the script and have the
> child process sleep for 10mins before unlinking the files. This gives
> the user enough time to download the file and listen to it, after which
> it's trashed.
Maybe you could have a process runing all the time , occasionaly
checking
for old .au files and deleting them.
I think it would be easier and the memory overhead will be also
substantialy smaller.
(Maybe the CGIs should check for the presence of this daemon and
in case invoke it.)
Jenda
------------------------------
Date: Thu, 27 Mar 1997 17:51:50 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Functions and operators
Message-Id: <Pine.GSO.3.96.970327172556.15008D-100000@kelly.teleport.com>
On 27 Mar 1997, Tom Christiansen wrote:
> I believe the programming public is most comfortable calling all the
> prefix alphabetic ones "functions", and calling all the infix, postfix,
> circumfix, and nonalphabetic ones "operators". I follow that usage to
> avoid freaking them out.
That's a good reason. :-) I'll go along with that.
Nevertheless, some things just don't seem to be functions to me. I
remember learning somewhere that a function returns a value. That's not
necessarily relevant, but it affects me when I try to refer to some things
as "functions".
The first group are functions, I suppose, but you hardly ever see their
return values used (or even documented). Some of those are push, srand,
study, and binmode. But I can accept those as functions, and I might as
well include print as well, since I'm feeling generous. :-)
The next group includes last, next, redo, exec, die, dump, goto, exit, and
return. These could be called control structures, but I'm more likely to
call them operators.
Then there are substr, pos, and vec, which may well be functions. But when
they're used as lvalues I don't know what to call them, but it ain't
"functions"! :-)
Finally, there is scalar, which has the syntax of a function, but it's
certainly not a function. I call it an operator, but I don't know whether
that's right. No matter how you slice it, it's a special case.
Just my thoughts!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Tue, 25 Mar 1997 15:17:39 -0800
From: Jan Krynicky <Jan.Krynicky@st.ms.mff.cuni.cz>
To: Oscar Wahlberg <qraoswa@era-lvk.ericsson.se>
Subject: Re: Getting filedates in perl
Message-Id: <33385D13.7CBC@st.ms.mff.cuni.cz>
Oscar Wahlberg wrote:
>
> Hi all....
>
> I've got a slight problem, I have to get the modified
> time from a file at a regular basis...
>
> I need to do this because I want to run specific code
> if a file is older than ten minutes.
> It seems to work the first time, but not the second
> (I run it in a while loop)...
>
> This is what I've done...
>
> while (1) {
> if ((-M $filename) > 0.00694) #0.00694 = 10 mins approx ?
> { #1/(24*6)
> ## Exec some code...
> }
> sleep($sometime);
> }
>
> That's simplifying it a bit, but shows what I am trying to do,
> though it doesnt work at all.
> After the second turn around I end up with a negative value from
> the '-M $filename'.
Excerpt for the manpage
" -M Age of file in days when script started. "
so this is relative to the start time of the script not the time of this
call !
> I've tried doing a stat ($filename) and -M _, though no luck there
> either ?
>
The same problem.
You must use (.....,$mtime) = stat($file);
if (time-$mtime>10*$mins) { # $mins=60;
Ex.:
#####
$mins=60;
$i=12;
sub mtime {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($_[0]);
return $mtime;
}
while ($i--) {
if (time - (mtime "mantxt.pl") > 10*$mins) {
print "Older than 10 minutes.\n";
} else {
print "Pretty new.\n";
}
sleep 60;
}
#####
Jenda
------------------------------
Date: Wed, 26 Mar 1997 13:59:59 -0500
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: getting year from localtime
Message-Id: <fl_aggie-ya02408000R2603971359590001@news.fsu.edu>
In article <E7nwu1.BwI@nonexistent.com>, abigail@ny.fnx.com wrote:
+ $year = (localtime) [5] + 1900;
^^^^
Whoops, forgot about that. And before someone else asks, not, it's not
subject to the year 2000 problem.
+ Abigail -- Does everything need to be spelled out?
In triplicate. Top copy is yours.
James
--
Consulting Minster for Consultants, DNRC
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>
------------------------------
Date: Wed, 26 Mar 1997 18:43:40 -0800
From: Jan Krynicky <Jan.Krynicky@st.ms.mff.cuni.cz>
To: Jonathan Tracey <jont@uunet.pipex.com>
Subject: Re: Has anyone heard the rumour that Microsoft have bought Perl?
Message-Id: <3339DEDC.73ED@st.ms.mff.cuni.cz>
Jonathan Tracey wrote:
>
> I have it on good authority that Microsoft have aquired the rights to
> future versions of Perl. If so how long before we get Visual Perl?
> Any thoughts.
>
> Jon..................
Never. Bill loves Basic. Anything else is far over too hard for his
silly head.
If they bought Perl, they did it just to kill Perl.
Jenda
------------------------------
Date: 27 Mar 1997 11:19:59 -0800
From: Sriranga R. Veeraraghavan <sveerara@cisco.com>
Subject: Re: Newbie asks how do I format a numeric output?
Message-Id: <ls3ybb9xhuo.fsf@sveerara-ultra.cisco.com>
You want to use printf or sprintf, which are explained on pgs 169
and 187 of the Camel Book (1992 v1.2). The entry for sprintf (pg 187)
gives all the options. You can probably try this:
$i = 7.99*2;
printf "%d.2",$i;
HTH,
----ranga <sveerara@cisco.com>
------------------------------
Date: 28 Mar 1997 04:57:15 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Opening file for reading and writing simultaneously under perl?
Message-Id: <5hfj3b$ud@fridge-nf0.shore.net>
markus@gsmag.com wrote:
: AFAIK the open() function under perl only permits me to read XOR write
: to a file. My question is whether there is a possibility to open a
: file for readwrite simultaneously.
Ooo, sounds like a job for the FAQ! http://www.perl.com/FAQ
You're looking for something like +< -or even- +>> -or even- +>
When you read the FAQ, you'll learn the differences between each one.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: 27 Mar 1997 21:13:43 -0800
From: Russ Allbery <rra@stanford.edu>
To: markus@gsmag.com
Subject: Re: Opening file for reading and writing simultaneously under perl?
Message-Id: <qumwwqs38fs.fsf@cyclone.stanford.edu>
[ Posted and mailed. ]
markus <markus@gsmag.com> writes:
> AFAIK the open() function under perl only permits me to read XOR write
> to a file. My question is whether there is a possibility to open a file
> for readwrite simultaneously.
Nope, open() allows that too. See the documentation in man perlfunc. To
get you started, you want to open the file with something like:
open (FILE, "+< filename") or die "cannot open: $!";
--
Russ Allbery (rra@stanford.edu) <URL:http://www.eyrie.org/~eagle/>
------------------------------
Date: Tue, 25 Mar 1997 10:47:01 -0800
From: Jan Krynicky <Jan.Krynicky@st.ms.mff.cuni.cz>
To: lewis@nexusint.com
Subject: Re: PARADOX
Message-Id: <33381DA5.3D7E@st.ms.mff.cuni.cz>
Lewis Taylor wrote:
>
> I am currently writing a prog which will allow you to edit HTML files
> from a browser. The following is an except from the program to generate
> a TEXTBOX containing the file $file_to_edit
>
> print "<TEXTAREA NAME=\"text\" ROWS=15 COLS=50>\n\n\n";
>
> open(FILE,"$file_to_edit");
> while (<FILE>)
> {
> print;
> }
> close(FILE);
>
> print "\n\n\n</TEXTAREA>\n";
>
> This would work fine but for the fact that at the end of $file_to_edit
> there are two tags </BODY> and </HTML> These are parsed screwing up the
> generated page completly.
>
> So therefore my question to you would be how do I get the file
> displayed in the TEXTBOX in such a way that when I submit it is passed
> to the form variable "text"
>
> Thanks in advance,
>
> Lewis
Try this :
print "<TEXTAREA NAME=\"text\" ROWS=15 COLS=50>\n\n\n";
open(FILE,"$file_to_edit");
while (<FILE>)
{
s/</</g; # print all '<' as '<' = "escape" the '<'
print;
}
close(FILE);
print "\n\n\n</TEXTAREA>\n";
Jenda
------------------------------
Date: Fri, 28 Mar 97 10:02:49 GMT
From: mark@ispc001.demon.co.uk (Mark Katz)
Subject: Re: Parsing file problem
Message-Id: <859543369snz@ispc001.demon.co.uk>
In article <333AC77A.6C28@absyss.fr> seay@absyss.fr "Douglas Seay" writes:
>ab20@tntvax.ntrs.com wrote:
>> I have a file with the following record:
>>
>> |1997-02-13 00:00:00:000|N|NULL |NULL |XYZ |NULL|JKL |NULL |123
>>
>> My output should look like this:
>> |1997-02-13 00:00:00:000|N|||XYZ ||JKL ||123
>>
>> Basically I'm just stripping the word "NULL" and any trailing spaces before
>> the next delimiter "|". Is there a way using awk or perl to accomplish this?
>>
>perl: s/NULL[ ]+|/|/g
>sed: s/NULL[ ]+|/|/g
Nice solution which can be copied into awk with the sub function
{ sub ( "NULL[ ]+|", "|", $0)
print}
It may need the odd \ to 'protect the | ;-(
Much better that the one I was planning using FS, OFS...
By the way I'm not sure you want the 'g' at the end of the sed script
If you do, then use gsub instead of sub
>After learning Perl, I haven't found that much use for awk.
I dont wish to start a useless flame war - this is an awk newsgroup ;-)
Rgds
Mark
--
Mark Katz
ISPC, London - Innovation in data-delivery tools
Tel: (44) 181-455 4665, Fax (44) 181-458 9554
** Visit our website on http://www.efiche.com/efiche **
------------------------------
Date: Fri, 28 Mar 1997 06:14:42 GMT
From: pduff@airmail.net (Patrick Duff)
Subject: Perl mishandles some multidimensional array references???
Message-Id: <333b60e6.83659863@news.airmail.net>
I am really having trouble with multidimensional arrays and hashes. I
understand them, I use them a lot! It's just that in a few cases I've
found that Perl (Win NT Build 302, version 5.003) acts brain damaged.
Today I finally got annoyed enough to put together a few simple
examples showing Perl failing to correctly execute good Perl code.
Consider the following programs. The first one behaves correctly.
Each of the following variants should behave identically to the first
one, but instead they fail with various error messages, as indicated.
Only the last example is bad Perl code, which I threw in just to show
what happens when I follow the advice in the previous variant's error
message. I could give you more examples using curly braces in various
ways to try to get Perl to properly parse various references to
@Title, but none of the obvious ones work.
What I really want to use is something like the following fragment:
@Title[0] = ('A1','A2','A3','A4');
@Title[1] = ('B1','B2','B3','B4');
for $X (0 .. $#Title[0]) { ### };
So, unless someone can point out something I'm doing wrong -- please
Perl Gods, put this annoying quirk on your list of bugs to fix!
--
regards, Patrick Duff (pduff@airmail.net)
########################################
$Title[0][0] = 'A1';
$Title[0][1] = 'A2';
$Title[0][2] = 'A3';
$Title[0][3] = 'A4';
$Title[1][0] = 'B1';
$Title[1][1] = 'B2';
$Title[1][2] = 'B3';
$Title[1][3] = 'B4';
for $X (0 .. 3) {
for $Y (0 .. 1) {
print(" $Title[$Y][$X]");
} };
print("\n");
#Output is:
# A1 B1 A2 B2 A3 B3 A4 B4
########################################
@Title[0] = ('A1','A2','A3','A4'); #This line changed
@Title[1] = ('B1','B2','B3','B4'); #This line changed
for $X (0 .. 3) {
for $Y (0 .. 1) {
print(" $Title[$Y][$X]");
} };
print("\n");
#Error messages:
#Scalar value @Title[0] better written as $Title[0] at line 1.
#Scalar value @Title[1] better written as $Title[1] at line 2.
#No output.
########################################
$Title[0][0] = 'A1';
$Title[0][1] = 'A2';
$Title[0][2] = 'A3';
$Title[0][3] = 'A4';
$Title[1][0] = 'B1';
$Title[1][1] = 'B2';
$Title[1][2] = 'B3';
$Title[1][3] = 'B4';
for $X (0 .. $#Title[0]) { #This line changed
for $Y (0 .. 1) {
print(" $Title[$Y][$X]");
} };
print("\n");
#Error message:
#Can't use subscript on array length at line 10.
#No output.
########################################
$Title[0][0] = 'A1';
$Title[0][1] = 'A2';
$Title[0][2] = 'A3';
$Title[0][3] = 'A4';
$Title[1][0] = 'B1';
$Title[1][1] = 'B2';
$Title[1][2] = 'B3';
$Title[1][3] = 'B4';
for $X (0 .. $#{Title[0]}) { #This line changed
for $Y (0 .. 1) {
print(" $Title[$Y][$X]");
} };
print("\n");
#Error message:
#Can't use subscript on array length at line 10.
#No output.
########################################
$Title[0][0] = 'A1';
$Title[0][1] = 'A2';
$Title[0][2] = 'A3';
$Title[0][3] = 'A4';
$Title[1][0] = 'B1';
$Title[1][1] = 'B2';
$Title[1][2] = 'B3';
$Title[1][3] = 'B4';
for $X (0 .. @Title[0]) { #This line changed -- array evaled in a
scalar context
for $Y (0 .. 1) {
print(" $Title[$Y][$X]");
} };
print("\n");
#Error message:
#Scalar value @Title[0] better written as $Title[0] at line 1O.
#No output.
########################################
$Title[0][0] = 'A1';
$Title[0][1] = 'A2';
$Title[0][2] = 'A3';
$Title[0][3] = 'A4';
$Title[1][0] = 'B1';
$Title[1][1] = 'B2';
$Title[1][2] = 'B3';
$Title[1][3] = 'B4';
for $X (0 .. $Title[0]) { #This line changed
for $Y (0 .. 1) {
print(" $Title[$Y][$X]");
} };
print("\n");
#No error message, but script goes into an infinite loop.
#No output.
------------------------------
Date: Thu, 27 Mar 1997 14:05:24 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: Prince Mystery <mystery@itis.com>
Subject: Re: Please repost Answer: Re: Q: How to search _VERY_ long scalars for recurring patterns?
Message-Id: <333AEF24.741A@egames.com>
[mail & post]
Prince Mystery wrote:
> Hey, what was the answer to this guys' question??? I've got this exact
> same problem...
Go to <URL:http://www.dejanews.com/> and search for:
How to search VERY long scalars for recurring patterns
Use the net, Luke.
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
Date: 27 Mar 1997 18:45:21 -0800
From: mconst@soda.CSUA.Berkeley.EDU (Michael Constant)
Subject: Re: printing associative arrays in order
Message-Id: <5hfbc1$jsv@soda.CSUA.Berkeley.EDU>
Ishwarya Rao <irao1@gaia.umbc.edu> wrote:
>When an associative array is printed, the elements are printed in a
>random order. I was wondering if there is a one line command to print
>the elements of an associative array in the order in which it was
>created, rather than in a random order.
Almost -- it's two lines, not one, and you have to use the two lines
before you even create the hash:
use Tie::IxHash;
tie %hash, "Tie::IxHash";
Now you can modify the hash as you wish, and the elements will always
come out in order you put them in:
%hash = (foo => 1, bar => 2, baz => 3);
$hash{quux} = 4;
print %hash; # prints foo1bar2baz3quux4
You can download the Tie::IxHash module from CPAN (see the perlmod(1)
manpage for details about CPAN). For more information about the tie
command in general, see perltie(1).
--
Michael Constant (mconst@soda.csua.berkeley.edu)
------------------------------
Date: Thu, 27 Mar 1997 22:23:01 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Q: tr
Message-Id: <53hfh5.1dg.ln@localhost>
Henry Chan (hchan@didactic.portal.ca) wrote:
: Hi,
: I'm having problems with regular expressions with tr.
^^^^^^^^^^^^^^^^^^^
That is clear, as tr/// does not even _use_ regular expressions ;-)
from the perlop man page:
--------------------------------
=item tr/SEARCHLIST/REPLACEMENTLIST/cds
=item y/SEARCHLIST/REPLACEMENTLIST/cds
Translates all occurrences of the characters found in the search list
with the corresponding character in the replacement list. It returns
the number of characters replaced or deleted. If no string is
specified via the =~ or !~ operator, the $_ string is translated. (The
string specified with =~ must be a scalar variable, an array element,
or an assignment to one of those, i.e. an lvalue.) For B<sed> devotees,
C<y> is provided as a synonym for C<tr>. If the SEARCHLIST is
delimited by bracketing quotes, the REPLACEMENTLIST has its own pair of
quotes, which may or may not be bracketing quotes, e.g. C<tr[A-Z][a-z]>
or C<tr(+-*/)/ABCD/>.
Options:
c Complement the SEARCHLIST.
d Delete found but unreplaced characters.
s Squash duplicate replaced characters.
If the C</c> modifier is specified, the SEARCHLIST character set is
complemented. If the C</d> modifier is specified, any characters specified
by SEARCHLIST not found in REPLACEMENTLIST are deleted. (Note
that this is slightly more flexible than the behavior of some B<tr>
programs, which delete anything they find in the SEARCHLIST, period.)
If the C</s> modifier is specified, sequences of characters that were
translated to the same character are squashed down to a single instance of the
character.
If the C</d> modifier is used, the REPLACEMENTLIST is always interpreted
exactly as specified. Otherwise, if the REPLACEMENTLIST is shorter
than the SEARCHLIST, the final character is replicated till it is long
enough. If the REPLACEMENTLIST is null, the SEARCHLIST is replicated.
This latter is useful for counting characters in a class or for
squashing character sequences in a class.
Examples:
$ARGV[1] =~ tr/A-Z/a-z/; # canonicalize to lower case
$cnt = tr/*/*/; # count the stars in $_
$cnt = $sky =~ tr/*/*/; # count the stars in $sky
$cnt = tr/0-9//; # count the digits in $_
tr/a-zA-Z//s; # bookkeeper -> bokeper
($HOST = $host) =~ tr/a-z/A-Z/;
tr/a-zA-Z/ /cs; # change non-alphas to single space
tr [\200-\377]
[\000-\177]; # delete 8th bit
If multiple translations are given for a character, only the first one is used:
tr/AAA/XYZ/
will translate any A to X.
Note that because the translation table is built at compile time, neither
the SEARCHLIST nor the REPLACEMENTLIST are subjected to double quote
interpolation. That means that if you want to use variables, you must use
an eval():
eval "tr/$oldlist/$newlist/";
die $@ if $@;
eval "tr/$oldlist/$newlist/, 1" or die $@;
--------------------------------
See? Nowhere in the description of tr/// that is provided with the
perl distribution is there any mention or regular expressions.
: I'm trying to replace the first and last chars with a certain char.
^^^^^^^^^^^^^^
Oh. Then tr/// is definitely not what you want to use then, as
the it translates _all_ the characters in the string.
You want s/// instead.
: i.e.
: $old = "HELLO";
: ($new = $old) =~ tr/^.$./ML/;
: I want the result
: MELLT, but it doesn't seem to work.
^
where would this 'T' come from?
: What am I doing wrong?
-------------------
#! /usr/bin/perl -w
$_ = 'HELLO';
s/^./M/; # first char
s/.$/T/; # last char
print "$_\n";
-------------------
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Tue, 25 Mar 1997 22:24:42 -0800
From: Jan Krynicky <Jan.Krynicky@st.ms.mff.cuni.cz>
To: Sherman Hsieh <shsieh@haas.berkeley.edu>
Subject: Re: regular expression for check lower case
Message-Id: <3338C12A.196F@st.ms.mff.cuni.cz>
Sherman Hsieh wrote:
>
> I was wondering how to go about checking a variable for cases. For
> example, I want to do something if $variable is all lower case. I
> couldn't figure out what regular expression to use. Help.
>
> -Sherman
> --
/^[^A-Z]*$/ is true if there are no capitals in the string.
Jenda
------------------------------
Date: Thu, 27 Mar 1997 20:57:20 +0000
From: Eric Poindexter <eric@nettown.com>
To: Ken Zauter <zauter@usa.net>
Subject: Re: Server Error-what's up?
Message-Id: <333ADF30.6BAD8846@nettown.com>
Ken Zauter wrote:
>
> I downloaded a perl program called Guestbook authored by Matt Wright. I'm
> no newcomer to programming, just perl, so I know all about initializing
> variables, etc... What I am new to also is the whole HTML - perl
> connection. How does data get passed from an HTML file to a perl program?
>
> Anyway, my real question is why do I keep getting server errors even after
> making all the necessary changes to the perl program itself and its
> associated HTML files? My ISP's webmaster insists there's "something wrong
> with the program". Does this Matt Wright guy's stuff usually work?
>
> My problem child is at http://www.dreamscape.com/kennyz/guestbook.html.
> Any help will be greatly appreciated.
Make sure your printing a header before the HTML, i.e.
print "Content-type: text/html\n\n"; #yes, 2 \n
Also try running from the command line.
And from telnent, e.g.
%telnet nettown.com 80
GET http://nettown.com/perl/
--
Eric
<mailto:eric@nettown.com>
[http://nettown.com/perl/]
have a good day! (yes, Poindexter is Really my name :-)
------------------------------
Date: 28 Mar 1997 06:03:51 GMT
From: Anirvan Chatterjee <anirvan@crl.com>
Subject: Re: Small Database
Message-Id: <5hfn08$mjr@nexp.crl.com>
-----BEGIN PGP SIGNED MESSAGE-----
William W. Fowlkes <wfowlkes@sios.com> wrote:
: Greetings.
: I would like to maintain a text delimited file on the server (UNIX, Apache
: Server using Perl 5) through Perl. I would like to be able to add to this
: text file and search by keyword the records meeting this criteria.
Take a look at the Sprite module. I believe it should do most of what
you're looking for. Find out a bit more about it at
http://perl.com/cgi-bin/cpan_mod?module=Sprite&readme=1
and download it at
http://perl.com/cgi-bin/cpan_mod?module=Sprite
_______________________________________________________________
Anirvan Chatterjee . anirvan@crl.com . <URL:http://www.mx.org/>
PGP 0x93C5C165 . finger for PGP/geek . encrypted mail preferred
http://www.mx.org/bookfinder/ : online book comparison shopping
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBMztfQmTQ0LuTxcFlAQGC7gQArGIkgP+scQdcDfsMxLQRuCxWnUywG8Q+
bac9GSSle4a3hBC3ms2p2mEpSELE5C/Zwxy6AaoQ0w6rIPZXm90PPAvpSnZbKDeL
05yMUelHoeop0uhfKyeCP0IzalwtN3S/h+aeeZ0ccCJLN48U955kk6omIlqCJ73s
WAZSrPes7Xw=
=3+91
-----END PGP SIGNATURE-----
------------------------------
Date: 27 Mar 1997 16:44:49 -0800
From: blm@halcyon.com (Brian L. Matthews)
Subject: Re: TPJ: Nukes
Message-Id: <5hf4a1$3vc$1@halcyon.com>
In article <v67mitz0gh.fsf@colon.dev.ampersand.com>,
Mark Atwood <zot@ampersand.com> wrote:
|Please tell me this story was a joke...
|(In TPJ #5, "Perl and Nuclear Weapons Don't Mix", Ray F. Piodasoll
|relates that he had written real nuclear missile guidance software in
|Perl, that ultimately ended up burned into the ROMs of real nuclear
|missiles...)
I don't have any idea whether it's true or not, but don't know why
one would find it scary (at least not any more scary than the general
concept of software controlling missiles carrying nuclear weapons).
I'd say perl's at least as bug-free as any other interpreter or
compiler out there, and a good perl programmer should be able to
produce code as good or better than an equivalent programmer in
most other languages.
I just wonder how many times he used the Schwartzian Transform... :-)
Brian
--
Brian L. Matthews Illustration Works, Inc.
For top quality, stock commercial illustration, visit:
http://www.halcyon.com/artstock
------------------------------
Date: Fri, 28 Mar 1997 10:57:37 GMT
From: peosili@iol.it (Pompeo Silingardi)
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <333b0b81.4589909@news.alt.net>
On 27 Mar 1997 17:04:58 GMT, kaz@vision.crest.nt.com (Kaz Kylheku)
wrote:
>In article <01bc3a04$51baad40$87ee6fce@timpent.a-sis.com>,
>Tim Behrendsen <tim@a-sis.com> wrote:
>>Remember: The Sistine Chapel was a commissioned project. Should
>>Michelangelo have done inferior work because he was getting paid
>>for it?
>
>He most likely did do inferior work. But then again, he was a pretty unique
>individual who was most likely able to make recommendations and demands,
>the fullfillment of which enabled him to do better work. In the software
>business, you would have to be the equivalent of a Michelangelo to be
>able to do the same.
Oh no please , don' t write such a thing in order to back up your
argument ! La Cappella Sistina most likely was Michelangelo' s
greatest creative effort , regardless of the amount of money he
received for it. He worked for * years* on it....
Sorry for the off-topic but i thought it necessary underlining it.
Best Regards.
Pompeo Silingardi.
------------------------------
Date: 27 Mar 97 18:12:43 GMT
From: Christian.Ascheberg@welfen-netz.com (Christian Ascheberg)
Subject: where can I get oearl for OS/2
Message-Id: <333ab89b.0@194.25.97.1>
hi,
(I'm new here)
where can I get pearl for OS/2?
*----------------------------------------------*
|Christian Ascheberg from Wolfenbttel, Germany|
*-------------- I use OS/2 Warp4 --------------*
------------------------------
Date: Thu, 27 Mar 1997 22:24:13 -0600
From: Alan Bond <alanbond@sky.net>
Subject: Wrapping text in perl
Message-Id: <333B47ED.7312@sky.net>
Yes, I am a perl novice.
Word wrap in perl?
I have a string that represents the contents of a text field from
a form. The text field on the form has auto-wrapping. When my
perl program gets the string, it is one long string. Does anyone
know a snippet of code I could use to reformat the string and insert
newline characters at whitespace after, say 40 characters?
Thanks.
Alan Bond
------------------------------
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 195
*************************************