[18977] in Perl-Users-Digest
Perl-Users Digest, Issue: 1172 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 21 14:06:15 2001
Date: Thu, 21 Jun 2001 11:05:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993146715-v10-i1172@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 21 Jun 2001 Volume: 10 Number: 1172
Today's topics:
a smarter version of chomp <bernie@fantasyfarm.com>
Advice for Perl Class (Dave Hoover)
Re: CGI::CARP (carpout) or (fatalsToBrowser) ? <todd@designsouth.net>
don't know if this can be done.to do with splitting up <lying_happy_eyes@hotmail.com>
Re: don't know if this can be done.to do with splitting <pne-news-20010621@newton.digitalspace.net>
Re: don't know if this can be done.to do with splitting <rsherman@ce.gatech.edu>
Re: don't know if this can be done.to do with splitting (Anno Siegel)
Re: don't know if this can be done.to do with splitting <jurgenex@hotmail.com>
Re: don't know if this can be done.to do with splitting <Allan@due.net>
ENV{'REMOTE_USER'} problem <ub98aa@brocku.ca>
Re: ENV{'REMOTE_USER'} problem <pne-news-20010621@newton.digitalspace.net>
Re: ENV{'REMOTE_USER'} problem nobull@mail.com
Re: Executing UNIX shell commands in PERL (Rainer Moser)
Re: Executing UNIX shell commands in PERL <pne-news-20010621@newton.digitalspace.net>
explicit flush of filehandles (empty buffer) <pilsl_@goldfisch.at>
Re: explicit flush of filehandles (empty buffer) <pne-news-20010621@newton.digitalspace.net>
flatfiles vs. dbm vs.... <kisrael@andante.eecs.tufts.edu>
Re: Opening and Reading Named Pipes <narendra@spiff.hr.att.com>
Re: Opening and Reading Named Pipes <pne-news-20010621@newton.digitalspace.net>
Passing a DBM name to a program. <amittai@amittai.com>
Re: Pattern matching with variables (Rafael Garcia-Suarez)
Re: Pattern matching with variables (Jay Tilton)
Re: Pattern matching with variables (Anno Siegel)
Re: Pattern matching with variables <mjcarman@home.com>
Perl Test Problem - show-shebang <seppy@chartermi.net>
problem with reading from a pipe <nils@snailsen.de>
Re: Question <todd@designsouth.net>
Re: Reference-problem <mjcarman@home.com>
Re: Regexps, using variables to get $1, $2, etc. googlenews@edge-web.com
Re: Returning undef from embedded Perl (Anno Siegel)
Re: Small Database Becomes Large Database <mjcarman@home.com>
Re: Small Database Becomes Large Database <dempsey@dickinson.edu>
Re: Sorting array on multiple keys <ren@tivoli.com>
Uninitialzed values?vvp <vprasad@americasm01.nt.com>
Re: Uninitialzed values?vvp nobull@mail.com
Re: Why does this split not work? <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 21 Jun 2001 11:57:37 -0400
From: Bernard Cosell <bernie@fantasyfarm.com>
Subject: a smarter version of chomp
Message-Id: <2q54jt4s58ivd5o5hirvunenuqpbkku02i@4ax.com>
I'm pretty sure this has come up before, but I can't remember how the
discussion went. I'm working on an app that has to read both local
[=unix] files and stuff that comes in from the Internet. I'm finding
it a nuisance to get 'chomp' to do the right thing every time
[switching $/ back and forth and back and forth]. I can cobble up a
little thing that'd do the job:
sub smartchomp
{ $_[0] =~ s/\r?\n$// ; }
but that would probably be a bunch slower than the handcoded-C-version
[although I admit, actual performance isn't a issue, so this isn't
actually an operational problem]. It also doesn't implement quite all
of the semantics of chomp [not an issue for me in the
problem-at-hand].
Much as 'chomp' was a slightly-smartened version of 'chop', has anyone
considered putting together a yet-slightly-smarter version of chomp?
I know that this is a huge can of worms and lacks locality and
generality, but still, having xchomp implement the rule "if the last
thing in the string is \r, \n or \r\n, remove it and return it"
wouldn't be ALL that un-useful, would it? I'm hard pressed to think
of a case where it does something different from what 'chomp' does
where it wasn't chomp, rather than xchomp, that did the wrong thing...
/Bernie\
--
Bernie Cosell mailto:bernie@rev.net
Roanoke Electronic Village
------------------------------
Date: 21 Jun 2001 10:21:34 -0700
From: redsquirreldesign@yahoo.com (Dave Hoover)
Subject: Advice for Perl Class
Message-Id: <812589bb.0106210921.e27e8c2@posting.google.com>
I began learning Perl in November of 2000 and I feel like I've got a
good understanding of Perl fundamentals (I just finished reading
"Effective Perl Programming"...great book).
Anyway, at my job I have the opportunity to use some training money to
learn more about whatever I want. I want to learn more about Perl and
Networks and CGI. I live in the Chicago area and I need some
recommendations about where I could find some excellent classes
nearby.
TIA
=====
Dave Hoover
"Twice blessed is help unlooked for." --Tolkien
http://www.redsquirreldesign.com/dave
------------------------------
Date: Thu, 21 Jun 2001 17:17:09 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: CGI::CARP (carpout) or (fatalsToBrowser) ?
Message-Id: <p_pY6.241$F5.37933@news1.rdc1.tn.home.com>
> So.. qw()= quotes?
> >
> > Zur
No, qw() stands for "quote word" and is the same as putting quotes around
each word between the ()'s and makes it a list.
@a = 1..5;
#is the same as
@a = qw( 1 2 3 4 5 );
It separates each item by any kind of space, so you can use tabs or newlines
and beginning and trailing whitespaces for the best visibility.
------------------------------
Date: Thu, 21 Jun 2001 17:03:22 +0100
From: "lying_happy_eyes" <lying_happy_eyes@hotmail.com>
Subject: don't know if this can be done.to do with splitting up file names
Message-Id: <9gt5og$l39$1@plutonium.btinternet.com>
I've got a load of files named
my_file.txt
my_other_text_file.txt
another_small_file.txt
etc etc
And i wanted to know if i could show them in a perl script as
my file
my other text file
another small file
i'm SURE this can be done, but after spending about half an hour trying to
find a tutorial on it, i can't find any good ones :(
Can someone either tell me how to do it and put me outta my misery, or give
me a link to a GOOD UNDERSTANDABLE tutorial that doesn't assume you've got
five years of programming experience?
thanks!!
--
lying_happy_eyes
XXX
http://go.to/nypihas
http://balder.prohosting.com/thenyp/cgi-bin/ikonboard/ikonboard.cgi
------------------------------
Date: Thu, 21 Jun 2001 18:48:23 +0200
From: Philip Newton <pne-news-20010621@newton.digitalspace.net>
Subject: Re: don't know if this can be done.to do with splitting up file names
Message-Id: <m794jt02cp9psf5igui1e8udr5bgmkl5i6@4ax.com>
On Thu, 21 Jun 2001 17:03:22 +0100, "lying_happy_eyes"
<lying_happy_eyes@hotmail.com> wrote:
> I've got a load of files named
> my_file.txt
> my_other_text_file.txt
> another_small_file.txt
>
> etc etc
>
> And i wanted to know if i could show them in a perl script as
What do you mean with "show them in a perl script"?
> my file
> my other text file
> another small file
So, you want to replace underscores with spaces, and chop off '.txt' at
the end? Something like this, perhaps:
# read the file names into an array, say @files
for (@files) {
tr/_/ /;
s/\.txt$//;
}
# now @files will have the names in the format you showed.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 21 Jun 2001 12:55:16 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: don't know if this can be done.to do with splitting up file names
Message-Id: <3B31A864.5DD74909@ce.gatech.edu>
lying_happy_eyes wrote:
> I've got a load of files named
> my_file.txt
> my_other_text_file.txt
> another_small_file.txt
>
> etc etc
>
> And i wanted to know if i could show them in a perl script as
>
> my file
> my other text file
> another small file
>
> i'm SURE this can be done, but after spending about half an hour trying to
> find a tutorial on it, i can't find any good ones :(
>
> Can someone either tell me how to do it and put me outta my misery, or give
> me a link to a GOOD UNDERSTANDABLE tutorial that doesn't assume you've got
> five years of programming experience?
>
> thanks!!
>
> --
> lying_happy_eyes
> XXX
> http://go.to/nypihas
> http://balder.prohosting.com/thenyp/cgi-bin/ikonboard/ikonboard.cgi
s/\_/ /g; #substitute spaces for all underscores
s/\.\w{3}$//g; #delete file extensions
------------------------------
Date: 21 Jun 2001 17:00:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: don't know if this can be done.to do with splitting up file names
Message-Id: <9gt96s$rpd$2@mamenchi.zrz.TU-Berlin.DE>
According to lying_happy_eyes <lying_happy_eyes@hotmail.com>:
> I've got a load of files named
> my_file.txt
> my_other_text_file.txt
> another_small_file.txt
>
> etc etc
>
> And i wanted to know if i could show them in a perl script as
>
> my file
> my other text file
> another small file
for ( @filenames ) {
s/\.txt$//;
tr/_/ /;
}
> i'm SURE this can be done, but after spending about half an hour trying to
> find a tutorial on it, i can't find any good ones :(
Wow! Half an hour spent on a programming problem! Get used to it.
What tutorials have you looked at, and in what parts have you searched?
You didn't expect to find a tutorial on changing parts of filenames to
blanks, did you?
> Can someone either tell me how to do it and put me outta my misery, or give
> me a link to a GOOD UNDERSTANDABLE tutorial that doesn't assume you've got
> five years of programming experience?
Tutorials usually spell out the pre-requisites quite explicitly. One
that doesn't is probably not a good one, or not a tutorial at all.
Look there, and find one that fits your needs.
As for "UNDERSTANDABLE", if you're just beginning programming, it's not
going to be easy. Not even with the most excellent tutorial will it
be easy. Be prepared to invest a lot of hard work, including learning
to read non-tutorial documents. That isn't meant to stop you from
trying, but don't try lightly.
Anno
------------------------------
Date: Thu, 21 Jun 2001 10:32:03 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: don't know if this can be done.to do with splitting up file names
Message-Id: <3b322f94$1@news.microsoft.com>
"lying_happy_eyes" <lying_happy_eyes@hotmail.com> wrote in message
news:9gt5og$l39$1@plutonium.btinternet.com...
> I've got a load of files named
> my_file.txt
> my_other_text_file.txt
> another_small_file.txt
>
> etc etc
>
> And i wanted to know if i could show them in a perl script as
>
> my file
> my other text file
> another small file
Assuming the names are really as you said and the file name is stored in
$name:
$name =~ s/\.txt$//; # this removes the trailing ".txt" part
$name =~ s/_/ /g; # replaces the underscore with a space
Hope this helps.
BTW: The official way for removing the filename extension is to use
File::Basename, but in your case this would be overkill. However, if things
become more complex then you may want to use that instead of the quick hack
mentioned above.
jue
------------------------------
Date: Thu, 21 Jun 2001 13:52:08 -0400
From: "Allan M. Due" <Allan@due.net>
Subject: Re: don't know if this can be done.to do with splitting up file names
Message-Id: <9gtc4u$pes$1@nntp9.atl.mindspring.net>
"lying_happy_eyes" <lying_happy_eyes@hotmail.com> wrote in message
news:9gt5og$l39$1@plutonium.btinternet.com...
> I've got a load of files named
> my_file.txt
> my_other_text_file.txt
> another_small_file.txt
> etc etc
> And i wanted to know if i could show them in a perl script as
> my file
> my other text file
> another small file
> i'm SURE this can be done, but after spending about half an hour trying to
> find a tutorial on it, i can't find any good ones :(
I'll play:
s/(.+)\.\w{1,3}$/$_=$1,y!_! !,$_/e;
See perlop that came with your documentation.
> Can someone either tell me how to do it and put me outta my misery, or
> give me a link to a GOOD UNDERSTANDABLE tutorial that doesn't
> assume you've got five years of programming experience?
I still like:
http://www.oreilly.com/catalog/lperl3/
Which looks like is coming out in a 3rd edition (not new news I am sure but
I don't get out much anymore).
AmD
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
I dunno, I dream in Perl sometimes...
- Larry Wall in <8538@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Thu, 21 Jun 2001 12:44:30 -0400
From: Umair Tariq Bajwa <ub98aa@brocku.ca>
Subject: ENV{'REMOTE_USER'} problem
Message-Id: <3B32246D.1AD587CD@brocku.ca>
--------------B0C0D6918618FCBE986D645A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I am designing and developing database. I have login page for the users
to provide valid database login and pasword for authentication purposes.
I would like to access ENV{'REMOTE_USER'} on each page to make sure
whether user is a valid database user or not. I am trying to access
ENV{'REMOTE_USER'} on each script but it returns null. Does anyone have
any idea how can i do that? Any help will be greatly appreciated.
Thanks in advance.
Umair
--
Favorite Quotes:
===============
"The box said 'Windows 95 or better', so I installed Linux"
-- Unknown
"A computer without Windows is like a chocolate cake without mustard."
-- Unknown
--------------B0C0D6918618FCBE986D645A
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I am designing and developing database. I have login page for the users
to provide valid database login and pasword for authentication purposes.
I would like to access ENV{'REMOTE_USER'} on each page to make sure whether
user is a valid database user or not. I am trying to access ENV{'REMOTE_USER'}
on each script but it returns null. Does anyone have any idea how can i
do that? Any help will be greatly appreciated.
<p>Thanks in advance.
<p>Umair
<pre>--
Favorite Quotes:
===============
"The box said 'Windows 95 or better', so I installed Linux"
-- Unknown
"A computer without Windows is like a chocolate cake without mustard."
-- Unknown</pre>
</html>
--------------B0C0D6918618FCBE986D645A--
------------------------------
Date: Thu, 21 Jun 2001 18:51:52 +0200
From: Philip Newton <pne-news-20010621@newton.digitalspace.net>
Subject: Re: ENV{'REMOTE_USER'} problem
Message-Id: <tf94jto7t5n331jtqnv5j0qg8o1c7g4joc@4ax.com>
On Thu, 21 Jun 2001 12:44:30 -0400, Umair Tariq Bajwa <ub98aa@brocku.ca>
wrote:
> I am designing and developing database. I have login page for the users
> to provide valid database login and pasword for authentication purposes.
> I would like to access ENV{'REMOTE_USER'} on each page to make sure
> whether user is a valid database user or not. I am trying to access
> ENV{'REMOTE_USER'} on each script but it returns null. Does anyone have
> any idea how can i do that? Any help will be greatly appreciated.
news:comp.infosystems.www.authoring.cgi is ---------> that way.
Followups set.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 21 Jun 2001 17:56:52 +0100
From: nobull@mail.com
Subject: Re: ENV{'REMOTE_USER'} problem
Message-Id: <u9lmml7ovf.fsf@wcl-l.bham.ac.uk>
Umair Tariq Bajwa <ub98aa@brocku.ca> writes:
> I am designing and developing database. I have login page for the users
> to provide valid database login and pasword for authentication purposes.
> I would like to access ENV{'REMOTE_USER'} on each page to make sure
> whether user is a valid database user or not. I am trying to access
> ENV{'REMOTE_USER'} on each script but it returns null. Does anyone have
> any idea how can i do that? Any help will be greatly appreciated.
$ENV{REMOTE_USER} contains the username as identified by the standard
authenitcation mechansims implemented by the web server.
This has nothing to do with Perl.
If you are rolling your own authenitcation mechansims you need some
sort of session concept.
This has nothing to do with Perl.
One mechanism you can use is a cookie that contains a session ID.
This has nothing to do with Perl.
You probably want to avoid the cookie from being a password equivlent
(i.e. you don't want someone getting hold of the cookie to be able to
use it to log in again later).
This has nothing to do with Perl.
Some web sites abuse cookies and so some people disable cookies so
cookies may not work. If cookies _do_ work then they are the right
solution.
This has nothing to do with Perl.
Another option is put the session token in a hidden field or in the
URL.
By the way, did I mention this has nothing to do with Perl.
> --------------B0C0D6918618FCBE986D645A
> Content-Type: text/html; charset=us-ascii
> Content-Transfer-Encoding: 7bit
>
> <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
This is a plain text newsroup - please no not post HTML.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 21 Jun 2001 15:21:50 GMT
From: moser@ivk.uni-stuttgart.de (Rainer Moser)
Subject: Re: Executing UNIX shell commands in PERL
Message-Id: <3b32105a.28901688@news.uni-stuttgart.de>
On Thu, 21 Jun 2001 16:20:37 +0200, Philip Newton
<pne-news-20010621@newton.digitalspace.net> wrote:
>On Thu, 21 Jun 2001 13:40:55 GMT, steven.smolinski@sympatico.ca (Steven
>Smolinski) wrote:
>
>> That string will be passed to your shell, probably "/bin/sh -c". That
>> shell, depending upon what it is, doesn't appear to support 'source'.
>> Some shells use unary prefix dot (i.e., ". sysalias.def; my_alias"), but
>> you should really check your system manual for /bin/sh.
>
>IIRC, 'source' is csh. So the OP should probably invoke csh directly.
>(How to pass the script to csh as an argument I don't know, but the OP
>should be able to glean the information from the man pages for csh.)
>
>Cheers,
>Philip
>--
>Philip Newton <nospam.newton@gmx.li>
>Yes, that really is my address; no need to remove anything to reply.
>If you're not part of the solution, you're part of the precipitate.
We are using the tcsh, which in the command line can execute the
source command, but not via a system command from PERL. That's what I
don't understand!
Rainer
------------------------------
Date: Thu, 21 Jun 2001 17:27:43 +0200
From: Philip Newton <pne-news-20010621@newton.digitalspace.net>
Subject: Re: Executing UNIX shell commands in PERL
Message-Id: <ce44jtguttiennjf1q98n2nas7nqnt9259@4ax.com>
On Thu, 21 Jun 2001 15:21:50 GMT, moser@ivk.uni-stuttgart.de (Rainer
Moser) wrote:
> We are using the tcsh, which in the command line can execute the
> source command, but not via a system command from PERL. That's what I
> don't understand!
From `perldoc -f system`:
: If there is only
: one scalar argument, the argument is checked for shell
: metacharacters, and if there are any, the entire argument is
: passed to the system's command shell for parsing (this is
: `/bin/sh -c' on Unix platforms, but varies on other platforms).
system() doesn't care about your login shell, but generally calls
/bin/sh (a Bourne shell, usually) if it calls a shell at all. So tcsh's
abilities are irrelevant in this case since your system() doesn't call
it.
If you want system() to use tcsh, you'll have to call it directly.
Perhaps something like
system "tcsh -c 'source sysalias.def; my_alias'"
will work, but I don't know the syntax for tcsh calls.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 21 Jun 2001 17:29:23 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: explicit flush of filehandles (empty buffer)
Message-Id: <3b3212d5$1@e-post.inode.at>
I use buffered writing to certain files (and I want to use buffered
writings), but at some point I want to flush the whole buffer without
actually closing the Filehandle.
How can I do this ?
Would it be useful to redirect the STDOUT to my filehandle, disable
buffering ($|=1) and write out a single line and restoring STDOUT ?
(as far I know, only STDOUT can be set unbuffered)
thnx,
peter
background:
I want to keep the filehandle open to save time when I need the filehandle
again. Closing and Opening should actually take more time than just
flushing it. But I want all the buffer written to the logs when certain
steps are donw, so I can view the logfile.
a system-sync-call will - as I expected - not do it.
--
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Thu, 21 Jun 2001 17:36:52 +0200
From: Philip Newton <pne-news-20010621@newton.digitalspace.net>
Subject: Re: explicit flush of filehandles (empty buffer)
Message-Id: <3t44jt48d72n12hkkatv6dtohl6tgfta6c@4ax.com>
On Thu, 21 Jun 2001 17:29:23 +0200, peter pilsl <pilsl_@goldfisch.at>
wrote:
> How can I do this ?
Set $| to 1
> (as far I know, only STDOUT can be set unbuffered)
Not true. From `perldoc perlvar`:
: autoflush HANDLE EXPR
: $OUTPUT_AUTOFLUSH
: $| If set to nonzero, forces a flush right away and after every
: write or print on the currently selected output channel.
So you have to select your filehandle and then set $|, or (if you're
using a file handle object) call the autoflush method on it.
If using the select method, you'll probably want to select the old file
handle afterwards, since select also determines, among other things,
where print's output goes to.
Example:
{ my $oldfh = select FH; $| = 1; select $oldfh; }
or
select ( (select(FH), $| = 1)[0] );
Note that you shouldn't need to write a line to flush the buffer -- just
setting $| to 1 should flush immediately, according to the docs. To be
on the safe side, I suppose you could print "" (that is, print the empty
string) to the file handle. Then, if you want, you can set $| to 0
again.
> a system-sync-call will - as I expected - not do it.
Because the data is in Perl's buffers, not the OS's.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 21 Jun 2001 15:07:35 GMT
From: Kirk Is <kisrael@andante.eecs.tufts.edu>
Subject: flatfiles vs. dbm vs....
Message-Id: <X4oY6.307$l2.18040@news.tufts.edu>
Recently I discovered the wonder of Perl's builtin mapping of hashes to
DBM files. (In fact I used it to make something like the PalmOS's thinkDB
for the web, http://alienbill.com/abp/online/ )
Anyway, before I found out about dbm (it's amazing what you can miss when
you learn your Perl on the street, so to speak) I was a big proponent of
flatfiles.
What are the relative merits of the two, dbm vs. flatfiles?
And is their another option as lightweight and portable as these two?
How does it compare to DBI::CSV, and does that support SQL, or what?
Anyways, my first stab at answering these questions:
Flatfiles:
PRO: more tools to edit raw database, i.e. any text editor,
so you don't have to build a miniprogram for every operation
PRO: super-duper portable
CON: slow?
CON: have to write code for every operation, deletes are a bit awkward
DBM
PRO: fairly portable (what about NT systems?)
PRO: easy operatoins via hash
CON: *must* have strong unique key system
CON: for storing multiple data values per key, have to do
hackey system (for instance on k/db I had each bit of data
on a seperate line in the string)
--
Kirk Israel - kisrael@cs.tufts.edu - http://www.alienbill.com
DEALING WITH MORTALITY: A Skeptic's Guide - http://kisrael.com/mortal/
------------------------------
Date: Thu, 21 Jun 2001 11:03:30 -0400
From: Narendra Ravi <narendra@spiff.hr.att.com>
To: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: Opening and Reading Named Pipes
Message-Id: <3B320CC2.CBB7D284@spiff.hr.att.com>
Philip Newton wrote:
>
> [Posted and emailed]
>
> On Thu, 21 Jun 2001 10:33:48 -0400, Narendra Ravi
> <narendra@spiff.hr.att.com> wrote:
>
> > I am having a problem opening the named pipe. The following
> > snippet of Perl show my attempts:
>
> And the error messages you are getting are...?
>
> Cheers,
> Philip
No error message. The program just hangs at
sysopen (FIFO, $pipename, O_RDONLY) ...
OR
$pfh = new IO::File, "$pipename", O_RDONLY;
OR
$pfh = new IO::File, "$pipename", "r";
Looks like the call blocks.
Thank you,
--
-- Narendra Ra[a]vi Email : narendra@spiff.hr.att.com
MT A4-4B27 Phone : 732-420-7792
------------------------------
Date: Thu, 21 Jun 2001 17:31:58 +0200
From: Philip Newton <pne-news-20010621@newton.digitalspace.net>
Subject: Re: Opening and Reading Named Pipes
Message-Id: <hp44jtc0jtufdg0gbjs5cslr04hks6hd4g@4ax.com>
On Thu, 21 Jun 2001 11:03:30 -0400, Narendra Ravi
<narendra@spiff.hr.att.com> wrote:
> The program just hangs at
>
> sysopen (FIFO, $pipename, O_RDONLY) ...
It's probably waiting for someone to write the pipe. Is there a process
writing to it before you try to read it?
> Looks like the call blocks.
That's probably what's happening.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 21 Jun 2001 19:21:55 +0200
From: "Amittai Aviram" <amittai@amittai.com>
Subject: Passing a DBM name to a program.
Message-Id: <9gtalp$929$1@rznews2.rrze.uni-erlangen.de>
I would like to write a simple diagnostic tool that opens any DBM and reads
out the respective keys and values. But how to pass the name of the DBM as
a variable? I have tried the code below and get the error message that
there is "no such file." Of course, a DBM name is _not_ the name of the
file. Ideally, BTW, I would like to pass the name as part of the command
invoking the program, rather than in response to a question, but, if I try
to use $ARGV, I get exactly the same error message. The code below will
work, of course, if, instead of having it ask me for STDIN input, I just
hard code the DBM name as the value of the variable $datafile -- but that's
what I would like to avoid.
Thanks! --
Amittai
#!/usr/local/bin/perl
print "Enter the DBM name you wish to open:";
$datafile = <STDIN>;
dbmopen(%DATA, $datafile, 0666) || die "Cannot open $datafile: $!";
%data = %DATA;
dbmclose(%DATA) || die "Cannot close $datafile: $!";
print "DATA RETRIEVED:\n\n";
foreach $key (keys %data) { print "The value of $key is $data{$key}.\n" };
--
Amittai Aviram
Please note new address! -- amittai@amittai.com
------------------------------
Date: 21 Jun 2001 15:08:43 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Pattern matching with variables
Message-Id: <slrn9j43he.apb.rgarciasuarez@rafael.kazibao.net>
Loki wrote in comp.lang.perl.misc:
}
} If i have the line read: if (m/\.EXE/) {...... etc then the script
} works.
} However if the line reads: if (m/$pattern/) {...... with $pattern =
} "\.EXE" predeclared then it finds files like userexe.cfg as it is
} treating the . as a wildcard and ignoring the preceeding \.
In Perl, "\." is the same as ".". Hence your $pattern string does not
contain any backslash. You should use '\.' or "\\." instead.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Thu, 21 Jun 2001 15:15:25 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Pattern matching with variables
Message-Id: <3b320bb2.74929427@news.erols.com>
On 21 Jun 2001 07:49:04 -0700, si.cox@bbsrc.ac.uk (Loki) wrote:
>For this example i will say we are searching for .EXE files.
>
>If i have the line read: if (m/\.EXE/) {...... etc then the script
>works.
>However if the line reads: if (m/$pattern/) {...... with $pattern =
>"\.EXE" predeclared then it [produces unwanted positive matches]
>I know when perl does a pattern match it translates variables before
>doing the match but surely this means it should work declaring
>$pattern = "\.EXE".
Within double quotes, the \ is already an escape, and an escaped period is
still a period. If you assign...
$pattern = "\.EXE";
then $pattern is '.EXE'.
Use single quotes to prevent \ from becoming an escape until it gets to the
regex, i.e.
$pattern = '\.EXE';
Even better, use qr//.
$pattern = qr/\.EXE/;
if (m/$pattern/) {
#do something
}
------------------------------
Date: 21 Jun 2001 15:17:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Pattern matching with variables
Message-Id: <9gt36c$irb$1@mamenchi.zrz.TU-Berlin.DE>
According to Rafael Garcia-Suarez <rgarciasuarez@free.fr>:
> Loki wrote in comp.lang.perl.misc:
> }
> } If i have the line read: if (m/\.EXE/) {...... etc then the script
> } works.
> } However if the line reads: if (m/$pattern/) {...... with $pattern =
> } "\.EXE" predeclared then it finds files like userexe.cfg as it is
> } treating the . as a wildcard and ignoring the preceeding \.
>
> In Perl, "\." is the same as ".". Hence your $pattern string does not
> contain any backslash. You should use '\.' or "\\." instead.
...also consider the quotemeta() function (q.v.) and its derivative
\Q.
Anno
------------------------------
Date: Thu, 21 Jun 2001 10:11:38 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Pattern matching with variables
Message-Id: <3B320EAA.6F89292B@home.com>
Loki wrote:
>
> Have a script to scan a database of filenames. This allows the
> entry of a pattern to match against.
> For this example i will say we are searching for .EXE files.
>
> [I]f the line reads: if (m/$pattern/) {...... with $pattern =
> "\.EXE" predeclared then it finds files like userexe.cfg
Define $pattern as a regex using regex quoting:
$pattern = qr/\.EXE/;
-mjc
------------------------------
Date: Thu, 21 Jun 2001 11:30:35 -0400
From: Brian Seppanen <seppy@chartermi.net>
Subject: Perl Test Problem - show-shebang
Message-Id: <3B32131B.7477662F@chartermi.net>
I've had an ongoing issue with a solaris 7 host that won't run a simple
perl script that will work on other solaris 7 boxes without modification
and without problem.
Basically it appears as if the box does not interpret the file as a perl
script and gives me shell
errors when I try to execute it. Doing a file on the script gives me
the following
/export/home/root/scripts/mail.access: executable /usr/local/bin/perl
script
-rwxr-xr-x 1 root other 651 Jun 21 08:16
/export/home/root/scripts/mail.access
When I try to execute the program it gives the following errors:
/export/home/root/scripts/mail.access: =
#######################
##
## to rebuld the database sendmail uses in conjunction with this file
issue the command below
##
## makemap -v dbm /etc/mail/access < /etc/mail/access
##
#######################
: No such file or directory
/export/home/root/scripts/mail.access: line 13: syntax error near
unexpected token `(F,">/etc/mail/access")'
/export/home/root/scripts/mail.access: line 13: `open
(F,">/etc/mail/access")||die "cant open /etc/mail/access!!!\n";'
Basically it appears that these are shell errors, but why am I getting
shell errors is the problem?
The script is partially as follows
#!/usr/local/bin/perl
$header="
#######################
##
## to rebuld the database sendmail uses in conjunction with this file
issue the$
##
## makemap -v dbm /etc/mail/access < /etc/mail/access
##
#######################
";
open (F,">/etc/mail/access")||die "cant open /etc/mail/access!!!\n";
print F $header;
My thoughts were that for some reason perl wasn't interpreting the
shebang properly (#!) because the path is proper to perl, however, the
shell is executing it for some reason (I'm using bash on solaris 7). To
further complicate matters if I specify the entire perl path and program
the script runs fine.
such that /usr/local/bin/perl /export/home/root/scripts/mail.access runs
just fine.
However, when I try to recompile perl I get the following error during
the test phase and I was wondering if this may be part of my problem.
op/magic............ok 22/35Dying on warning: Can't exec
"./show-shebang": No such file or directory at op/magic.t line
168.
op/magic............FAILED test
23
Has anyone ever experienced this problem??? The perl version is
perl5.6.1.
I'd appreciate any insights. I've been battling this for days and I've
already taken it to the comp.unix.shell, solaris, and misc newsgroups.
I'm hoping someone here may have some insight.
Thanks,
Brian Seppanen
seppy@chartermi.net
------------------------------
Date: Thu, 21 Jun 2001 18:38:27 +0200
From: Nils =?iso-8859-1?Q?Sch=E4le?= <nils@snailsen.de>
Subject: problem with reading from a pipe
Message-Id: <3B322303.93F848C6@snailsen.de>
hi,
i am writing on a script to start another programm and formart its
output.
see the sourec down under. my problem is, that with some programs it
hangs and waiting for
some output of the program while the progrtamm has allready finished and
does not exit any more (in most cases when the program starts ab
backgroundjob). to solve this problem i have written the signalhandler
which closes my open connection to the child process if its terminate.
this works fine in the case, that the scripts hang and waiting for more
input but it brings up new problems. if the programm produce a lot of
output for example show an logfile or thomething, the child process
terminate and the signalhandler kill the pipe even if ther are mor data
to read and i got not the full output of the programm.
has anybody an idea whow to read from a pipe without this two problems?
thanx nils
require './term2html.pm';
use FileHandle;
autoflush STDOUT 1;
$DONE=0;
sub catch_cld {
$DONE++;
close SCRIPT;
}
$SIG{CLD} = 'catch_cld'; # could fail in modules
open SCRIPT,'something_to_exec |' or warn "cant't open";
while ( ($line=<SCRIPT>)) {
print convert($line)."\n";
}
close SCRIPT or 1;
------------------------------
Date: Thu, 21 Jun 2001 17:12:16 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: Question
Message-Id: <QVpY6.237$F5.34221@news1.rdc1.tn.home.com>
"Hans Baartmans" <hans@ti.com> wrote in message
news:9gqr5s$1kp$1@tilde.csc.ti.com...
> I am reading in a file of user names and putting these files into an
array.
> Then I would like to use an 'if' statement within a 'foreach' loop to
check
> to see if these home directories contain a particular file. Can I use the
> '-e' option to see if the file exists?
>
> I am not a good perl programmer, but this is what I did in part of my
> script.
>
> foreach $user (@user) {
> print "\n";
> print "Checking home directory: $user\n";
> if (-e "/home/$user/$rhosts") {
> print "/home/$user/$rhosts exists. \n";
> print OUT "ls -al /home/$user/$rhosts";
> }
> }
>
if the filehandle OUT is open for writing, then that part is ok. And I don't
know if you actually wanted to print "ls -al ..." or if you wanted to print
the results of the unix command "ls -al ...". Right now you are printing the
command. If you want to print the results of running the command, use
backticks.
print OUT `ls -al /home/$user/$rhosts`;
------------------------------
Date: Thu, 21 Jun 2001 09:38:52 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Reference-problem
Message-Id: <3B3206FC.343EFF88@home.com>
Stefan Serena wrote:
>
[Attribution restored]
> Anno Siegel wrote:
>
> > foreach ( $apple, $orange, $lemon, $banana ) {
> > # do something with $_ here.
> > }
> >
> > Note that foreach makes $_ an alias to each variable in turn, so
> > everything you do to $_ really happens to $apple, $orange, etc.
>
> Didn't know that. I thought it makes a copy to $_
> That means, the following code changes every entry of the array?
>
> foreach $entry (@allentries) {
> $entry = $entry x 2; # can be anything...
> }
Correct.
-mjc
------------------------------
Date: Thu, 21 Jun 2001 16:33:06 -0000
From: googlenews@edge-web.com
Subject: Re: Regexps, using variables to get $1, $2, etc.
Message-Id: <tj48e2a1cive55@corp.supernews.com>
Michael Carman <mjcarman@home.com> tapped:
> If the point is that the search/replace patterns are variables instead
> of hard-coded, then you need to evaluate the RHS:
RHS?
> It's still not clear to me just what you're trying to accomplish. Do you
> want to modify $string? Or just extract values from it? Why do you want
> the match/replace patterns stored in variables? If you can give us a
> better explanation of what you have, what you want to end up with, and
> why you think you need to do it the way you're trying to, we can provide
> better advice.
This has to do with renaming files. If the filenames match the pattern
specified in $match, then they're changed to a different name using the
value of replace which may or may not contain strings stored from the
regexp used with $match. ($match and $replace are entered into a config
file and read by the script).
The manpages weren't really clear to me in regards to dealing with this
specific issue. I think I really need to upgrade to the 3rd ed. of the
Camel book too. I have a long way to go yet before I reach complete
enlightenment. This has been a good learning experience.
------------------------------
Date: 21 Jun 2001 17:56:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Returning undef from embedded Perl
Message-Id: <9gtcg3$8c$1@mamenchi.zrz.TU-Berlin.DE>
According to Dave Weaver <davew@wsieurope.com>:
> I have an application with an embedded Perl interpreter, and I'm
> using perl_call_pv() from my program to call Perl subroutines.
>
> I'd like my Perl subroutines to be able to return undef to
> indicate an error, but despite reading though perlembed and
> perlcall I can't see how to do this.
[snip rest]
perlguts describes how to create an undefined scalar value, as well
as how to recognize one. It is actually the ultimate resource in
XS (and, presumably, perl-embedding) programming. Well, penultimate
before you resort to the source.
Anno
------------------------------
Date: Thu, 21 Jun 2001 09:59:40 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Small Database Becomes Large Database
Message-Id: <3B320BDC.F75E65D9@home.com>
Paul Dempsey wrote:
>
> I have a simple Unix DBM file [...] I needed to change the keys
> for this file, so I read the file in and wrote to a different
> DBM file with the new key.
>
> The problem is my new data file has grown from 250 KB to to 25 MB in
> size.
[snip of code sample]
> Any thoughts? Or is there a better way to change record keys in
> a DBM file?
No idea on the blowup in file size, but I don't mess with DBM much.
You should be able change keys in place by copying the old entry to a
new one and then delete()ing the original:
my @oldkeys = keys %hash;
foreach my $old (@oldkeys) {
my $new = $hash{$old}[10]; # Or whatever $new should be for you
$hash{$new} = $hash{$old};
delete $hash{$old};
}
A couple of things to note:
1) You want to make a copy of your keys and loop over that, not
over "keys %hash" directly. Adding/deleting keys while iterating
over them is not recommended...
2) If any of your new keys have the same name as an old key, you
could lose data (depending on the order they get processed in).
-mjc
------------------------------
Date: Thu, 21 Jun 2001 17:32:24 GMT
From: Paul Dempsey <dempsey@dickinson.edu>
Subject: Re: Small Database Becomes Large Database
Message-Id: <3B322FBB.5F597A68@dickinson.edu>
Michael Carman wrote:
> Paul Dempsey wrote:
> > I have a simple Unix DBM file [...] I needed to change the keys
> > for this file, so I read the file in and wrote to a different
> > DBM file with the new key.
> > The problem is my new data file has grown from 250 KB to to 25 MB in
> > size.
>
> [snip of code sample]
> You should be able change keys in place by copying the old entry to a
> new one and then delete()ing the original:
>
> my @oldkeys = keys %hash;
> foreach my $old (@oldkeys) {
> my $new = $hash{$old}[10]; # Or whatever $new should be for you
> $hash{$new} = $hash{$old};
> delete $hash{$old};
> }
Thanks. I actually tried that myself but it still created a huge file.
I finally tried deleting a few records with the longest values (500 or
more characters) and then everything worked fine. But I don't understand
why the original DBM file could handle these records, but when I copied
the records (even into the same file), it became 10 times as large.
Oh, well. Thanks for your help.
-Paul
------------------------------
Date: 21 Jun 2001 11:05:30 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Sorting array on multiple keys
Message-Id: <m33d8tddit.fsf@dhcp9-173.support.tivoli.com>
On Wed, 20 Jun 2001, ps@siteindia.com wrote:
> Hi Experts,
>
> I want to sort my array on multiple keys, right now it is sorted on
> one key date and it has another field description
>
> i want to sort first on date and then under date on description.
> Any help or pointer is greatly appreciated.
>
> my(@itemList) = sort {
> return 0 if !defined($$a{date}) and !defined($$b{date});
> return -1 if !defined($$a{date});
> return 1 if !defined($$b{date});
> $$a{date} <=> $$b{date}
> } ( @Fees);
Starting from your existing comparison, you could use:
(Note: I prefer $a->{date} over $$a{date}.)
my(@itemList) = sort {
return $a->{desc} cmp $b->{desc}
if !defined $a->{date} and !defined $b->{date};
return -1 if !defined $a->{date};
return 1 if !defined $b->{date};
$a->{date} <=> $b->{date} or $a->{desc} cmp $b->{desc}
} @Fees;
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 21 Jun 2001 13:07:03 -0400
From: "Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com>
Subject: Uninitialzed values?vvp
Message-Id: <3B3229B7.74B825F5@americasm01.nt.com>
Hello - I have a block of code that is giving me this error:
Thu Jun 21 12:48:05 2001] miscv.cgi: Use of uninitialized value at
miscv.cgi line 108. [Thu Jun 21 12:48:05 2001] miscv.cgi: Use of
uninitialized value at miscv.cgi line 108.
=
[...connects to database successfully...]
my @cat;
my $rowhash;
my $hashref;
my ($field,$data,%rowhash);
($field,$data) = each %rowhash;
while (my $row = $sth->fetchrow_hashref)
{
push @cat, \%rowhash;
LINE 108: print $cgi->p("$field = $data");
}
Is my $field,$data = each %rowhash in the wrong place?
Help?
V
------------------------------
Date: 21 Jun 2001 18:37:21 +0100
From: nobull@mail.com
Subject: Re: Uninitialzed values?vvp
Message-Id: <u98zil7mzy.fsf@wcl-l.bham.ac.uk>
"Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com> writes:
> Subject: Uninitialzed values?vvp
Not exactly helpful. And what does '?vvp' mean?
> Hello - I have a block of code that is giving me this error:
>
> Thu Jun 21 12:48:05 2001] miscv.cgi: Use of uninitialized value at
> miscv.cgi line 108. [Thu Jun 21 12:48:05 2001] miscv.cgi: Use of
> uninitialized value at miscv.cgi line 108.
>
> =
>
>
> [...connects to database successfully...]
> my @cat;
> my $rowhash;
> my $hashref;
> my ($field,$data,%rowhash);
> ($field,$data) = each %rowhash;
>
> while (my $row = $sth->fetchrow_hashref)
> {
>
> push @cat, \%rowhash;
> LINE 108: print $cgi->p("$field = $data");
> }
>
> Is my $field,$data = each %rowhash in the wrong place?
Eh?
Nothing in you code ever puts anything into %rowhash (or $hashref or
$rowhash for that matter) so it doesn't matter where you put the
statement that's trying to read stuff out of %rowhash it'll always be
return undef.
use PSI::ESP;
You meant something like:
my @cat;
while (my $row = $sth->fetchrow_hashref)
{
push @cat, { %$row };
while ( my ($field,$data) = each %$row)
{
print $cgi->p("$field = $data");
}
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 21 Jun 2001 16:42:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why does this split not work?
Message-Id: <5t84jt87pa9qf2kvgufgu8ujl0bqt4jh4m@4ax.com>
tuxy wrote:
>I'm trying to split a pretty large buffer (>1000 lines) into sections
>The file is a series of name-values like
>
> NAME Jane Doe
> AGE 21
> ADDRESS Anytown USA
> !
> NAME John Smith
> .
> .
>
>
>
>so I'm using something like
>
> my @people=split /^\s*NAME\s+/m,$buf;
>
>and I'm getting very odd results. It consistently fails with this
>message:
>
> Use of uninitialized value in split at datax.pm line 447, <IN> line
>21 (#1)
>
>which I cannot comprehend.
Nevermind the <IN> line 21, that is from a file from which you read 21
lines, and you never closed it. Is this indeed line 447 in file
data.pm?
It doesn't fail for me, not even on perl 5.6.0. But I do get an empty
item at the start, and of course, you stripped the srtring "NAME " from
it as well. If you want to keep those, try:
my @people=split /(?<=.)^\s*(?=NAME\s+)/sm,$buf;
which ignores the "NAME" on the very first line, and keep the lines like
"NAME Jane Doe" intact.
--
Bart.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 1172
***************************************