[10670] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4262 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 20 02:07:26 1998

Date: Thu, 19 Nov 98 23:00:20 -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           Thu, 19 Nov 1998     Volume: 8 Number: 4262

Today's topics:
    Re: Bareword? bigcheese@my-dejanews.com
    Re: Bareword? (Ilya Zakharevich)
    Re: Base64 encoding problem... (The Corruptor)
    Re: delete/modify DBM <crmcgee2@email.msn.com>
        detecting hard drives (Jye Tucker)
        File descriptor/flock problem phukit@enteract.com
    Re: File I/O & text processing <rlogsdon@io.com>
    Re: How do i trim a string in Perl?? (Ronald J Kimball)
    Re: how to get `date` in perl for win32 (newbie) <rlogsdon@io.com>
    Re: I download ActiveState but don't understand how to  (Larry Rosler)
    Re: Is it possible to run a web server on Win95? (Dana Booth)
    Re: Multipliers x{m,n} (David Combs)
    Re: Multipliers x{m,n} (Larry Rosler)
    Re: Need equivalent to a sh's export command. (Thomas Jordan)
        opening an already opened file <nospam.perl_rocks@hotmail.com>
    Re: opening an already opened file (Martien Verbruggen)
        PERL for windows 95/NT <sreenivas@sns.com.sg>
        Please help on getting username <rwilliamson@uno.gers.com>
        Posting FROM Perl <ariste@gol.com>
        Pretty printing from newer CPerl mode (Ilya Zakharevich)
    Re: programing fun: trees: FlattenAt <xah@best.com>
    Re: reverse comma operator in the camel (Peter J. Kernan)
    Re: Server Administration with Perl <admin@sidhe.net>
    Re: Single word ouptu from aa array <pmoore@interaccess.com>
    Re: sort related ... (Matthew Bafford)
    Re: sort related ... (Tad McClellan)
    Re: Two-Part RE question (Ronald J Kimball)
    Re: Two-Part RE question (Ronald J Kimball)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 20 Nov 1998 04:33:21 GMT
From: bigcheese@my-dejanews.com
Subject: Re: Bareword?
Message-Id: <732reg$o0f$1@nnrp1.dejanews.com>

Well.. I fixed up some of the errors.. but
it gives me

"
Bareword found where operator expected at line 42, near "$base ='<IMG
SRC=kana/k1"
syntax error at line 42, near "$base = '<IMG SRC=kana/k1"
Bareword found where operator expected at line 43, near "$bwth = ' WIDTH"
Bareword found where operator expected at line 43, near "15 HEIGHT"
Bad name after n:: at line 43.
"

