[6834] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 459 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 9 20:07:18 1997

Date: Fri, 9 May 97 17:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 9 May 1997     Volume: 8 Number: 459

Today's topics:
     Re: [Q] Getting the pid of an execed process. <dorman@s3i.com>
     Re: [Q] program execution (Andrew M. Langmead)
     Re: A Perl Question <usenet-tag@qz.little-neck.ny.us>
     FileHandle module shell/daemon problem <webmaster@looksee.com>
     Re: Have a question? Post it here at the CGI Discussion (for spam reasons the real address is in the body) (TOTO)
     Re: Hide my code? <mishra.aditya@emeryworld.com>
     Re: How Does Someone Copy a File in perl? (I R A Aggie)
     Re: How Does Someone Copy a File in perl? (A. Deckers)
     how is syslog supposed to find 'hostname'? (Bernard Cosell)
     Re: HP OV SNMP Question <cliff@tricon.net>
     Re: if (condition) always testing true (Abigail)
     Re: Incorrect warning? (Mik Firestone)
     Re: need help w/forms and Perl (Jeff Yoak)
     Re: Perl auto-replier (A. Deckers)
     Re: problems with open command (A. Deckers)
     Re: problems with open command john2@zapcom.net
     Re: problems with open command <sibsib@hotmail.com>
     regular expression <zaheed.haque@ein.ericsson.se>
     Re: regular expression <amit@csd.sgi.com>
     Searching NT Network For File <rauenzc@enter.net>
     Sorting Hashes (Or a list of hashes..) <jcokos@ccs.net>
     Re: system () won't execute the called program. <mishra.aditya@emeryworld.com>
     Re: url detection in a string (Abigail)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 09 May 1997 15:25:41 -0400
From: Clark Dorman <dorman@s3i.com>
Subject: Re: [Q] Getting the pid of an execed process.
Message-Id: <dd8r0jvm2.fsf@s3i.com>


andrew@ugh.net.au (Andrew) writes:
> I am trying to exec another program from a perl script and keep track of
> its pid.

Easy enough, I think, _if_ the thing you exec is a simple executable.  There
are some issues I don't understand if it is not a simple executable. 
 
> I fork my perl script and have the child exec. I have the PID of the child
> but exec gives a new PID to the execed process (I want to send a kill to
> the process later).

It doesn't on _my_ system.  I note that you did not include information about
your system (mine: perl -V gives Solaris 2.5 on a sun sparcstation-20).  The
exec'ed process gets the perl child's id.  See below for an example.
 
> Does anyone have any ideas?

Here's my script, called k2.pl.  time_waster is a time-wasting c-program.  
----------------------------------------------------------------------
#!/home/dorman/bin/perl -w
use strict;
use Config;

my $pid = fork;
my $our_pgrp;

$our_pgrp = getpgrp;

defined ($pid) or die "couldn't fork: ($!)" ;

if ($pid) {
   print " Child pid is ($pid).  Now in parent ($our_pgrp) is pgrp\n";
   sleep 10;
   print " Stopping child from parent  ($pid)\n";
   kill 'STOP', $pid or die "($!) returned from stop pid";
   sleep 10;

   print " Restarting child from parent  ($pid)\n";
   kill 'CONT', $pid or die "($!) returned from cont pid";
   sleep 10;

   print " Killing child from parent  ($pid)\n";
   kill 'KILL', $pid or die "($!) returned from kill pid";
   # or system("kill -9 $pid") or die " ($!) returned from kill pid";

   print " tried to kill\n";
} else {
   # In child.
   sleep 5;
   print " Exec'ing in child ($our_pgrp) is pgrp\n";
   exec("time_waster");
}
----------------------------------------------------------------------

It looks like this when run:  

blackbird:sub_stuff (2:47pm) 17% k2.pl > k2.output &
[1] 17478

blackbird:sub_stuff (2:47pm) 18% sps
  PID  PPID S COMMAND
17479 17478 S /home/dorman/bin/perl -w k2.pl
17478 17351 S /home/dorman/bin/perl -w k2.pl
17351 17349 S /home/dorman/bin/tcsh

blackbird:sub_stuff (2:47pm) 21% sps
  PID  PPID S COMMAND
17479 17478 O time_waster
17478 17351 S /home/dorman/bin/perl -w k2.pl
17351 17349 S /home/dorman/bin/tcsh

blackbird:sub_stuff (2:47pm) 23% sps
  PID  PPID S COMMAND
17479 17478 T time_waster
17478 17351 S /home/dorman/bin/perl -w k2.pl
17351 17349 S /home/dorman/bin/tcsh

