[6552] in Perl-Users-Digest
Perl-Users Digest, Issue: 177 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 25 14:17:23 1997
Date: Tue, 25 Mar 97 11:00:53 -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 Tue, 25 Mar 1997 Volume: 8 Number: 177
Today's topics:
Re: chunk POST and receive with LWP or other module (Simon Hyde (aka Jeckyll))
Re: Dereferencing single value using CGI gives list ins (Simon Hyde (aka Jeckyll))
Re: Directory Listing in Perl <seay@absyss.fr>
Re: Directory Listing in Perl (Nathan V. Patwardhan)
Re: Document Contains No Data <tchrist@mox.perl.com>
Documentation or example code for SNMP.pm wanted <qdtcall@k2.kiere.ericsson.se>
Re: File and Disk replication (Simon Hyde (aka Jeckyll))
Re: Forward- and Backslashes as Pathname Delimiters rtanikella@rfbd.org
Re: help needed connecting character strings (Simon Hyde (aka Jeckyll))
How do I ? .. rand/srand champs read this (Amandi R. Quvalis)
Re: How do I delete a line out of a text file <rob@netcentral.net.no.spam>
Re: Module or script of data checking routines? (Simon Hyde (aka Jeckyll))
Multithreading? <elliot@wellspring.com>
Perl and Sco Unix? (Icculus)
Re: Perl book sugestions wanted <seay@absyss.fr>
Re: Perl process doesn't go away <eryq@enteract.com>
Re: Perl to interact like "expect" script ? (Matthew H. Gerlach)
Perl: case of? <mgrady@nortel.ca>
printing associative arrays in order <irao1@gaia.umbc.edu>
Re: q: multikey lists, sort by key#1,key#2, save/load, (Simon Hyde (aka Jeckyll))
Regular Expresion question. <abennett@stonehill.edu>
Re: Regular Expresion question. <seay@absyss.fr>
Re: Regular Expresion question. <wkuhn@uconect.net>
Re: Regular Expresion question. <tchrist@mox.perl.com>
Re: Running a DOS-command under perl for OS/2 (Ilya Zakharevich)
Re: Running a DOS-command under perl for OS/2 rtanikella@rfbd.org
Re: sendmail and perl question <eryq@enteract.com>
Re: Serializing Stateless Requests for File Access <tchrist@mox.perl.com>
Re: Unix and ease of use (WAS: Who makes more ...) <dempseyh@pinn.net>
Re: Unix and ease of use (WAS: Who makes more ...) (Peter Seebach)
Re: What's a bad Perl book? <rra@stanford.edu>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 25 Mar 1997 18:27:34 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: chunk POST and receive with LWP or other module
Message-Id: <3338fcd4.611467@news.uni-stuttgart.de>
On 24 Mar 1997 21:34:14 GMT, dribbs@netspace.org (Keith Dreibelbis)
wrote:
>Hello,
>
>*snip*
>
>I am curious if the opposite is possible, i.e. if you can have a variable
>to POST that actually comes from a file. And then there is the problem of
>having a CGI to receive the file. I'm wondering if i'm going to have to
>do it myself, going into the low-level CGI stuff, since it doesn't seem
>that any modules do this. ("thou shalt not reinvent the wheel")
>
>*snip*
You might want to take a look at the RFC for uploading files (RFC1867
has information on the CGI side, and may also have the web browser
side in it too, I'm not sure).
---
Yours Sincerely,
,
() o /| | |
/\ _ _ _ __ _ _ |___| __| _
/ \| / |/ |/ | / \_/ |/ | | |\| | / | |/
/(__/|_/ | | |_/\__/ | |_/ | |/ \_/|/\_/|_/|__/
/|
\|
(Simon Hyde)
------------------------------
Date: Tue, 25 Mar 1997 18:27:35 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: Dereferencing single value using CGI gives list instead
Message-Id: <3339feb4.1091424@news.uni-stuttgart.de>
On Mon, 24 Mar 1997 20:20:28 GMT, brian@brie.com (Brian Lavender)
wrote:
>I have a problem with this perl script using CGI. I just want the
>value printed when I dereference $query for the parameter. Instead it
>is printing a list of all the parameters submitted to the query. Try
>the code with the following parameters. How can I make it so it just
>dereferences the value for the paramter fed through the @items
>array?
>
>Brian
>
>individual_day=3
>twodayearly=5
>
>#!/usr/bin/perl
>
>use CGI;
>$query = new CGI;
>@items = qw(individual_day twodayearly twodaypaytron tent dry_camp
>rv_limited rv_full);
>print $query->header;
>print $query->start_html("List dump Problem");
>foreach $item (@items) {
> next unless ( $query->param($item) > 0);
> print "The world is $query->param($item)\n";
You'll have to change this to:
print "The world is ", $query->param($item), "\n";
or
print "The world is ". $query->param($item). "\n";
---
Yours Sincerely,
,
() o /| | |
/\ _ _ _ __ _ _ |___| __| _
/ \| / |/ |/ | / \_/ |/ | | |\| | / | |/
/(__/|_/ | | |_/\__/ | |_/ | |/ \_/|/\_/|_/|__/
/|
\|
(Simon Hyde)
------------------------------
Date: Tue, 25 Mar 1997 17:21:55 +0000
From: Douglas Seay <seay@absyss.fr>
To: Paul Denman <pdenman@ims.ltd.uk>
Subject: Re: Directory Listing in Perl
Message-Id: <333809B3.10C7@absyss.fr>
Paul Denman wrote:
>
> Hello,
>
> I am trying to put together a quick n' dirty Perl listing which will ask
> for a directory
> and output the files in that directory.
>
> I have come up with:
>
> print "Enter the directory you want listing:";
> chop($newdir = <STDIN>);
> chdir($newdir) || die "Cannot chdir to $newdir";
> opendir(DOT,".") || die "Cannot opendir .";
> foreach (sort readdir(DOT)) {
> print "$_ \n";
> }
> closedir(DOT);
>
> I would like to also display the date each file was created - Is this so
> simple that I'm missing it?
> Kind regards,
>
> Paul Denman
[posted and mailed]
Paul,
You are missing two things. The simplier one is "stat",
it is found in the perlfunc man page.
The more complicated thing is that Unix doesn't keep
file creation times for files, so unless you are into
some kernel wizardry, you'll never get the time that
files were created. Unix utilities (like "ls") give
the last time the file was modified.
Also, for what you are doing, why not just try
print "Enter the directory you want listing:";
chop($newdir = <STDIN>);
system("ls -1 $newdir");
While it isn't as fast as your example (it has to launch
the ls program), it is simplier, and it should qualify
as "quick n' dirty".
Hope this helps.
- doug
------------------------------
Date: 25 Mar 1997 16:30:39 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Directory Listing in Perl
Message-Id: <5h8ujf$4u@fridge-nf0.shore.net>
Paul Denman (pdenman@ims.ltd.uk) wrote:
: I would like to also display the date each file was created - Is this so
: simple that I'm missing it?
: Kind regards,
Sounds like you're looking for stat() which should be documented in
perlfunc.pod. You should also be aware that there's not actually
a "created date" in stat() - there's a last_modified date, etc ---
you'll find these documented in perlfunc.pod, and in books like _Learning
Perl_ by Randal Schwartz, and _Programming Perl_, the definitive Perl
guide by Larry Wall, Tom Christiansen, and Randal Schwartz!
Good luck!
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: 25 Mar 1997 18:19:47 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Document Contains No Data
Message-Id: <5h9503$oof$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Tim Wilson <atms@zilker.net> writes:
:I'm trying to use a "mailform.cgi" script that I downloaded.
:However, I am something of a novice when it comes to CGI, and
:have run across a problem.
:
:When I hit the "Submit" button on the form, I get a "Document
:Contains No Data" message returned. Are there one or several
:simple explanations for this, or is it more likely that I have
:bungled one of a million different possible things in my HTML?
:
:If anyone has the time/patience to respond, I would appreciate it.
After reading several hundred of these, I did:
http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html
I'm afraid I was a bit testy at the time (you'd've been too if you'd read
as many as I had), but the check list and cures are still valid even if the
tone is a bit strong on the tough-love sarcasm.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
if (*name == '+' && len > 1 && name[len-1] != '|') { /* scary */
--Larry Wall, from doio.c in the v5.0 perl distribution
------------------------------
Date: 25 Mar 1997 16:31:54 +0000
From: EDT Calle Dybedahl <qdtcall@k2.kiere.ericsson.se>
Subject: Documentation or example code for SNMP.pm wanted
Message-Id: <iswwqworut.fsf@k2.kiere.ericsson.se>
Well, the subject line pretty much sums it up. I'm trying to use
ucd-snmp (a variant of the CMU snmp agent) and the SNMP module
(version 1.6, from CPAN) to fetch information from a bunch of
machines.
Ufortunately, the documentation for the SNMP module is somewhat
lacking, and the example code is not very illuminating either. It would
probably make more sense if I knew more about SNMP, but there never
seems to be enough time to learn :-(
At the moment I'm trying to get the data item ".1.3.6.1.4.1.2021.6.6.1"
(which is one of the extensions in the ucd snmp, it returns free disk
space). I can get it just fine using snmpget from a command line, but
I've failed utterly to get it from Perl.
Does anyone have any hints or pointers to good documens to read?
--
Calle Dybedahl, UNIX Sysadmin
qdtcall@kiemw.ericsson.se http://www.lysator.liu.se/~calle/
------------------------------
Date: Tue, 25 Mar 1997 18:27:36 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: File and Disk replication
Message-Id: <333aff4f.1247134@news.uni-stuttgart.de>
On Mon, 24 Mar 1997 13:42:50 -0500, "John R. Fairfield"
<fairfijr@dadeint.com> wrote:
>Does any have any experience doing file and disk replication in perl?
>Looking for examples! I have a remote (mirror) site which I only want
>do an update once a night because of network traffic during the day.
>I have a small program which will replace new files in a directory tree
>structure but doesn't delete missing files. Still learning!
>--
if both these mirrors are mounted on the same system then the
following should do:
use File::Find;
find (\&main, '/path/to/main/site');
sub main{
($file = $File::Find::name) =~ s/\Q/path/to/main/site\E//;
#Although size isn't the most reliable measure of whether a
#file has changed or not, in this case it will do
#Make sure this is never set to 0 so that if the file isn't
#there $MIRROR_FILES{$_} != $MAIN_FILES{$_} for 0 length
#files.
$MAIN_FILES{$file} = -s || 1;
}
find (\&mirror, '/path/to/mirror/site');
sub main{
($file = $File::Find::name) =~ s/\Q/path/to/mirror/site\E//;
$MIRROR_FILES{$file} = -s || 1;
}
foreach(keys(%MAIN_FILES)){
if ($MIRROR_FILES{$_} != $MAIN_FILES{$_}){
system('cp',"/path/to/main/$_", "/path/to/mirror/$_");
}
}
foreach(keys(%MIRROR_FILES)){
if (! $MAIN_FILES{$_}){
#Remove from mirror
unlink("/path/to/mirror/site/$_");
}
}
If they aren't both mounted on the same system then these methods
could still be used, you just wouldn't be able to use File::Find
---
Yours Sincerely,
,
() o /| | |
/\ _ _ _ __ _ _ |___| __| _
/ \| / |/ |/ | / \_/ |/ | | |\| | / | |/
/(__/|_/ | | |_/\__/ | |_/ | |/ \_/|/\_/|_/|__/
/|
\|
(Simon Hyde)
------------------------------
Date: Tue, 25 Mar 1997 10:41:20 -0600
From: rtanikella@rfbd.org
Subject: Re: Forward- and Backslashes as Pathname Delimiters
Message-Id: <859307219.1050@dejanews.com>
Hey All,
Thanks to everyone for the input. In the end, it was Donald's suggestion
that got it working. The solution was:
$pid = system(P_WAIT, 'sgmlbmd', 'arg1', arg2');
Single quotes were necessary.
Thanks again!
Reg
------------------------------------------------
Rajanikanth Tanikella Internet: rtanikella@rfbd.org
E-Text Programmer WWW: http://www.rfbd.org
Recording For the Blind and Dyslexic Phone: 609/520.8006
20 Roszel Rd Fax:609/520.7990
Princeton NJ 08540 </sig>
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Tue, 25 Mar 1997 18:27:32 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: help needed connecting character strings
Message-Id: <3337faf3.130401@news.uni-stuttgart.de>
On 24 Mar 1997 22:06:00 GMT, Kathy Scott <kscott@uab.edu> wrote:
>I have a string of characters assigned in the variable $helixname
>For example $helixname=helix25
>I have had no problem refering to a file as $helixname.dt so that the file
>that is being dealt with is helix25.dt
>However, when I tried this line
>rename("existingfile", $helixname.dt);
>The computer leaves out the period before the extension; so, the file's new
>name is helix25dt
>Can anyone explain this?
Yeah, since you didn't quote this as a string the . operator
concatenates 2 strings, and in this case it takes $helixname, and then
concatenates it to 'dt' to produce the same as $helixname . 'dt', to
do what you want to do you can try any of the following:
"$helixname.dt"
$helixname . '.dt'
$helixname . ".dt"
NB you can't do '$helixname.dt' since the ' quotes stop perl expanding
the data inside so if you were to say print '$helixname.dt'; that
would output:
$helixname.dt
---
Yours Sincerely,
,
() o /| | |
/\ _ _ _ __ _ _ |___| __| _
/ \| / |/ |/ | / \_/ |/ | | |\| | / | |/
/(__/|_/ | | |_/\__/ | |_/ | |/ \_/|/\_/|_/|__/
/|
\|
(Simon Hyde)
------------------------------
Date: 25 Mar 1997 16:46:50 GMT
From: amandi@cast.uark.edu (Amandi R. Quvalis)
Subject: How do I ? .. rand/srand champs read this
Message-Id: <5h8vhq$mts@picayune.uark.edu>
Keywords: srand, rand, blah blah
Hey ,
How do i output the contents of a m x n matrix in a random fashion ?
I tried using srand( time() ^ ($$ + ($$ < 15)) ^ unpack "%32L*", `ps -cef | gzip` ); [yah those are backquotes)
to seed it and generate m x n random #s using rand. Unfortunately, rand gives me repeats and I
am left with duplicates. All I want is to generate m x n unique numbers with no repetition
in a pretty random fashion.
Any ideas, all ye JAPHs out there ? Argh!@
Regards,
Amandi.
------------------------------
Date: Tue, 25 Mar 1997 09:32:39 -0600
From: Rob Huffstedtler <rob@netcentral.net.no.spam>
Subject: Re: How do I delete a line out of a text file
Message-Id: <3337F017.66318D1F@netcentral.net.no.spam>
That's the inefficient way to do it. If you are on a unix platform, you
can use perl to write an ed script and feed it to ed. Thus you can
either dearch for particular text ro go to a particular line, delete
that line then do a qw to quit and write it to disk.
If you aren't using a UNIX variant, I'm afraid it doesn't look good.
Both Mac and Win32 have a real dearth of powerful editors. On the other
hand, they have some that are a lot easier to use.
If anyone knows of a good editor for X, please let me know. I'd love to
see one that had all of the navigation features of joe, but was a little
quicker to use.
Mike Campbell wrote:
>
> "Matthew Enger" <menger@mindless.com> writes:
>
> > I am new to perl and I need to delete aline out of a textfile. I
> > have a aray called @lines which I was going to delete a part out of
> > that then output the aray to file. Does anyone have a methoud of
> > doing this? Or deleteing a line using another method?
>
> If you want to simply delete a line from a file without going through
> an array, you can use perl's -i switch. Note that this _does_ make a
> (temporary) copy of the file while it works.
>
> perl -i.bak -ne 'print unless (some condition which id's the line you
> want to remove);' filename
>
> Say you want to delete any line with the word "foo" in it:
>
> perl -i.bak -ne 'print unless /foo/;' file
>
> Or you want to delete line number 10:
>
> perl -i.bak -ne 'print unless ($. == 10);' file
>
> Hope this helps. (The -i.bak will create a .bak file before it works,
> so you have your original if something goes wrong. Simply using -i
> with no parameter will not create any backup file.)
------------------------------
Date: Tue, 25 Mar 1997 18:27:37 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: Module or script of data checking routines?
Message-Id: <333e0a38.4040310@news.uni-stuttgart.de>
On 23 Mar 1997 21:26:35 -0800, dhawk@shell3.ba.best.com (David
Hawkins) wrote:
>I'm handling incoming data and different lines have to be checked in
>different ways: some have to have a certain number of digits on the
>line, others can't have more than a certain number of letters, etc.
>
>I was wondering if there was a module or file of subroutines available
>that had routines where I could pass the data to &checkdigits with
>the range of allowable digits, and other routines with similiar
>functions? I looked through the modules on CPAN but didn't see
>what I was looking for.
>
I don't know about a function, but here's a regular expression that
will do it in one line:
die "Invalid Line" unless ($line =~ /^\d{min,max}\n?$/);
eg
die "Invalid Line" unless ($line =~ /^\d{4,5}\n?$/);
would fail any line that wasn't just a set of digits of length between
4 and 5.
---
Yours Sincerely,
,
() o /| | |
/\ _ _ _ __ _ _ |___| __| _
/ \| / |/ |/ | / \_/ |/ | | |\| | / | |/
/(__/|_/ | | |_/\__/ | |_/ | |/ \_/|/\_/|_/|__/
/|
\|
(Simon Hyde)
------------------------------
Date: Tue, 25 Mar 1997 12:15:09 -0500
From: Elliot Mednick <elliot@wellspring.com>
Subject: Multithreading?
Message-Id: <3338081D.7C8C@wellspring.com>
A couple of years ago, back when 5.001m/n was the stable version of
choice, I asked about a version of Perl that would support multiple
threads. Or multiple tasks. Or multiple processes. That is, I would
like to have several threads, each on their own stack, running
simultaneously -- at least conceptually. Global variables would be
shared among the threads/tasks/processes. Some sort of semaphore
mechanism would be needed to support critical sections.
I attempted to do this myself and ran out of time. Someone sent me a
patch to 5.001m and it was not bad, though I didn't prefer the spawn
mechanism.
I have not been reading the newsgroup for several months. I checked the
various Perl pages and I didn't see anything obvious.
So, is -- or will there be -- multithreading support in Perl?
Thank you in advance.
--Elliot
<elliot@wellspring.com>
------------------------------
Date: 25 Mar 1997 15:04:41 GMT
From: agcowan@euler.uncg.edu (Icculus)
Subject: Perl and Sco Unix?
Message-Id: <5h8pi9$jee$1@newton.uncg.edu>
Keywords: Sco Perl
Hey folks,
I am just wondering, will Perl compile nicely on a box
running Sco Unix?
Thanks,
Andy
------------------------------
Date: Tue, 25 Mar 1997 17:48:04 +0000
From: Douglas Seay <seay@absyss.fr>
To: Falcon <draggs@hawkeye.idx.com>
Subject: Re: Perl book sugestions wanted
Message-Id: <33380FD4.10A3@absyss.fr>
Falcon wrote:
>
> I need a good perl book. I learn best by examples. Also, I'm a
> professional programmer so I will use the book mostly as just a
> reference. Does anybody have any recomendations?
Programming Perl (e1) by Wall and Schwartz.
Programming Perl (e2) by Wall, Christiansen, and Schwartz.
Both versions have lots of examples. e1 is out-of-date,
but is easier to read (IMHO) and a chapter of little tricks.
e2 has all the latest OO features, but only longer examples.
e2 is the one to get unless you need the little tricks from
e1. I don't my copy with me or I would give you the ISBN.
It can be found at any decent book store or ordered directly
from O'Reilly & Assoc from http:/www.ora.com
------------------------------
Date: Tue, 25 Mar 1997 10:28:06 -0600
From: Eryq <eryq@enteract.com>
To: Larry Alexander <lalex@apnet.com>
Subject: Re: Perl process doesn't go away
Message-Id: <3337FD16.4DEF6CD1@enteract.com>
Larry Alexander wrote:
>
> I have been running a script (an HTML registration script where users type
> in their name, email address and interests) since December 1996 with no
> problem. For the past week, however, I have been noticing a process that
> is eating up CPU time. This script, called guestap.pl appears in the ps
> listing as "guestap." without the "pl" extension with many minutes of time
> against it. I have to manually go in and kill this process.
It could be a runaway child process (do you use fork? or system? or open("|")?).
It could also be your CGI program itself, caught in an infinite loop
(you can't trust the "ps" name: "ps" can be lied to on some systems
by setting argv[0]).
If a Perl CGI program (or any CGI program) gets caught in an infinite loop,
there is sometimes no way of knowing that the user talking to it hit the "stop"
button on their browser... generally, you find this out when you go to output
your HTML and you get a SIGPIPE because the socket is no longer connected to
anything. THIS VARIES INCREDIBLY based on:
(1) your OS,
(2) your HTTPD,
(3) how your HTTPD is set up to spawn/reap children,
(4) whether your script is NPH or not,
(5) probably other stuff.
If you don't use sleep() or SIGALRM in your script, a "safety valve" might be
to set up a SIGALRM handler that does this:
$SIG{'ALRM'} = sub {
syswrite(STDERR, "Alarm!\n", 7);
exit(-1);
};
and at the start of your Perl CGI set an alarm going with something like 5 minutes
on the clock, or whatever you need to be reasonably sure that a normal script completed.
This might help catch runaways... but the real solution, of course, is to find the
problem.
HTH,
--
___ _ _ _ _ ___ _ Eryq (eryq@enteract.com)
/ _ \| '_| | | |/ _ ' / Hughes STX, NASA/Goddard Space Flight Cntr.
| __/| | | |_| | |_| | http://www.enteract.com/~eryq
\___||_| \__, |\__, |___/\ Visit STREETWISE, Chicago's newspaper by/
|___/ |______/ of the homeless: http://www.streetwise.org
------------------------------
Date: Tue, 25 Mar 1997 15:47:50 GMT
From: gerlach@netcom.com (Matthew H. Gerlach)
Subject: Re: Perl to interact like "expect" script ?
Message-Id: <gerlachE7Lvvq.Gnu@netcom.com>
Yes, perl can interact like an "expect" script. If you are running
a common version of UNIX get Comm.pl.
Matthew
In article <5h6ulq$e57@inet-nntp-gw-1.us.oracle.com> <jtjioe@us.oracle.com> writes:
>All,
>Can Perl interact with program or shell just like "expect" ?
>I usually use expect script to do interaction with program say
>installation program, remote login etc.
>
>Is this possible with Perl also?
>
>Thanks in advance,
>--
>Joe Chitrady
>jtjioe@us.oracle.com
------------------------------
Date: Tue, 25 Mar 1997 12:21:05 -0500
From: Matthew Grady <mgrady@nortel.ca>
Subject: Perl: case of?
Message-Id: <33380981.7D85@nortel.ca>
Does anyone know if Perl has the equivalent of a "case of" control
structure? If so, is it the same as in C?
Thanks,
Matt Grady
------------------------------
Date: Tue, 25 Mar 1997 13:47:55 -0500
From: Ishwarya Rao <irao1@gaia.umbc.edu>
Subject: printing associative arrays in order
Message-Id: <33381DDB.41C6@gaia.umbc.edu>
Hello,
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.
Thanks,
Ishwarya Rao
------------------------------
Date: Tue, 25 Mar 1997 18:27:38 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: q: multikey lists, sort by key#1,key#2, save/load, etc?
Message-Id: <333f0b1e.4270593@news.uni-stuttgart.de>
On Mon, 24 Mar 97 03:44:44 GMT, appleo@cybercomm.net (Apple-O) wrote:
>in perl i need to sort a list with x number of columns by different keys
>(either key#1, key#2, key#3, etc)
>
>i would like to store the list as a tab-delimited text file.
>
>i was told perl 5 has provisions for multidimensional arrays, which i
>would use to handle the list.
>
>how do you implement multidim arrays and sort them by diff keys?
>
>* please try to keep any sample code to simple elemental commands
>and not the complicated does 1000 things in 1 line kind of stuff,
>it's much easier for me to understand perl scripts written in the
>style of c or pascal
Well, i'll try to explain how this works, if you don't follow try
taking a look at the sort section of man perlfunc. In perl a 2D array
is in fact an array of references (pointers in C terms) to arrays,
although most of the time it behaves like a 2D array would normally,
this program takes advantage of this, when creating and sorting it.
while (<DATA>){
next if /^\s*$/;
chomp $_;
#Add the array of split data as one element of @data_2d
push(@data_2d, [split(/\t/,$_)]);
}
#Sort will go through the array of references @data_2d, and compare
#each element to the other by passing them to the function which was
#it's first argument as $a and $b, we then take the arrays to which $a
#and $b point to fish out their first element and compare it to the
#other
# Therefore to sort alphabetically by the first column:
@sorted = sort {$a->[0] cmp $b->[0]} @data_2d;
# Print it out:
print "Sorted by name:\n---------------\n";
#Go throught the array of references returned by sort
foreach $line (@sorted){
#and then go through the array to which these point
#(see below for a quicker way)
foreach $column (@$line){
print "$column\t";
}
print "\n";
}
# To sort numerically by the second column:
@sorted = sort {$a->[1] <=> $b->[1]} @data_2d;
print "\nSorted by score:\n----------------\n";
foreach $line (@sorted){
#print a joined version of the array which is pointed to
print join("\t", @$line), "\n";
}
__END__
London 999
Leeds 34
Manchester 7
Mirfield 55
Dewsbury 9
Huddersfield 10
Birmingham 15
Bristol 60
Cardiff 4
---
Yours Sincerely,
,
() o /| | |
/\ _ _ _ __ _ _ |___| __| _
/ \| / |/ |/ | / \_/ |/ | | |\| | / | |/
/(__/|_/ | | |_/\__/ | |_/ | |/ \_/|/\_/|_/|__/
/|
\|
(Simon Hyde)
------------------------------
Date: Tue, 25 Mar 1997 11:16:09 +0000
From: Aaron Bennett <abennett@stonehill.edu>
Subject: Regular Expresion question.
Message-Id: <3337B3F7.32E2@stonehill.edu>
Hello everyone:
I'm a neophyte perl programmer trying to break the code on Regular
Expressions. I'm working on a mail from a form script (I know there's
about 1 million scripts like that out there I could copy, but then I'll
never learn anything :)
Part of what I want to do is parse the email address the user enters in
a form and make sure it has one and only one "@" symbol and at least one
".".
Here's a snippet: it doesn't compile correctly, and I know I just don't
understand what I'm supposed to do.
# is email address valid?
print "Content type: text/html", "\n\n";
if %mail_form{'email'} =~ /\@{1}.+/ {
print "<H1>Email is valid ", %mail_form{'email'}, "</H1>"; }
Am I on the right track? I've read the camel book's pages on regular
expresions and the regular expression section of the perl faq, but I
can't seem to get this right.
Thanks all, Aaron Bennett.
--
| Aaron Bennett
| Internet Services Coordinator
| Stonehill College Department of Academic Computing
| http://www.stonehill.edu
| "The most precious things remain unseen."
------------------------------
Date: Tue, 25 Mar 1997 18:20:13 +0000
From: Douglas Seay <seay@absyss.fr>
To: abennett@stonehill.edu
Subject: Re: Regular Expresion question.
Message-Id: <3338175D.31D7@absyss.fr>
Aaron Bennett wrote:
>
> Hello everyone:
>
> I'm a neophyte perl programmer trying to break the code on Regular
> Expressions. I'm working on a mail from a form script (I know there's
> about 1 million scripts like that out there I could copy, but then I'll
> never learn anything :)
>
> Part of what I want to do is parse the email address the user enters in
> a form and make sure it has one and only one "@" symbol and at least one
> ".".
>
> Here's a snippet: it doesn't compile correctly, and I know I just don't
> understand what I'm supposed to do.
>
> # is email address valid?
> print "Content type: text/html", "\n\n";
> if %mail_form{'email'} =~ /\@{1}.+/ {
> print "<H1>Email is valid ", %mail_form{'email'}, "</H1>"; }
>
> Am I on the right track? I've read the camel book's pages on regular
> expresions and the regular expression section of the perl faq, but I
> can't seem to get this right.
[posted and mailed]
you are not running with -w are you? "%mail_form{'email'}"
is a no-no as it doesn't do what you think it does. that
should be "$mail_form{'email'}".
what your /\@{1}.+/ RE is doing is searching for a @ followed by
at least one other character. the "@{1}" is redundant, as exactly
one match is the default. It also looks like you think the "." is
a normal character. It matches anything but end-of-line (\n).
To do what you asked (exactly one '@' and one or more '.'), you
should try something like
$mail_form{'email'} =~ m/@[^.@]+\.[^@]+$/
because that will match a '@', followed by a string of
non-@ and non-. characters, a dot and the anything but a
'@' until the end of the string. actually, this differs
from your requirement in that it looks for at least one
'.' after the @ (before doesn't count).
the bad news is that you _cannot_ define a valid email
address by any means other than trial and error. Send
it and wait for a failure (which may not come). You cannot
define rules that accept all bizarre options that exist
"out there". TomC has some guidelines on this thing at
http://www.perl.com but I don't remember the exact path,
so you'll have to look around a bit.
- doug
------------------------------
Date: Tue, 25 Mar 1997 11:45:52 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: abennett@stonehill.edu
Subject: Re: Regular Expresion question.
Message-Id: <33380140.6BD4B1E6@uconect.net>
Your compilation errors are not due to the regular expression.
Here is what needs to be done to get your program to compile:
1. Wrap the test expression associated with the if statement in ().
2. Change %mail_form to $mail_form.
Now, on to your regular expression. If you want to match only one @
symbol and at least one ".":
/\@{1}[^.]+\./
The above will match @ followed by one or more non-period characters
followed by one period. Since you are not concerned how many periods
are matched there is no need to go any further, right?
You may want to look at the other mail scripts to see what they use to
check for valid email address format.
-Bill
--
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com
------------------------------
Date: 25 Mar 1997 18:13:30 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Regular Expresion question.
Message-Id: <5h94ka$oof$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Bill Kuhn <wkuhn@uconect.net> writes:
:You may want to look at the other mail scripts to see what they use to
:check for valid email address format.
>From the FAQ:
How do I check a valid email address?
You can't.
Without sending mail to the address and seeing whether it
bounces (and even then you face the halting problem), you
cannot determine whether an email address is valid. Even if
you apply the email header standard, you can have problems,
because there are deliverable addresses that aren't RFC-822
(the mail header standard) compliant, and addresses that
aren't deliverable which are compliant.
Many are tempted to try to eliminate many
frequently-invalid email addresses with a simple regexp,
such as /^[\w.- ]+\@([\w.-]\.)+\w+$/. However, this
also throws out many valid ones, and says nothing about
potential deliverability, so is not suggested. Instead, see
http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/ckaddr.gz ,
which actually checks against the full RFC spec (except for nested
comments), looks for addresses you may not wish to accept email to
(say, Bill Clinton or your postmaster), and then makes sure that the
hostname given can be looked up in DNS. It's not fast, but it works.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Lisp has all the visual appeal of oatmeal with fingernail clippings mixed in."
--Larry Wall
------------------------------
Date: 25 Mar 1997 15:32:33 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Running a DOS-command under perl for OS/2
Message-Id: <5h8r6h$94j$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to
<volker.doerrsam@mach.uni-karlsruhe.de>],
who wrote in article <33324938.515C@mach.uni-karlsruhe.de>:
> Hello,
>
> is there a way to tell perl running under OS/2 to start a DOS-Box and/or
> a DOS-programm? I've already tried to run at least 'command.com' but it
> doesn't work. :-(
>
> any hint is appreciated
Hmm, I hopped that CRT would handle it gracefully... Anyway, one can
always do
system 'cmd', '/c/dos', 'program';
Ilya
------------------------------
Date: Tue, 25 Mar 1997 10:41:09 -0600
From: rtanikella@rfbd.org
Subject: Re: Running a DOS-command under perl for OS/2
Message-Id: <859304627.31967@dejanews.com>
In article <33324938.515C@mach.uni-karlsruhe.de>,
volker.doerrsam@mach.uni-karlsruhe.de wrote:
>
> Hello,
>
> is there a way to tell perl running under OS/2 to start a DOS-Box and/or
> a DOS-programm? I've already tried to run at least 'command.com' but it
> doesn't work. :-(
>
> any hint is appreciated
>
> ciao
> -Volker
Hi,
I've been playing with this for the past few days. Though my experience
is far from encyclopedic, here's what I have found:
To run a DOS program try:
$returnval =
system(P_WAIT, 'cmd', '/c', 'c:\some\dir\dosprog', 'arg1', 'arg2');
To spawn a simple DOS window:
$return = system(P_WAIT, 'cmd', '/c', d:\os2\mdos\command');
If you do not specify the path to the COMMAND.COM, it will fail.
I believe the P_WAIT is not necessary (it's the default.) The '/c' makes
the parent wait for the child to finish before continuing. (That's also
what the P_WAIT is for. This worked fine for me, but I wonder if they are
redundant, or if they both need to be there, or what? Time to experiment
=)
I have not checked to see if the DOS limitation of command-line length
interferes. (That's today's lesson.) For you that might mot be an issue.
Another suggestion is to place the call to the DOS program within a REXX
script and call the script in the same fashion:
system(P_WAIT, 'cmd', '/c', 'rexxscript.cmd', 'arg1', 'arg2');
This spawns a CMD shell and runs the REXX script. If you have arguments
to the REXX script, then you might need to have the REXX script pull them
in and pass them to the DOS program, something like this:
/* REXX scripts need to begin with a comment */
parse arg variable1 variable2
'c:\some\dir\dosprog' variable1 variable2
/* End of REXX */
That simple script would do the trick. Again, there is that command-line
length issue that might or might not interfere. But at least this gives
you a little something to work with.
Hope it has helped...
Reg
------------------------------------------------
Rajanikanth Tanikella Internet: rtanikella@rfbd.org
E-Text Programmer WWW: http://www.rfbd.org
Recording For the Blind and Dyslexic Phone: 609/520.8006
20 Roszel Rd Fax:609/520.7990
Princeton NJ 08540 </sig>
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Tue, 25 Mar 1997 10:07:51 -0600
From: Eryq <eryq@enteract.com>
To: Rich <scrich@cris.com>
Subject: Re: sendmail and perl question
Message-Id: <3337F857.39596027@enteract.com>
I suggest invoking sendmail as
"| /path/to/sendmail -t -oi -oem"
Fewer mishaps that way:
-t scan message header for recipients
-oi dot on its own lines doesn't end message
-oem error processing = mail error msg to sender
--
___ _ _ _ _ ___ _ Eryq (eryq@enteract.com)
/ _ \| '_| | | |/ _ ' / Hughes STX, NASA/Goddard Space Flight Cntr.
| __/| | | |_| | |_| | http://www.enteract.com/~eryq
\___||_| \__, |\__, |___/\ Visit STREETWISE, Chicago's newspaper by/
|___/ |______/ of the homeless: http://www.streetwise.org
------------------------------
Date: 25 Mar 1997 14:54:08 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Serializing Stateless Requests for File Access
Message-Id: <5h8oug$ghv$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Gabriele R Fariello - 608-576-8660 <gabriele@clotho.com> writes:
:Is there a way in Perl to open a file for writing if and only if it does
:not exist in one system call?
My guess is that you haven't read the http://www.perl.com/perl/faq/
that covers this.
Q: How do I create a file only if it doesn't exist?
A: You need to use the O_CREAT and O_EXCL flags from the Fcntl
module in conjunction with sysopen():
use Fcntl;
sysopen(FH, "/tmp/somefile", O_WRONLY|O_EXCL|O_CREAT, 0644)
or die "can't open /tmp/somefile: $!":
Be warned that neither creation nor deletion of files is
guaranteed to be an atomic operation over NFS. That is, two
processes might both successful create or unlink the same
file!
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
:The only reason [not to use] perl is that some sysadmins don't allow software that they didn't pay for.
By all means, let them send me money if it makes them feel better. :-)
--Larry Wall in <1993Dec13.213032.26623@netlabs.com>
------------------------------
Date: Tue, 25 Mar 1997 11:20:19 +0500
From: "Hugh A. L. Dempsey" <dempseyh@pinn.net>
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <33376EA3.3C06@pinn.net>
> Tim Behrendsen wrote:
> Do you think he is going to put something
> into Linux that he wouldn't put into his commercial baby?
>
> --
> ==========================================================================
> | Tim Behrendsen (tim@a-sis.com) | http://www.cerfnet.com/~timb |
> | "Judge all, and be prepared to be judged by all." |
> ==========================================================================
Why, yes, I do. In his commercial baby, he is directed by the
"pointy-haired
boss" and must do what the management team wants, rather than what he
thinks
is right. This frustration will be relieved by by putting "the right
code" into
linux.
Best,
Hugh
dempseyh@pinn.net
------------------------------
Date: 25 Mar 1997 10:52:39 -0600
From: seebs@solutions.solon.com (Peter Seebach)
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <5h8vsn$9uv@solutions.solon.com>
In article <01bc388f$41537ac0$87ee6fce@timpent.a-sis.com>,
Tim Behrendsen <tim@a-sis.com> wrote:
>Indeed, which is why it will never be dominant (note I did
>*NOT* say successful, which is a different thing). Microsoft
>et al have an incentive of fundamental survivability, and
>Linux does not. Commercial operating systems will always be
>a few steps ahead of free operating systems, simply because
>they have to be to survive, and that is a much more powerful
>incentive than some guy working part time on some part of
>the operating system, particularly when that same guy is
>probably working on a commercial O/S in order to put the kids
>through college.
Nonsense!
Commercial systems will often *lag* free OS's, precisely because they can't
afford to take risks.
Linux developers can release something they know to be buggy, and have
thousands of people help them work out the bugs.
NetBSD has a 64 bit file system. It has had one for a long time. How
long did it take Sun to get a real 64 bit file system? How about all of the
commercial Unix and NT systems which *didn't* have 64 bit file systems, and
some of which *still don't*.
Wanna bet on whether the first usable IPv6 implementation is in a commercial
or a free system?
When I'm at work, if I do an okay job, I get paid. If I try to do a perfect
or excellent job, I get criticied for taking too long, because time to market
is important.
When I'm playing around, and writing patches or enhancements for NetBSD, I
have the time and luxury to do whatever I want, which will always be better
than commercial success could support.
>Do you think he is going to put something
>into Linux that he wouldn't put into his commercial baby?
Yes. Love.
-s
--
Copyright 1997 Peter Seebach - seebs at solon.com - C/Unix Wizard
I am not actually gladys@nancynet.com but junk mail is accepted there.
The *other* C FAQ, the hacker FAQ, et al. http://www.solon.com/~seebs
Unsolicited email (junk mail and ads) is unwelcome, and will be billed for.
------------------------------
Date: 25 Mar 1997 09:42:47 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: What's a bad Perl book?
Message-Id: <qumend3q354.fsf@cyclone.stanford.edu>
Eric Bohlman <ebohlman@netcom.com> writes:
> (Seriously, has anyone done any research on whether Perl is easier to
> learn as a first or subsequent language, and if the latter, which first
> languages make it easier and which make it harder? I sometimes think my
> C background has sometimes gotten in the way of my learning certain
> aspects of Perl.)
My informal experience with various people around Stanford learning the
language is that it's much easier to learn as a subsequent language.
Sure, your C background may cause problems in a few places, but I don't
think you realize how much it helps as well. There's a *lot* that's the
same, right down to the semicolons at the end of each line (although C
programmers use far too many parens).
C experience seems to be the most useful, followed by regular expression
experience in *something*, be it vi, sed, egrep, or whatever. Shell and
awk experience are also useful.
--
Russ Allbery (rra@stanford.edu) <URL:http://www.eyrie.org/~eagle/>
------------------------------
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 177
*************************************