Can you help me?
(here's most of the code. between 17 and 31 is just comments)

17 @kana = $ENV{'QUERY_STRING'} =~ /([^Aaeiou +9]*[Aaeiou +9])/g;
31 for ($i = 1; $i < length($ENV{'QUERY_STRING'}); $i++) {;
32 $fi = $kana[$i];
33	if (length($fi)==8 && $fi=~/%28[KkHh][12345]%29) {
34		chop($kana[$i]);
35		chop($kana[$i]);
36		chop($kana[$i]);
37		$hd = chop($kana[$i]);
38		$fr = chop($kana[$i]);
39		if ($fr eq 'K') {
40			if ($hd == 1) {
41				$base = '<IMG SRC=kana/k1/';
42				$bwth = ' WIDTH=15 HEIGHT=15>\n';
43				$bqth = ' WIDTH=3 HEIGHT=15>\n';
44				$bpth = ' WIDTH=4 HEIGHT=15>\n';
45				$bsml = ' WIDTH=15 HEIGHT=12>\n';
46			}

Thanks for all your help!
-Dan

In article <F2oDqr.Es5@world.std.com>,
  aml@world.std.com (Andrew M. Langmead) wrote:
> bigcheese@my-dejanews.com writes:
>
> >What is a Bareword?
>
> >"Bareword found where operator expected at line 39"
>
> A bareword in perl is a sequence of alphanumeric characters that it
> can't figure out any other meaning for. It treats them like they are
> quoted strings.
>
> $foo Set_to 'bar';
>
> Set_to is a bareword.
>
> If you made it an explicit string:
>
> $foo 'Set_to' 'bar';
>
> You would get a slightly different error message:
>
> String found where operator expected at ...
>
> So the error isn't really that you have a bareword, its just that perl
> is trying to tell you that what it found when it was expecting an
> operator.
>
> As others have said, the code you posted looks syntatically
> correct. (Although a bit odd with the double quoted numeric value.)
> but as you work with computer languages, you'll begin to learn a
> valuable lesson. Compilers and interpreters get confused when parsing
> incorrect source code. They try to tell you as much as they can, but
> you really have to take their error messages with a grain of salt.
> They're already heading off into the weeds. Try examining the code
> starting a few lines before line 39. There is probably something that
> started perl in the wrong direction, but it wwasn't until line 39 that
> it noticed it.
>
> It kind of line my favorite analogy to explain fatal errors in
> programs ("General Protection Error", "Core Dump", "System Error",
> etc. Whatever term you are familiar with.) When someone who has no
> background in computer programming asks me why a program has given
> some sort of fatal error, I explain that the program is pretty much
> just following its instructions, just like someone following a
> path. It doesn't necessarily keep checking that the path is clear. The
> event that caused the error is like someone (maybe even the program
> itself) leaving a rake right in the middle of the path, with its
> spokes upturned. Essentially, the program stepped on the rake, the
> handle flung up, knocked him on the head, and knocked him out. Its
> easy to tell when the rake flew up and hit him. (This bit of slapstick
> imagery tends to make a connection to what had happened.) Its harder
> to find out when the rake got left on the path.
>
> Perl is telling you it got hit on the head with a rake. The perl
> parser does a fair job of checking that the path is clear before it
> walks, so usually it can tell you when the rake got put onto the
> path. Sometimes its a little bit off, though.
> --
> Andrew Langmead
>


--
 Dan  /| ________________
O|===|* >________________>
      \| http://members.xoom.com/big_cheese

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


------------------------------

Date: 20 Nov 1998 04:44:55 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Bareword?
Message-Id: <732s47$1jq$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to 
<bigcheese@my-dejanews.com>],
who wrote in article <732reg$o0f$1@nnrp1.dejanews.com>:

> Bareword found where operator expected at line 42, near "$base ='<IMGSRC=kana/k1"
> 
> 17 @kana = $ENV{'QUERY_STRING'} =~ /([^Aaeiou +9]*[Aaeiou +9])/g;
> 31 for ($i = 1; $i < length($ENV{'QUERY_STRING'}); $i++) {;
> 32 $fi = $kana[$i];
> 33	if (length($fi)==8 && $fi=~/%28[KkHh][12345]%29) {
> 34		chop($kana[$i]);
> 35		chop($kana[$i]);
> 36		chop($kana[$i]);
> 37		$hd = chop($kana[$i]);
> 38		$fr = chop($kana[$i]);
> 39		if ($fr eq 'K') {
> 40			if ($hd == 1) {
> 41				$base = '<IMG SRC=kana/k1/';
> 42				$bwth = ' WIDTH=15 HEIGHT=15>\n';

If you would use a smart editor, you would momentarily see that the /
on line 41 end a REx which starts on line 33.

Hope this help,
Ilya


------------------------------

Date: Thu, 19 Nov 1998 15:59:45 GMT
From: corruptor@terry.org.uk (The Corruptor)
Subject: Re: Base64 encoding problem...
Message-Id: <3654400d.17272516@news.ukonline.co.uk>

On Wed, 18 Nov 1998 20:46:56 GMT, Tom Phoenix <rootbeer@teleport.com>
wrote:

>binmode? Hope this helps!


Bingo! Problem solved...

Thanks...


-- 

_THE_____                                      ____
______   \________________________  ___________\___\______________________
  \   \____/  __  \_____  \  __   \/  /\  \ _____  \ ______/  __  \_____  \
   \    __/__/  \__\  \ \__\ \ \__/__/  \__\\   /  / \    /__/  \__\  \ \__\
\   \__/ /  \____/  \  \  \   \  /  \____/  \\_/  /   \__/  \____/  \  \
 \_______\__________/___\  \___\ \__________/  __/ \_____\__________/___\
----====-=**********=====---====--=********\___\=---======**********===----
                                            -===-
             "EGO iS NotHinG wIthOuT ArrOgAncE tO BaCk iT uP..."


------------------------------

Date: Thu, 19 Nov 1998 23:31:10 -0800
From: "crmcgee2" <crmcgee2@email.msn.com>
Subject: Re: delete/modify DBM
Message-Id: <uwnpKbEF#GA.251@upnetnews05>

Hi,

Tom Phoenix wrote in message ...
>On Thu, 19 Nov 1998, Chris Clark wrote:
>
>> # deleteItem
>>
>> sub deleteItem {
>>
>>  $database = "mydbm.dbm";


Do not specify an extension dbmopen creates/uses two extension .dir & .pag

>>  dbmopen (%contents, $database, 0700);
>
>Like open(), it's good to check the return value from dbmopen() for
>errors. (And do you really want 0700 there? I wouldn't....)
>

>>  $FORM{'newsitem'};
>
>What does this statement do for you? What do you think it does? Have you
>turned on warnings in your program?
>
>Hope this helps!
>
>--
>Tom Phoenix       Perl Training and Hacking       Esperanto
>Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/
>




------------------------------

Date: Fri, 20 Nov 1998 13:59:21 +1000
From: jye@buckconsultants.com.au (Jye Tucker)
Subject: detecting hard drives
Message-Id: <jye-ya02408000R2011981359210001@qld.nnrp.telstra.net>

Hi there,

I'm trying to write a perl script to be put onto a FreeBSD boot floppy and
used in a number of different machines with no guarantees of consistant
hardware. 

What I am trying to do is to ask the script to detect what hard drives are
connected to the machine so that I can use the mount system command to
mount them. 

Has anyone heard of any modules or techniques for detecting hardware or am
I just going to have to grep through the output of dmesg?

Thanks for any help,

Jye


------------------------------

Date: 20 Nov 1998 06:00:59 GMT
From: phukit@enteract.com
Subject: File descriptor/flock problem
Message-Id: <7330ir$jeu$1@eve.enteract.com>

Hi all, I'm having some problems with flock and file descriptors..  I'm
reasonably perl literate, but this file i/o is a little above me right 
now.

I have a script that opens a hash database with appropriate file locking.
My script works fine if I open the database, access it, and exit.  I can't
open it if I've already opened and closed it once before during the run of
the script, so it makes me think my close isn't written properly.

I get a "Bad file descriptor at ..." error message when I try to open it 
again.  BTW, it doesn't matter whether I open the file up for read/write
or just read, so I'll only include the read code:

$dbtype = "DB_HASH";
$dbfile = "/blah/blah.db";
sub LOCK_SH { 1 }
sub LOCK_EX { 2 }
sub LOCK_NB { 4 }
sub LOCK_UN { 8 }

sub opendb_read {
	$db_obj = tie(%db, "DB_File", $dbfile, O_RDWR, 0, $$dbtype) 
		or die "Can't open $dbfile ";
	$db_fd = $db_obj->fd;

	open(DB_FH, "+<&=$db_fd") or die "fdopen $!";
						This is the line that bails
						out the second time around.

	unless (flock(DB_FH, LOCK_SH | LOCK_NB)) {
		print "CONTENTION; can't read during write update 
			Waiting for read lock ($!) .....";
		unless (flock (DB_FH, LOCK_SH)) { die "flock: $!" }
	}
}

sub closedb {
	flock(DB_FH, LOCK_UN);
	untie %db;
	undef $db_obj;
}

The first time it goes through these, it works fine, but if I call 
opendb_read again in the same script, I get that damn error.

If someone could help me out in any way, I would be most appreciative.
I cannot figure out what's going on for the life of me.  I've poked
around on dejanews, but I can't find anything applicable.

If anyone needs any more info, please email me or post a reply and I'll
post what you ask for.

Thanks a lot!


------------------------------

Date: Fri, 20 Nov 1998 00:25:07 -0600
From: REUBEN LOGSDON <rlogsdon@io.com>
To: A Chung <amyun@ricochet.net>
Subject: Re: File I/O & text processing
Message-Id: <Pine.BSF.4.02A.9811200022440.17059-100000@schultz.io.com>

in general, the best idea is to write all new text to a temp file, then
unlink then main file and rename your temp file over to the main name.
however i saw a documented way to both read/write on the same filehandle
using "+<".  From c:/perl/docs/perl/perlfunc.html:

--
open FILEHANDLE 
Opens the file whose filename is given by EXPR, and associates it with
FILEHANDLE. If FILEHANDLE is an expression, its value is used as the name
of the real filehandle wanted. If EXPR is omitted, the scalar variable of
the same name as the FILEHANDLE contains the filename. If the filename
begins with ``<'' or nothing, the file is opened for input. If the
filename begins with ``>'', the file is opened for output. If the filename
begins with ``>>'', the file is opened for appending. You can put a '+' in
front of the '>' or '<' to indicate that you want both read and write
access to the file; thus '+<' is usually preferred for read/write
updates--the '+>' mode would clobber the file first. These correspond to
the fopen(3) modes of 'r', 'r+', 'w', 'w+', 'a', and 'a+'. 
--

i could not get this to work

Regards,
Reuben Logsdon


On Thu, 19 Nov 1998, A Chung wrote:

> Could someone please help me with a file i/o question using PERL?
> 
> I would like to open a file and add text or replace text in the same
> file.
> 
> So far I have figured out that IN and OUT seem to be key words for the
> open command for reading/writing. I would have thought that the
> filehandle parameter would have a key word like this. Then again I am
> new to this.
> 
> 
> Andrew
> 
> 



------------------------------

Date: Fri, 20 Nov 1998 01:18:00 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: How do i trim a string in Perl??
Message-Id: <1dirmhk.1g0338ailsehsN@bay2-205.quincy.ziplink.net>

<blanchardo@my-dejanews.com> wrote:

> try this :
>  $abc =~ s/^ *(.*) *$/$1/;

Woops...  This will not strip the trailing spaces.  They'll be matched
by (.*) and kept.

Try the solution from the FAQ (which has already been posted to this
thread several times) instead.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


------------------------------

Date: Fri, 20 Nov 1998 00:12:14 -0600
From: REUBEN LOGSDON <rlogsdon@io.com>
Subject: Re: how to get `date` in perl for win32 (newbie)
Message-Id: <Pine.BSF.4.02A.9811200010340.17059-100000@schultz.io.com>

Try:

my $date = scalar localtime(time);

It prints a little different output than the sys command, but it's the
same time.

Regards,
Reuben Logsdon


On Wed, 18 Nov 1998, Brett M. Zimmerman wrote:

> j9feng@my-dejanews.com wrote:
> 
> > The following codes work fine under linux,
> >
> > my $date=`date`;
> >
> > but it will not work under win95, because the command 'date' under
> > win95 will print the current date and then ask for "Enter new
> > date(MM/DD/YY): " expecting you input new date or just hit ENTER.
> >
> > Is there a way to get the current date?
> >
> 
>  the /T option causes the date command to just give the date without
> prompting for a change.
> 
> --
> Brett M. Zimmerman
> zim@ou.edu
> 
> 
> 
> 
> 



------------------------------

Date: Thu, 19 Nov 1998 21:20:35 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: I download ActiveState but don't understand how to install it on Win98
Message-Id: <MPG.10be9bfce2d21e73989916@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <3654CC1A.EDEFF758@cam.org> on Thu, 19 Nov 1998 20:55:38 -
0500, Sylvain Lavigne <proband@cam.org> says...
> I download ActiveState but don't understand how to install it on Win98.
> I supposed I have to play around with the registries but don't know
> exacly how to doit to make it work.

I have installed their Perl software easily on NT and Windows 95, but I 
do not have Windows 98.  I just double-click on their .exe and their 
install program takes over.  I haven't had to edit the registry, though 
I did have to mess around with IIS4 (but everyone has problems there).

> I am using Netscape Communicator, do I need to configure other things
> there?

That seems irrelevant.

> So, what is the best procedure and fastest procedure to make it work.

See above.  Good luck!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 19 Nov 1998 21:50:05 -0800
From: dana@oz.net.DELETE.CAPS (Dana Booth)
Subject: Re: Is it possible to run a web server on Win95?
Message-Id: <3655030d.0@news.oz.net>

In article <3654E41F.BA773505@fit2print.com>
Kris <kris@fit2print.com> wrote:

> I have Apache 1.3.3 and Perl 5.0, and I'm wondering if its worth my time
> trying to figure out how to configure them to run on Win95 (4.00.950b,
> 96 megs RAM, Pentium 166).  Looking through the documentations it seems

If you're interested in only running a small time web server, let me make a suggestion...  Try 
TinyWeb from Ritlabs. It's a freebie, the friggin' whole archive is only a 56k zip file, it runs 
cgi scripts, and it works just fine. Probably not for big loads, and the configuration is limited, 
but if you want a small web server for Windows 95, you can have it up and running in about 
5 minutes. If you're interested in giving it a try, it's at www.ritlabs.com

---------------------------
Dana Booth <dana[at]oz.net>
Tacoma, Wa., USA
---------------------------



------------------------------

Date: Fri, 20 Nov 1998 04:16:01 GMT
From: dkcombs@netcom.com (David Combs)
Subject: Re: Multipliers x{m,n}
Message-Id: <dkcombsF2pD6p.BKz@netcom.com>

<snip>
>
>Each approach yields a list of captured matches, and you would be well 
>advised to assign the list to an array and work with offsets, than to 
>use $1, $2, ...
>
>-- 
>(Just Another Larry) Rosler


What do you mean, "offsets"?   "Subscripts", "indices"?
Or offsets INTO some string?




------------------------------

Date: Thu, 19 Nov 1998 21:31:09 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Multipliers x{m,n}
Message-Id: <MPG.10be9e7843aa6bf5989917@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <dkcombsF2pD6p.BKz@netcom.com> on Fri, 20 Nov 1998 04:16:01 
GMT, David Combs <dkcombs@netcom.com> says...
> >Each approach yields a list of captured matches, and you would be well 
> >advised to assign the list to an array and work with offsets, than to 
> >use $1, $2, ...
> >
> >-- 
> >(Just Another Larry) Rosler
> 
> What do you mean, "offsets"?   "Subscripts", "indices"?
> Or offsets INTO some string?

Array indices.  Sorry for the vague terminology.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Thu, 19 Nov 1998 22:52:33 GMT
From: *ace*@programmer.net (Thomas Jordan)
Subject: Re: Need equivalent to a sh's export command.
Message-Id: <3654a093.719427291@news.alpha.net>

On Thu, 19 Nov 1998 18:25:27 +0100, Hendrik Woerdehoff
<hendrik.woerdehoff@sdm.de> wrote:

>Thomas Jordan wrote:
>> On Thu, 19 Nov 1998 09:17:22 GMT, dave@mag-sol.com wrote:
>> >In article <36532a40.623599749@news.alpha.net>,
>> >  *ace*@programmer.net (Thomas Jordan) wrote:
>You cannot do this. Neither on UNIX nor on NT. Period.
>
>If your calling process happens to be a shell you might be able to write
>the shell commands to change the environment to a file. Then the shell
>could source this file. But that's the _only_ way to do it.

Ok :-(
Thanks for the info  :-)

-- Tom.	
===================================================
Thomas Jordan
mailto:ace -at- programmer.net
no-spam:replace -at- with @


------------------------------

Date: Thu, 19 Nov 1998 23:05:13 -0500
From: sara starre <nospam.perl_rocks@hotmail.com>
Subject: opening an already opened file
Message-Id: <3654EA79.DAA7051C@hotmail.com>

I had a file that was already opened, and I didn't realize that I hadn't
closed it. In a sub I opened it again. The open seemed to have no effect
at all - not even an error even though I was using /usr/local/bin/perl
-w

Shouldn't it have either said something like (open attempted on already
opened file) or reset the pointer to record 1? It seemed to do nada!

HUG,
S

--
"I'll quit using PERL when they pry my cold, dead fingers off the
mouse.."
-Sara Starre 1998




------------------------------

Date: Fri, 20 Nov 1998 04:27:54 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: opening an already opened file
Message-Id: <ed652.148$RQ1.395@nsw.nnrp.telstra.net>

In article <3654EA79.DAA7051C@hotmail.com>,
	sara starre <nospam.perl_rocks@hotmail.com> writes:
> I had a file that was already opened, and I didn't realize that I hadn't
> closed it. In a sub I opened it again. The open seemed to have no effect
> at all - not even an error even though I was using /usr/local/bin/perl
> -w
> 
> Shouldn't it have either said something like (open attempted on already
> opened file) or reset the pointer to record 1? It seemed to do nada!

While this cannot be found in the documentation for open, it can be
found in the documentation for close:

# perldoc -f close
[snip]
You don't have to close FILEHANDLE if you are immediately going to do
another C<open()> on it, because C<open()> will close it for you.
(See C<open()>.)  However, an explicit C<close()> on an input file
resets the line counter (C<$.>), while the implicit close done by
C<open()> does not.
[snip]

So, the open did do something, it closed the file, and reopened it.
It will not reset the line counter, but it will return the File
Handle's position to 0, in other words, it will reset the pointer to
record 1.

Try a little script like this:

#!/usr/local/bin/perl5.00404 -w
use strict;

for (1..2)
{
	open (IN, $0) || die "Couldn't open $0: $!";

	for (1..3)
	{
		# can't do this at once, because $. would be out of sync
		my $line = <IN>;
		print "$. $line";
	}
}

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | 
Commercial Dynamics Pty. Ltd.       | Curiouser and curiouser, said Alice.
NSW, Australia                      | 


------------------------------

Date: Fri, 20 Nov 1998 13:26:07 +0800
From: Sreenivas <sreenivas@sns.com.sg>
Subject: PERL for windows 95/NT
Message-Id: <3654FD6F.809F1997@sns.com.sg>

Hi,

I am new to PERL. I want to know where can I get PERL for windows 95/NT.

Please help.


Thanks
Sreenivas
email:sreenivas@sns.com.sg





------------------------------

Date: Thu, 19 Nov 1998 21:17:43 -0800
From: "Rusty Williamson" <rwilliamson@uno.gers.com>
Subject: Please help on getting username
Message-Id: <yV652.348$ay.12866@news.connectnet.com>

Hi,

I know I saw something on getting the username, the effective and real user
ID as well as group information but I just can't find it and the obvious
stuff is not working.   Can someone please point me in the right direction.

Thanks!

Rusty








------------------------------

Date: Fri, 20 Nov 1998 04:09:14 GMT
From: me <ariste@gol.com>
Subject: Posting FROM Perl
Message-Id: <3654ED8D.801C799A@gol.com>

I was wondering if there is a way to post a STDIN from perl to
another cgi.  I want check the data in Perl and if data from
the STDIN is ok, pass it along to another script just as if it
had been posted to the second script in the first place.

I have tried using

open(FILE, '|blahblahblah.cgi' || die "Can't open script!\n");
print FILE <STDIN>;
close (FILE);

and variations on it using read but to no avail.  The second 
script requires all of the Post headers/info.

any ideas?


Steve


------------------------------

Date: 20 Nov 1998 05:33:00 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Pretty printing from newer CPerl mode
Message-Id: <732uuc$7tr$1@mathserv.mps.ohio-state.edu>

I found out that the fine printout which CPerl was giving on my
machine was due to my customization, and that the "normal" Emacs would
not pretty-print unless you spend a lot of blood on configuration.

I released a new version of CPerl mode 

  ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode

which supports "meaningful" printing by default. (Available in Tools
submenu, it works in 20.3, does not work in 19.33, do not know exactly
when ps-print got smart enough.  Note that you may need auto-resizing
minibuffer or need to scroll it if the file name is too long.)

However, many people will find this first try "too picturesque" (it is
:-\).

Please help configuring printout configuration (in
`cperl-ps-print-face-properties' and in CPerl Faces configuration
subtree) so that

   a) all the info is preserved;
   b) More important constructs get more highlight;
   c) People do not run from you the moment you show them the printout.

Send me your suggestions!

Ilya


------------------------------

Date: Thu, 19 Nov 1998 21:30:00 -0800
From: "Xah" <xah@best.com>
Subject: Re: programing fun: trees: FlattenAt
Message-Id: <3654fe5e$0$12761@nntp1.ba.best.com>

Thanks to David Alan Black <dblack@pilot.njin.net> and Rick Delaney 
<rick.delaney@shaw.wave.ca>. Very cool solutions.

David's first solution has a bug. For example,
 print Dumper FlattenAt(['a', ['b']], [1]);
 # should return ['a', 'b'] but it doesn't.
David, can you post a fix?

David second solution:

sub FlattenAt {
   my ($tree, @levels) = (shift, @{shift()});
   my $offset = pop @levels;
   my $parent = $tree;
   foreach my $l (@levels) {
      $parent = $parent->[$l];
   }
   my $child = $parent->[$offset];
   splice @{$parent}, $offset, 1, @{$child};
   return $tree;
}

Excellent!

----------
Rick Delaney <rick.delaney@shaw.wave.ca> wrote:
>... but it should be pointed out that the original tree is
>altered.

Yes. It is important that the argument not be altered. I didn't realize this detail until yesterday. All my previous codes need to be fixed.

>The simplest solution to this is to make a copy of the tree first.  Here
>is one way:
>
>    sub CopyTree { # assumes only scalar or array ref elements
>        return [map { ref($_) ? CopyTree($_) : $_ } @{$_[0]}];
>    }

Yes, this is great. Thanks.

-----
Here's my original solution. It is basically the same as David Black's second solution.

#!perl -w
use strict;
use Data::Dumper; $Data::Dumper::Indent=0; $Data::Dumper::Deepcopy=1;

sub _flattenAt ($$) {
my $ref_tree = [@{$_[0]}];
my $ref_index = [@{$_[1]}];

my @parentNodeIndex = @{$ref_index}; pop(@parentNodeIndex);
my @parentNode = @{eval('$ref_tree' . join('', (map {"->[$_]"} @parentNodeIndex)))};
my $treePartsString = '$ref_tree' . join('', (map {"->[$_]"} @$ref_index));
splice(@parentNode, $ref_index->[-1], 1, @{eval($treePartsString)});

eval( '$ref_tree' . join('', (map {"->[$_]"} @parentNodeIndex)) . ' = \@parentNode');

return $ref_tree;
};

#-------------testing---------

print Dumper FlattenAt(['a', ['b']], [1]); # returns ['a', 'b'].
print Dumper FlattenAt([[8,['a']], [3] ], [0]); # returns [8, ['a'], [3] ]
print Dumper FlattenAt([ [8, ['a']], [3] ], [0,1]); # returns [ [8, 'a'], [3] ]

__END__

I thought that the line
 my $ref_tree = [@{$_[0]}]
should take care of the copying, but apparently that's not the case. For example,
 my $tree = [[[[4]]]];
 my $tree2 = _flattenAt($tree, [0,0,0]);
 print Dumper($tree,$tree2)
prints $VAR1 = [[[4]]];$VAR2 = [[[4]]];

Can anyone explain?

 Xah, xah@best.com
 http://www.best.com/~xah/PageTwo_dir/more.html
 "Petty penguins make way: GNU HURD is coming! <www.gnu.org>"


------------------------------

Date: 20 Nov 1998 06:08:23 GMT
From: pete@localhost.localdomain (Peter J. Kernan)
Subject: Re: reverse comma operator in the camel
Message-Id: <73310n$gaq$1@alexander.INS.CWRU.Edu>

In article <3652dd54.0@mirage.iasi.com>,
	jdl@iasi.com (J.D. Laub) writes:
> On page 48 of the camel:
> 
> # A "reverse comma operator".
> return (pop(@foo),pop(@foo))[0];
> 
[...snip...]
>     my @foo = (101, 303);
>     my $a = (pop @foo, pop @foo)[0];
>     print "a=$a.\n";
> 
> This prints 303, the RIGHT argument in the list, which is the 
> same as the 
> comma operator.  Can someone explain what Larry, Tom, & Randall 
> are trying to 
> convey with their "reverse comma operator" example?
> 
Perhaps it should be called the "double reverse comma operator".

-- 
	Perl Elves Rumble Lightheartedly
open SIG, "<$ENV{HOME}/.sig"         or die       "sigless!     $!"; 
$sig = do {local $/; <SIG>};         close SIG && print<<"$sig SIG";
        Pete Kernan  CWRU Physics and Statistics Depts
        http://theory2.phys.cwru.edu/~pete
$sig SIG


------------------------------

Date: Fri, 20 Nov 1998 07:27:40 +0100
From: Evert Smit <admin@sidhe.net>
Subject: Re: Server Administration with Perl
Message-Id: <36550BDB.1B1A4A8C@sidhe.net>

Hmm yes in a matter of fact i do have :) i am pretty familar with perl when it
comes to writing smal scripts. especially if they have to connect to MiniSQL
Databases. So i've never bothered to use files. Could anyone give me a brief code
snipplet for the following operations in a file? (Open,Close,Add line, Remove
Line, Replace line) What i am trying to do is to manage the redirect file, that
each user got in his directory.

Regards

Evert Smit

brian d foy wrote:

> In article <36540E2A.EA0BCCF9@sidhe.net>, Evert Smit <admin@sidhe.net> posted:
>
> > i am looking for a solution to have a web based application, that let's
> > users edit their various services on a webserver. Issues like managing
> > the e-mail forwarder account, issues like creating new e-mail accounts
> > or simple things like passwort protecting their directories. Any help,
> > hints and tips will be greatly apprecitated.
>
> um, use Perl?  personally, i don't recommend admin-ing a box via the
> web.  but then, i don't allow root logins from remote machines for
> the same reason ;)
>
> do you have more specific questions?
>
> --
> brian d foy                                 <http://computerdog.com>
> Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
> Perl Mongers <URL:http://www.pm.org>



------------------------------

Date: Thu, 19 Nov 1998 23:36:01 -0600
From: "Peter Moore" <pmoore@interaccess.com>
Subject: Re: Single word ouptu from aa array
Message-Id: <732v3p$7rf$1@supernews.com>


MSmith wrote in message <0%Mx1.338$ML4.1093024@news4.mia.bellsouth.net>...
>Im new to Perl. I'M trying to place a file, a txt file, into an array..then
>print out the first character of the first line..and then the second
>character....etc..but IM having a bit of trouble.  IM only able to print
out
>a line at a time:
>
>open (INFILE, "c:\\csv\\cpu_in\\test.txt");
>@csvfiles = <INFILE>;
>close (INFILE);
>print @csvfiles[0];
>
>
>

Its good that you are getting a lot of help with this.  to let you know why
your code dosn't  work the way you think it should might help you in future.

my intreptation is the assignment @csvfiles = <INFILE>; makes all lines that
end in <CR> become an array of stings; like this

char *string_array[max_string];

when you try to print, you are actually giving the pointer to the the n'th
string_array that was built.

print @csvfiles[3] gives you the 3rd pointer to whatever was on the third
string and so you get the whole 3rd line. ive had this problem too and im
not too hot at perl but i got over it by:

$str_line = @str_array;
print $str_line[i++];

see ya
Pete





------------------------------

Date: Thu, 19 Nov 1998 23:05:59 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: sort related ...
Message-Id: <MPG.10beb4b487fc0fb0989721@news.scescape.net>

In article <3654DF52.A48559CF@hotmail.com>, Rakesh Puthalath 
<rakesh_puthalath@hotmail.com> pounded in the following:
=> 1               @new = sort {
=> 2                     ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
=> 5                } @old;
=> 
=> Can someone explain, line 2

   (            # Put the match in list context
       $b =~    # Bind $b to the next regex
       /=(\d+)/ # Grab digits following first =
   )[0]         # Get first element of list, ie: digit matched

   <=>          # Spaceship, see perlop
   
   (            # Put the match in list context
       $a =~    # Bind $a to the next regex
       /=(\d+)/ # Grab digits following first =
   )[0]         # Get first element of list, ie: digit matched

So, sort @old in descending order based on the number following the first 
equal sign of each element.

=> Thanks

HTH,

=> Rakesh

--Matthew


------------------------------

Date: Thu, 19 Nov 1998 23:43:14 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: sort related ...
Message-Id: <ihv237.gn4.ln@flash.net>

Rakesh Puthalath (rakesh_puthalath@hotmail.com) wrote:

: @new = sort {
:    ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
: } @old;

: Can someone explain, line 2


Uhh, what part don't you understand?


$a and $b are Perl's special variables for doing comparisons
within a sort.

<=> returns -1 if left operand is less than right operand,
             1 if left operand is greater than right operand,
             0 if the operands are equal

=~ binds a pattern match to a string to try and match against

// performs a pattern match

() around the entire match (both sides of the =~) gives it
a list context.

a pattern match in a list context returns all of the strings
that matched a parenthesized part

[0] takes an array slice consisting of the first such element

/=(\d+)/ matches an equals sign followed by one or more digits

-----

It sorts based on the first digits that follow an equals sign.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 20 Nov 1998 01:18:02 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Two-Part RE question
Message-Id: <1diroit.1f0yebpuwss2zN@bay2-205.quincy.ziplink.net>

Erik <eln@cyberhighway.net> wrote:

> Or, let's be a little more creative, and allow for nested []'s.
> Here's one that takes a string from STDIN, and prints each level of
> nested brackets.  So, entering "Just [Another [Perl] Hacker]" would
> output:
> Another [Perl] Hacker
> Perl
> 
> Here's the code for that:
> while(<>){
>         print while(s/^.*?\[(.*?)\](?!.*?\]).*$/$1/)
> }

Unnecessary use of non-greedy matching.
Unnecessary use of non-greedy matching.
Unnecessary use of non-greedy matching.


while(<>){
        print while(s/^[^\[]*\[(.*)\].*$/$1/);
}

Just as effective, rather more efficient.


Benchmark: timing 10000 iterations of control, fancy, simple...
   control:  0 secs ( 0.07 usr  0.00 sys =  0.07 cpu)
            (warning: too few iterations for a reliable count)
     fancy: 16 secs (16.13 usr  0.00 sys = 16.13 cpu)
    simple:  6 secs ( 5.72 usr  0.00 sys =  5.72 cpu)


use Benchmark;

$a = ('a' x 10) . '[';
$b = 'b' x 10;
$c = ']' . ('c' x 10);

$x = ($a x 10) . $b . ($c x 10);\

timethese(10_000, {
    fancy   => sub { $_ = $x; 1 while s/^.*?\[(.*?)\](?!.*?\]).*$/$1/ },
    simple  => sub { $_ = $x; 1 while s/^[^\[]*\[(.*)\].*$/$1/ },
    control => sub { $_ = $x },
});


-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


------------------------------

Date: Fri, 20 Nov 1998 01:18:04 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Two-Part RE question
Message-Id: <1dirpp4.ojqk5kz8e4dhN@bay2-205.quincy.ziplink.net>

Martien Verbruggen <mgjv@comdyn.com.au> wrote:

> [explaining difference between:]

> /\[(.+)]/;
> print "$&\n";
> 
> /\[(.+?)]/;
> print "$&\n";

Note that the latter regex can be written using greedy matching:

/\[([^]]+)\]/

Most of the uses of non-greedy matching posted to clpm can be rewritten
with greedy matching, making the regex more efficient.  Too many Perl
programmers use non-greedy matching without understanding it.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


------------------------------

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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 4262
**************************************

home help back first fref pref prev next nref lref last post