blackbird:sub_stuff (2:48pm) 27% sps
  PID  PPID S COMMAND
17479 17478 O time_waster
17478 17351 S /home/dorman/bin/perl -w k2.pl
17351 17349 S /home/dorman/bin/tcsh

[1]  + Done                          k2.pl > k2.output

blackbird:sub_stuff (2:48pm) 30% cat k2.output 
 Child pid is (17479).  Now in parent (17478) is pgrp
 Stopping child from parent  (17479)
 Restarting child from parent  (17479)
 Killing child from parent  (17479)
 tried to kill
blackbird:sub_stuff (2:48pm) 31% which sps
sps: 	 aliased to /usr/bin/ps -o pid -o ppid -o s -o args

The above does what we want: forks and execs a process, and sometime later
kills the child from the parent process.  

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

_But_, what if we want to do the above not with a simple executable, but
rather a script that calls an executable?  Then it doesn't work like that:

In the k2.pl script replace:
   exec("time_waster");
with:
   exec("time_waster.sh");
where time_waster.sh looks like this:
 ------------------------------
#! /bin/csh -f
time_waster
 ------------------------------
That is, a simple csh script that calls the time-waster c-program

blackbird:sub_stuff (3:05pm) 36% k2.pl > k2.output2 &
[1] 17524

blackbird:sub_stuff (3:05pm) 37% sps 
  PID  PPID S COMMAND
17525 17524 S /home/dorman/bin/perl -w k2.pl
17524 17351 S /home/dorman/bin/perl -w k2.pl
17351 17349 S /home/dorman/bin/tcsh

blackbird:sub_stuff (3:05pm) 39% sps
  PID  PPID S COMMAND
17528 17525 O time_waster
17525 17524 S /bin/csh -f ./time_waster.sh
17524 17351 S /home/dorman/bin/perl -w k2.pl
17351 17349 S /home/dorman/bin/tcsh

blackbird:sub_stuff (3:06pm) 43% sps
  PID  PPID S COMMAND
17528 17525 O time_waster
17525 17524 T /bin/csh -f ./time_waster.sh
17524 17351 S /home/dorman/bin/perl -w k2.pl
17351 17349 S /home/dorman/bin/tcsh

blackbird:sub_stuff (3:06pm) 51% sps
  PID  PPID S COMMAND
17528 17525 O time_waster
17525 17524 S /bin/csh -f ./time_waster.sh
17524 17351 S /home/dorman/bin/perl -w k2.pl
17351 17349 S /home/dorman/bin/tcsh

[1]  + Done                          k2.pl > k2.output2

blackbird:sub_stuff (3:06pm) 59% sps
  PID  PPID S COMMAND
17528     1 O time_waster
17351 17349 S /home/dorman/bin/tcsh

blackbird:sub_stuff (3:10pm) 63% cat k2.output2
 Child pid is (17525).  Now in parent (17524) is pgrp
 Stopping child from parent  (17525)
 Restarting child from parent  (17525)
 Killing child from parent  (17525)
 tried to kill
blackbird:sub_stuff (3:10pm) 64% 

Oops.  Well, when we exec'ed, it kept the perl child's pid, which is good.
The parent sends the signals and the process does the "correct" thing, only
the process in question is a shell script, and stopping (and later cont'ing)
it does not affect it's subprocess, the time_waster.  Ugh.  Then, of course,
when we kill the child process pid (the shell script), it dies nicely, but
leaves an orphan process (the time_waster).  

So, my question would be: how do I stop, restart, and then kill a process
_and_ it's children?  I would love to have the answer to this question
because that's what I'm working on right now, and I cannot figure it out.
I've gone through the perlipc and cannot figure out the answer.  I'm
presently going through this sort of thing with Proc::Simple to see if it has
the same thing.  Can anyone suggest anything?

-- 
Clark Dorman				"Evolution is cleverer than you are."
http://cns-web.bu.edu/pub/dorman/D.html                -Francis Crick


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

Date: Fri, 9 May 1997 14:41:13 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: [Q] program execution
Message-Id: <E9x4sp.2n0@world.std.com>

cjk@omedsrvb.omed.pitt.edu (Carl Joel Kuzmich) writes:


>Hi

>I have starting learing perl and confused with a little program I wrote.
>I bought the O'Reily mouse book and type in an example pgm, code
>snippet:

>print "<TITLE> "xxxxxxxxxxxxxxxx",  </TITLE> \n";

This line is a perl syntax error. Maybe you meant this:

print "<TITLE>", "xxxxxxxxxxxxxxxx",  "</TITLE> \n";
(three quoted items to print)or this:
print "<TITLE> \"xxxxxxxxxxxxxxxx\",  </TITLE> \n";
(one item with embedded quotes)

You might want to check and run your perl scripts yourself before you
have the server execute them on your behalf. Perl's error messages
will probably be detailed enough for your to determine the error. It
will give you a message containing the type of error (which you can
look up in the perldiag man page if you need some explaination of the
problem.) and the line number at which the error occured.

-- 
Andrew Langmead


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

Date: 9 May 1997 20:26:01 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: A Perl Question
Message-Id: <5l018p$t0a$1@news.netusa.net>

Ali Ranjbar  <ranjbar@cig.mot.com> wrote:
>I am new to Perl. I am trying to search for parentheses in a string and
>then get read of them. Getting read of them should not be difficult.

There are six respones to your question right now on my server, and I
don't like any of the answers. If that is exactly what you want to
do, tr is your friend:

$summary =~ tr:()::d;

Finds all parens and deletes them from the variable $summary.
Simple, fast, efficent.

Use a better subject in the future. "A Perl Question" in a perl
newsgroup is about as meaningful as "A Headline" on a newspaper.
"deleting parentheses" would have been a good subject.

>However; sounds like Perl is using () for memory in regular expressions.

Yup. It does.

>How do I do that. I tried:
>if ($summary=~ /\(/{ # where $summary has the string I am searching in.

Misssing a close paren. "if ($summary=~ /\(/){" is right.

>if ($summary=~ /(/{ # where $summary has the string I am searching in.

Missing close paren and illegal regexp.

>if ($summary=~ /(|)/{ # where $summary has the string I am searching in.

Missing close paren and regexp matches the empty string two ways.

Elijah
------
autoselects /\W(reg\S*\s*ex([^a-oq-z]|$)|res?([^\w:]|$)|pattern\s*match)/


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

Date: Fri, 09 May 1997 18:07:16 -0500
From: Tom Harvill <webmaster@looksee.com>
Subject: FileHandle module shell/daemon problem
Message-Id: <3373AE24.4433@looksee.com>

Hello Perl wizards,

Does anyone have a clue why this script:

-- CUT --
#!/usr/local/bin/perl
BEGIN {
  use lib "/usr/local/lib/perl5/";
}

use FileHandle;
my $FH = FileHandle->new_tmpfile || die "Can't do it: $! \n";
print ("***File Handle is: $FH \n");        
-- CUT --

Gives this output from the command line:
***File Handle is: FileHandle=GLOB(0x680b8)
(what I want)

BUT, when run from an daemon (sendmail alias in
particular), it gives this:
Can't do it: Invalid argument

I actually stripped out the offending code from
MIME-tools module 'ToolUtils.pm' that is doing 
this.  Doesn't the fact that $! contains an
error statement mean that the script got to
FileHandle.pm?

Does anyone have any idea, I need help...

Thank you very much in advance...

Tom Harvill
tom@mortsun.unl.edu


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

Date: Fri, 09 May 1997 19:23:06 GMT
From: sorry@no.can.do (for spam reasons the real address is in the body) (TOTO)
Subject: Re: Have a question? Post it here at the CGI Discussion Forum.
Message-Id: <337475bf.5209772@news.enterprise.net>

On Thu, 8 May 1997 23:05:13 -0500, tadmc@flash.net (Tad McClellan)
wrote:
>I didn't even have to go to the site to know that is was silly.
>Because in the original post:
>No usable address in the From:
>No Reply-to:
>No email address in the .sig
Sorry, my mistake. I usually leave the reply to field as
sorry@no.can.do  or something similar as I have been receiving a
number of spam messages as a result of posts from companies and post
my EMAIL address in the body of the message. For some reason it did
not do it.
For the record it is shootem@hotmail.com
>
>Anonymous postings are a dead giveaway...
See above
>
>Oh silly you. The poor crackers have to make a living too, ya know  ;-)
Actually I'm not a cracker, hacker or any of that stuff so this is not
the reason. This is the official CGI FAQ that Enterprise PLC created
back in April 96.
 
"CGI scripts can reside in any directory, however, this directory must
be both readable and writeable by everyone and executable. As such,
you will need to create a sub-directory."
As you can see Enterprise are quite happy to dish out this
information!

Now do you have anything constructive to post?

TOTO

shootem@hotmail.com



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

Date: 9 May 1997 22:22:52 GMT
From: "EWW" <mishra.aditya@emeryworld.com>
Subject: Re: Hide my code?
Message-Id: <01bc5ccd$0a5190e0$6496010a@mwa152504.emeryworld.com>

ATLANTIDE <"atlantide@wanadoo.fr"@wanadoo.fr> wrote in article
<5kutcn$km1@hetre.wanadoo.fr>...
> Hello,
> 
> How can I hide my code for a Perl program. I'd like to write Perl
> programs but i don't someone to change them. Like in C, an Exe program
> is not "uptatable" directly. Has Perl this utility ?

Here's an earlier posting in this newsgroup which can help
Adi


And then, Magnus suddenly uttered...

> Is there a perl obfuscator around?

I'm trying to make one nowadays, but have stumbled into some problems
(or perhaps, it's me not having enough time to figure out the
regexp's :)

here's what I've got:
==================================< arghify.pl >==
#!/store/bin/perl
# STORE is a system for installing and maintaining third party
# software on UNIX computers. For more info, take a look at 
# URL:http://www.pvv.unit.no/~arnej/store/storedoc_toc.html

require 5.003;

# It's quite important to unset the input record seperator here :)
$/ = undef;
$_ = <>;

# Ideally our MetaSyntactical Variable of Choice should be 
# qw(foo bar baz quux quuux quuuux quuuuux) etc - but for simplicity,
# our MetaSyntactical Variable of Choice Today is:
$msv = "foo00";

study;

	# single out the first line - if it begins with #!
	# and save it for later use...
s/^(\#\!.*?[\n\r])/\n/s;
$head = $1;

	# get rid of comments
s/(([\"\'])[^\1]*[^\\]\1)|[^\\]\#.*?$//gm;
	# still buggy!

	# strip away exess space and newlines
s/(([\"\'])[^\1]*[^\\]\1)|\s+/ $1/gs;
	# bugs  h^e^r^e  too :)

	# here we are supposed to swap (Good) variable names 
	# with (Bad) generic variable names (foo01 foo02 etc).
	# - but i can't seem to get it to work :/
# s/([\$\@\%]+)([\w_][\d\w_]*)/$1&foo($2)/gmei;
	# My problem lies here ^^^^^^^^^^, I believe.

print $head.$_."\n";

sub foo {
    $_{$_[0]}=$msv++ unless $_{$_[0]} && return $_{$_[0]};
}
==================================< arghify.pl >==

The script i still buggy, and quite incomplete, but if any of the RE
gurus out there could help me (us? :), I'd send him/her a Fox in the
mail... (Sorry, we haven't got camels in norway :) 

Anyway, as the code is right now - i can do something like this:

18:13 (ra) bin <0>arghify.pl arghify.pl
[snip output]
18:14 (ra) bin <0>arghify.pl arghify.pl | arghify.pl 
[snip output]
18:14 (ra) bin <0>arghify.pl arghify.pl | arghify.pl | arghify.pl 
[snip output]

 .. and get identical output! 8)


> As if lurkers hadn't problems yet reading regexps :-D

> I really need one.

Whatever for? :)


-- Salve Nilsen
-- 
#!/store/bin/perl
#@(#)RELEASE VERSION .sig V1.02 by Salve J. Nilsen - Hacker, Student,
Magician
($_='$ZNVYGB+$FWA?$CII:$BET;')?y:;ZA-Y\:?+${':\nm-za-l.@\:\0:?print:'}.':'.$
';




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

Date: Fri, 09 May 1997 17:10:29 -0500
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: How Does Someone Copy a File in perl?
Message-Id: <fl_aggie-ya02408000R0905971710290001@news.fsu.edu>

In article <5kvsfa$o95@sf18.dseg.ti.com>, simonson@skopen.dseg.ti.com
(Kevin M Simonson) wrote:

+      Anybody have any idea what the diagnostic means by "search pattern",

I know what a "search pattern" is, and I know what a diagnostic is, but
I can't say I've seen 'em put together like that...

+ and/or why it's making that complaint about my code?  I guess the real
+ thing I need to know is how to put a line in a "perl" script that copies a
+ file from the parent directory to the current directory.  Any input on this   
+ would be greatly appreciated.

Under unix:

$ perldoc File::Copy

     NAME
          File::Copy - Copy files or filehandles

[yadda yadda yadda]

James

-- 
Consulting Minister for Consultants, DNRC

To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>


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

Date: 9 May 1997 21:54:04 GMT
From: I-hate-cyber-promo@man.ac.uk (A. Deckers)
Subject: Re: How Does Someone Copy a File in perl?
Message-Id: <slrn5n777s.3hd.I-hate-cyber-promo@news.rediris.es>

In comp.lang.perl.misc,
	fl_aggie@hotmail.com wrote:
>$ perldoc File::Copy
>
>     NAME
>          File::Copy - Copy files or filehandles
>
>[yadda yadda yadda]

Never seen that keyword before. Are you sure? :-)

Alain



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

Date: Fri, 09 May 1997 13:37:25 GMT
From: bernie@rev.net (Bernard Cosell)
Subject: how is syslog supposed to find 'hostname'?
Message-Id: <33732717.177389646@news.rev.net>

Hi--

We're running 5.003 and I tried using Sys::Syslog and ran into an odd
problem.  Near the beginning of the program it does:

 $host = hostname() unless $host;        # set $Syslog::host to change

And it is blowing up on that line because it can't find 'hostname'.
What I'm wondering is how that was ever supposed to work... shouldn't
the Syslog module have had to had a "use Sys::Hostname;"?  If so,
should I just edit that line into my Syslog.pm file?  If not, how _is_
syslog supposed to find its link to hostname?

Thanks!
  /Bernie\
-- 
Bernie Cosell                        mailto:bernie@rev.net
Roanoke Electronic Village


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

Date: Fri, 09 May 1997 15:57:31 -0400
From: Cliff Hall <cliff@tricon.net>
Subject: Re: HP OV SNMP Question
Message-Id: <337381AB.4487@tricon.net>

ldavis@reston.ans.net wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> 
> Does anyone have perl scripts that will convert a mib in
> an rfc to a set of ObjStruct structures for use with the
> HP OpenView snmp api libraries?
> 
> - -Lynch
> - --

Well, I've got a slug....

-Dead parrot


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

Date: Fri, 9 May 1997 21:42:02 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: if (condition) always testing true
Message-Id: <E9xoA3.C5p@nonexistent.com>

On Fri, 9 May 1997 15:26:58 GMT, Jacob Salomon wrote in
comp.lang.perl.misc URL: news:E9x6zq.FvK@nonexistent.com:
++ Hi y'all.
++ 
++ I am new to this newsgroup. This is  my first post here.
++ 
++ I am learning perl now, using the book "Teach Yourself Perl in 21 Days".
++ I am not simply copying examples but experimenting with them. Hence, I
++ wanted to test the "break" statement (since I did not see it in the
++ book's index). But something weird is happening so I added some print
++ statements.
++ 
++ Here is my take on a program from p. 149 of the book. (I am omiting the
++ sort part.)
++ 
++ #!/usr/local/bin/perl

Did you copy this line from the book? If so, BURN THE BOOK. Always,
always, always run with -w, unless you know what you are doing.
And even then, run with -w.

Doing that would have solved all of your problems:

    Unquoted string "break" may clash with future reserved word at - line 9.
    Useless use of a constant in void context at - line 9.
    Identifier "main::count" used only once: possible typo at - line 5.
    Identifier "main::s_array" used only once: possible typo at - line 5.

And when you run it:

    Argument "end" isn't numeric in eq at - line 6, <stdin> chunk 1.
    Argument "Foo" isn't numeric in eq at - line 6, <stdin> chunk 1.

The book should have told you that there is no `break', nor `continue'
in Perl. There are `last' and `next'.  `break' is being treated as
being "break", the first warning tells you that. The second one
complains about use of a string as a single statement - it being
meaningless.  Had you use 'use strict;' it would have failed to even
compile.

The last warnings had told you that you should have used `eq'.


Remember: always, always use -w.




Abigail


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

Date: 9 May 1997 19:34:38 GMT
From: mfiresto@vnet.ibm.com (Mik Firestone)
Subject: Re: Incorrect warning?
Message-Id: <5kvu8e$eke$1@newdelhi.lexington.ibm.com>

In article <5ku8fv$15nm@yuma.ACNS.ColoState.EDU>,
Dave Steffen <steffend@lamar.colostate.edu> wrote:
>Howdy Folks!
>
>	I'm running Perl 5.003 on HP-UX 9.05, and using the -w switch
>I'm getting messages that I assume are incorrect:
Not really, but I will explain that in a few lines.
>
>#!/usr/bin/perl -w
>
>use Getopt::Std;
>getopts ('x:y:w:');
>print "$opt_x $opt_y $opt_w\n"; # these are set in the getopt module
>
>Executing `testbug -x1 -y2 -w3` gives
>
>Identifier "main::opt_w" used only once: possible typo at testbug line 12.
>Identifier "main::opt_x" used only once: possible typo at testbug line 12.
>Identifier "main::opt_y" used only once: possible typo at testbug line 12.
>1 2 3
>
>	Now, it's clear that the $opt_n variables are getting used
>twice (once when they're set and once when they're printed), but
>apparently the -w switch can't catch that.

That particular warning does not look into use'd modules to see if they are
created within.  It is only saying "Hey!  I only see these variables once
in your program, and I want to make sure you know what you are doing".

You can take care of that warning by using the 'use vars' pragma.
    use vars qw( $opt_x $opt_y $opt_w );
should clear the errors.

Mik
-----
Mik Firestone  mfiresto@mindspring.com
Evil Overlord Rule #20: I will never employ any device with a digital
countdown. If I find that such a device is absolutely unavoidable, I
will set it to activate when the counter reaches 117 and the hero is
just putting his plan into operation.


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

Date: Fri, 09 May 1997 19:15:06 GMT
From: jeff@yoak.com (Jeff Yoak)
Subject: Re: need help w/forms and Perl
Message-Id: <5l07lc$gqh@sjx-ixn5.ix.netcom.com>

"Alan J. Flavell" <flavell@mail.cern.ch> wrote:

>On Thu, 8 May 1997, Geoffrey Hebert wrote:

>> Check out the Perl site!
>            ^^^
>I'd be happy to, if you'd give us its URL.

>> http://www.microserve.net/~soccer/

>_THAT's_ "the" Perl site???  

It's also mildly annoying that the first three email addresses I
entered caused server errors.  When asked in situations like that, I
often enter addresses that will work but that I can trace back to the
site if I start getting junk.  I don't mind the poster asking for my
email address to enter the site, but simply believe me that it works.
Whatever "checking" is being done is clearly not working.

Cheers,
Jeff



Jeff Yoak  jeff@yoak.com  http://yoak.com/



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

Date: 9 May 1997 21:52:10 GMT
From: I-hate-cyber-promo@man.ac.uk (A. Deckers)
Subject: Re: Perl auto-replier
Message-Id: <slrn5n774a.opc.I-hate-cyber-promo@nessie.mcc.ac.uk>

[NB: followups to poster]

In comp.lang.perl.misc,
	jhb@delmar wrote:
[call for an auto-replier for clpm]

There is already an auto-replier in operation for this group, maybe more
(not sure i Tom is still doing things in the nackground).

Didn't you get an introductory message the first time you posted? Or was
this your first post? :-)

Alain

-- 
Perl information: <URL:http://www.perl.com/perl/>
        Perl FAQ: <URL:http://www.perl.com/perl/faq/>
    Perl archive: <URL:http://www.perl.com/CPAN/>


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

Date: 9 May 1997 20:55:50 GMT
From: I-hate-cyber-promo@man.ac.uk (A. Deckers)
Subject: Re: problems with open command
Message-Id: <slrn5n73qm.11u.I-hate-cyber-promo@news.rediris.es>

In comp.lang.perl.misc,
	john2@zapcom.net wrote:
>I'm a newbie and have a very basic question. Can anyone tell me why
>the following won't work? I have the permissions wide open (777) and
                                      +++++++++++            +++

Unless you're the only user on that machine, and even then I wouldn't
do it, this is a _really_ bad idea.

>of course, I have my own path in the $logdir.
>
>I'd really appreciate any help.
>
>Liz
>liz@zapcom.net

Which is it, john or liz? ;-)

>#!/usr/bin/perl

For starters, you should enable warnings by using the -w switch.

#!/usr/bin/perl -w

>   $logdir = path/to/log/dir";
              ^
              missing ". Was this in your original code? And since
              you're not interpolating anything, you might as well
              say '/path/to/log/dir', ie use single quotes.

>   $logfile = "test.log";
>   $reflog = "$logdir/$logfile";
>
>   $crlf = "\x0d\x0a";

This is unecessary, AFAIK. "\n" will do the right thing for your OS.

>   print "content-type: text/html$crlf";
>   print "$crlf";
>
>   $referer = $ENV{HTTP_REFERER} or exit 0;

They're going to be mighty confused when they don't get anyhting back
from the server, aren't they? ;-)

>
>   print qq(<a href="$referer">Back</a>);
>
>   lock();

This isn't a valid keyword. Have you defined it yourself as a subroutine?
(I know it's used as an example in man perlfunc, but still.) perl -w
would have told you about this.

>   open(REFLOG, ">>$reflog") or die "cannot open $reflog!\n";

Use the diagnostics provided. The $! global variable contains the error
number or message (depending on the context). It _will_ often help you
solve your problem, so use it and make that:

open REFLOG, ">>$reflog" or die "can't open $reflog: $!\n";

>   print REFLOG "$referer\n";
>   close REFLOG;
>   unlock();

Again, not a valid keyword. perl -w would have told you about this.

HTH,

Alain

-- 
Perl information: <URL:http://www.perl.com/perl/>
        Perl FAQ: <URL:http://www.perl.com/perl/faq/>
    Perl archive: <URL:http://www.perl.com/CPAN/>
>>>>>>>>>>>>> NB: comp.lang.perl.misc is NOT a CGI group <<<<<<<<<<<<<<


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

Date: Fri, 09 May 1997 22:48:06 GMT
From: john2@zapcom.net
Subject: Re: problems with open command
Message-Id: <3373a8f4.13462586@news.zapcom.net>

I wanted to extend a heartfelt thank you to everyone who responded to
my plea! It's tough learning all the rules to perl and to this list
:>. I'll be more detailed in the future. I hope I eventually learn
enough perl to help others with it.

BTW, My first post was recorded as john2 because I was on my nephew's
machine when I posted.

Thanks,

Liz
liz@zapcom.net
---------------------------------------------------------------




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

Date: Fri, 09 May 1997 18:16:46 -0400
From: Scott Blanksteen <sibsib@hotmail.com>
Subject: Re: problems with open command
Message-Id: <3373A24E.A292284D@hotmail.com>

john2@zapcom.net wrote:
> I'm a newbie and have a very basic question. Can anyone tell me why
> the following won't work? I have the permissions wide open (777) and

1) In general, you should be a little more specific than 
"won't work."

2) You're not really planning on leaving the permissions at 
777, are you?

> #!/usr/bin/perl

3) Is this the proper path to Perl on your machine?

4) Try to get in the habit of using the "-w" flag to Perl.

>    $crlf = "\x0d\x0a";
>    print "content-type: text/html$crlf";
>    print "$crlf";

5a) You mean "Content"...

5b) Just "\n\n" is generally sufficient, rather than your $crlf x 2.

>    $referer = $ENV{HTTP_REFERER} or exit 0;

6) Not every browser returns HTTP_REFERER to your script.  
Do you really want to quit the script so unfriendlily?

>    lock();

7) You need to import a module to use this call - it's not in 
Perl by default.

>    open(REFLOG, ">>$reflog") or die "cannot open $reflog!\n";

8) This will send an empty page to the user if it dies.

>    print REFLOG "$referer\n";

9) This will actually work :-)

>    close REFLOG;

10) Often, you want to check the return of close as well.  
(It may fail as a result of a full file system, for example.)

>    unlock();

11) See 7.

Scott

-- 
Scott I. Blanksteen
sib (at) worldnet (dot) att (dot) net


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

Date: Fri, 09 May 1997 22:23:33 +0200
From: Zaheed Haque <zaheed.haque@ein.ericsson.se>
Subject: regular expression
Message-Id: <337387C4.39D5@ein.ericsson.se>

Hey,

Just started to learn about regex. This learning is killing me.. I
have bought the book "Mastering Regular Expression" still it's super
tough stuff.. 

I am just wondering If there is any regular expression software or
something out there anyone aware of.. Someting that takes input
and shots out the correct regular expression in other words something
thats makes regular expression easier.. I am just trying to
find out if there any shortcut! -:)

Thanks in advanced for any help.

Zaheed


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

Date: Fri, 09 May 1997 15:39:48 -0700
From: amit kothari <amit@csd.sgi.com>
Subject: Re: regular expression
Message-Id: <3373A7B4.2781@csd.sgi.com>

Zaheed Haque wrote:
> 
> Hey,
> 
> Just started to learn about regex. This learning is killing me.. I
> have bought the book "Mastering Regular Expression" still it's super
> tough stuff..
> 
> I am just wondering If there is any regular expression software or
> something out there anyone aware of.. Someting that takes input
> and shots out the correct regular expression in other words something
> thats makes regular expression easier.. I am just trying to
> find out if there any shortcut! -:)
> 
> Thanks in advanced for any help.
> 
> Zaheed

I reminds me of a saying by Euclid to the king of greece - "There is no
royal path to geometry".
I guess u just have to slog more.

-- 
==========================================================================
:-) When all else fails, read the instruction.
email : amit@csd.sgi.com     
Home Page: http://www.geocities.com/ResearchTriangle/4960/
==========================================================================


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

Date: Fri, 09 May 1997 16:22:15 -0400
From: "Craig R." <rauenzc@enter.net>
Subject: Searching NT Network For File
Message-Id: <33738777.15BE@enter.net>

I'm new to perl and NT. What I want to do is to create a network
connection to a specific server but I'm not sure how to do this. I have
a book on perl but can't seem to find any way of accomplishing this. I
would appreciate any hints or advice.

Thanks

Craig


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

Date: Fri, 09 May 1997 16:14:18 -0400
From: John Cokos <jcokos@ccs.net>
Subject: Sorting Hashes (Or a list of hashes..)
Message-Id: <3373859A.7111@ccs.net>

I hope someone can help me out.  I've got a sample bit of data and
code at the bottom of this request for you to look at....

I cannot figure out how to sort a "List of Hashes".

Consider the following text file (Beneath the #####):
The code below reads the file and assigns each line to an element in a
hash.
Now, I want to be able to sort the whole thing by "msg_date" and "from".
and output a list of the "msg_num" and "subject" in the sorted order.

HELP PLEASE, I've read everything I can get my hands on to find the
answers
and I've had no luck at all.... 

Thanks,

John Cokos





Text Sample
########################################################################

==START==
Fred
1
John
05/01/1997
How are you
Just a quick note to see how you're doing...
==END==
==START==
 ....another entry like above
==END==


The "code"
########################################################33
  $recnum=-1;
  $linenum=0;
  open (HDR,"$messages");
    @AllLines=<HDR>;
  close (HDR);
  $numlines=@AllLines;
  for($xc = 0;$xc < $numlines;$xc++){
	$AllLines[$xc] =~ s/\cM//g;
	$AllLines[$xc] =~ s/\n//g;
  }  
 
  for($xc = 0;$xc < $numlines;$xc++){

     $t="";	# Initialize everything
     $n="";
     $f="";
     $d="";
     $s="";
     $m="";

     if ($AllLines[$linenum++] =~ /==START==/){
	$recnum++;
	$t = $AllLines[$linenum++];
	$n = $AllLines[$linenum++];
	$f = $AllLines[$linenum++];
	$d = $AllLines[$linenum++];
	$s = $AllLines[$linenum++];
	do {
	  $m = $m . $AllLines[$linenum++] . "\n";
	} until ($m =~ /==END==/);

	$unsorted[$recnum]{"to"}=$t;
	$unsorted[$recnum]{"msg_num"}=$n;
	$unsorted[$recnum]{"from"}=$f;
	$unsorted[$recnum]{"msg_date"}=$d;
	$unsorted[$recnum]{"subject"}=$s;
	$unsorted[$recnum]{"text"}=$m;

     }


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

Date: 9 May 1997 22:12:23 GMT
From: "EWW" <mishra.aditya@emeryworld.com>
Subject: Re: system () won't execute the called program.
Message-Id: <01bc5ccb$932c4600$6496010a@mwa152504.emeryworld.com>

Ken Anderson <anderson@necsys.gsfc.nasa.gov> wrote in article
<y7xenbk7em8.fsf@necsys.gsfc.nasa.gov>...
> 
> I have a perl program which has to execute an external
> c program, so i am using 
> 	system("cprog -p prog.par") && die "cprog failed. $!\n";

> 
> It simply does nothing. cprog never starts. no error message.
> 

How about including the path of the program in the system call ?
Adi




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

Date: Fri, 9 May 1997 21:49:42 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: url detection in a string
Message-Id: <E9xoMu.CsC@nonexistent.com>

On 9 May 1997 16:23:31 GMT, Eli the Bearded wrote in
comp.lang.perl.misc,alt.fan.e-t-b URL: news:5kvj23$l98$1@news.netusa.net:
++ Alastair Aitken  <a.aitken@unl.ac.uk> wrote:
++ >Sascha Kerschhofer wrote:
++ >> $test = "look at http://info.com/mor.html for further information";
++ >> &findurl($test);
++ >> 
++ >> $test should now be: "look at <A
++ >> HREF="http://info.com/more.html">http://info.com/more.html</A> for
++ >> further
++ >> information"
++ >>   $_ =~ s/(.*)(\shttp://.*\s)(.*)/$1 <A HREF="$2">$2</A> $3/g
++             ^^^^^^^^^^^^^^^
++ Oh. Bad idea. That will not work at all.
++ 
++ s,(\bhttp://\S+),<A HREF="$1">$1</A>,g
++ 
++ Would be much better. It still has some flaws, such as what if there is
++ a ',' '.' etc after the URL that is not part of it. Without knowing all
++ the data you will encounter these are hard to deal with.

Read <URL: http://www.ny.fnx.com/abigail/Perl/url.html> about regexs
for URLs.



Abigail


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

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

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