[16210] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3622 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 11 14:10:46 2000

Date: Tue, 11 Jul 2000 11:10:24 -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: <963339024-v9-i3622@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 11 Jul 2000     Volume: 9 Number: 3622

Today's topics:
    Re: How to display the correct time from a time server  (Abigail)
        interacting perl w/ nt/dos (Young H Lee)
    Re: interacting perl w/ nt/dos <sariq@texas.net>
    Re: interacting perl w/ nt/dos <foo@bar.va>
    Re: is this possible? <dpalmeNOSPAM@unitedtraffic.com>
    Re: multidimensional associative arrays (Abigail)
    Re: Multiple values per key nobull@mail.com
    Re: need post/lwp example <billw@dal.asp.ti.com>
    Re: need post/lwp example <billw@dal.asp.ti.com>
    Re: need post/lwp example <billw@dal.asp.ti.com>
    Re: Net::SMTP question yong321@yahoo.com
        Newbie - Read in chunks of data moria6@my-deja.com
        Newbie, do 'prog2.pl' vs. $rc = system("perl prog2.pl") (Charles Wilt)
    Re: Newbie, do 'prog2.pl' vs. $rc = system("perl prog2. <bart.lateur@skynet.be>
        open and show immediatly on the web an html page <star@sonic.net>
        problem with 'do file' jcushma@my-deja.com
    Re: question regarding file locking <pap@sotonians.org.uk>
    Re: question regarding file locking (Tad McClellan)
    Re: qw and delimiter usage <cal@iamcal.com>
        qw'...' throws off Perl parser <bart.lateur@skynet.be>
    Re: Redirect External Program's output on Windows ? undergronk@yahoo.com
    Re: Redirect External Program's output on Windows ? joerg@sql.de
        Req: Traceroute module/script which doesn NOT use Unix  <jbessels@planet.nl>
    Re: running system command as root from perl kmhanser@my-deja.com
        slow learner needs help with splice () <stephen_carpenter@hp.com>
    Re: slow learner needs help with splice () <uri@sysarch.com>
    Re: split NONSENSE <bart.lateur@skynet.be>
    Re: split NONSENSE (Abigail)
        stupid perl question <eprom007@hotmail.com>
    Re: stupid perl question <cal@iamcal.com>
    Re: stupid perl question (Leo Schalkwyk)
    Re: stupid perl question (Tad McClellan)
    Re: this newsgroup newsposter@cthulhu.demon.nl
    Re: utf-8 and perl 5.6.0... (M.J.T. Guy)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 11 Jul 2000 12:30:47 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: How to display the correct time from a time server on a page?
Message-Id: <slrn8mmjv3.am3.abigail@alexandra.delanet.com>

Lou (abcd@abcd.a) wrote on MMDVI September MCMXCIII in
<URL:news:8kf2qd$1kp$2@sunce.iskon.hr>:
++ "Abigail" <abigail@delanet.com> wrote in message
++ news:slrn8mktpk.7v7.abigail@alexandra.delanet.com...
++ >
++ > #!/opt/perl/bin/perl -wT
++ > use strict;
++ > print <<__END__
++ > Content-type: text/plain
++ >
++ > Please look at your watch.
++ > __END__
++ >
++ >
++ > HTH. HAND.
++ 
++ I have been reading yours st*pid answers, and there are more people here
++ like you, your a hacker ha?

Hell, no, I ain't no hacker. I herd goats.

++ If you haven't got an answer to someone question don't reply it.
++ You're just vain little girl in the world. You don't know anything about
++ perl, you just now how to **** people.

Why should I have to know anything about Perl? You posted this in the
javascript group, so Perl would be off-topic there.

++ That's you're job is suppose, that's only thing that you now. Nice culture
++ you have. I hope you're pround of yourself, that's somethin you should be
++ proud of, there isn't many people that knows this like you do.

Oh, I am very proud. I pet myself on my shoulders every day. And twice on
Fridays.

++ You're the best, do you know what for are computers?
++ You're the best, do you know what for are computers? Oh I'am silly how could
++ you know something like that, let me try like this: do you know what for is
++ that box that you have somewhere on a tree, or somewhere where you live.

Of course I know. It serve three purposes. It's a small little table. It's
also a stove to bake eggs on. And finally, it's a device to communicate
with space aliens.



Abigail
-- 
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s};;;
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};                # Perl 5.6.0 broke this...
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))


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

Date: 11 Jul 2000 16:06:19 GMT
From: yhlee@mail.med.upenn.edu (Young H Lee)
Subject: interacting perl w/ nt/dos
Message-Id: <8kfglr$vil$1@netnews.upenn.edu>

Lets say I had perl do:

system ("some_command > something.txt");


how could I access something.txt without using the open command in perl?  
So what I am basically asking (since i dont know DOS [or perl for that 
matter.hehe]) if I could get a system command to go directly to a hash or 
array or etc.. Instead of me making a temporary text file and then 
accessing it. So if I said

system ("net user /domain > userlist.txt");

how would i get the contents of "net user /domain" into say @users.

thanks for any help!

the newbie,

-----
Young H. Lee

"Never try to teach a pig to sing.  It wastes your time and annoys the pig."



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

Date: Tue, 11 Jul 2000 11:09:24 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: interacting perl w/ nt/dos
Message-Id: <396B46B4.F5D712ED@texas.net>

Young H Lee wrote:
> 
> Lets say I had perl do:
> 
> system ("some_command > something.txt");
> 
> how could I access something.txt without using the open command in perl?

The answers to 99% of your Perl questions are as close as your
harddrive.

Read:

perldoc -f system

for the answer to your current question.

Then, learn to fish:

perldoc perldoc
perldoc perl

- Tom


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

Date: Tue, 11 Jul 2000 18:11:45 +0200
From: Marco Natoni <foo@bar.va>
Subject: Re: interacting perl w/ nt/dos
Message-Id: <396B4741.68453AE7@bar.va>

Young,

Young H Lee wrote:
> Lets say I had perl do:
> system ("some_command > something.txt");
> how could I access something.txt without using the open command 
> in perl? So what I am basically asking (since i dont know DOS [or 
> perl for that matter.hehe]) if I could get a system command to 
> go directly to a hash or array or etc.. Instead of me making 
> a temporary text file and then accessing it. 

  FAQ.

  Solution #0: Read the FAQ list;

  Solution #1: Use the backticks;

  Solution #2: Open a pipe with the command (could be a nightmare in 
               a Microsoft environment).


	Best regards,
		Marco


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

Date: 11 Jul 2000 16:40:06 GMT
From: "D.W." <dpalmeNOSPAM@unitedtraffic.com>
Subject: Re: is this possible?
Message-Id: <01bfeb56$3927fce0$cf0114ac@raptor.unitedtraffic.com>

Ok, 
I think I have the idea, but I'm still having a problem with the system
prompting me for the passwords and being able to pass that information to
it from a variable. Any suggestions? I'm not looking for the answer per se
just I wasn't able to find anything in the perdoc file you suggested,
unless I just plainly missed it.

Douglas


Bob Walton <bwalton@rochester.rr.com> wrote in article
<396A18C0.DE27148B@rochester.rr.com>...
> "D.W." wrote:
> > 
> > I need to write a perl script that will act as a CGI that will be used
to
> > update a dbm database used for authentication.
> > 
> > I'm using the linux command dbmmanage /home/etc/passwords/pdbm adduser
> > <username> <password> <password>
> > 
> > Is it possible to write a perl script to automate this?
> > 
> > Douglas
> 
> Sure it's possible -- that kind of stuff is one of the things for which
> Perl is great.  Start with:
> 
>    perldoc perlop
> 
> and look at the section (under "quote and quote-like operators") for the
> "qx" operator.  That will let you run any Linux command from Perl and
> collect the command's standard output in a Perl variable.  Common usage
> of the qx operator is to use the "backticks" form:
> 
>    $output=`linux_command_goes_here`;
> 
> The "backticks" are also known as "grave accents", and are typically
> found on the keyboard key to the left of the "one" key.
> -- 
> Bob Walton
> 


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

Date: 11 Jul 2000 12:32:40 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: multidimensional associative arrays
Message-Id: <slrn8mmk2n.am3.abigail@alexandra.delanet.com>

Philip Rennert (phil.rennert@ioip.com) wrote on MMDVI September MCMXCIII
in <URL:news:396B19AD.904FEF90@ioip.com>:
'' Okay, thanks, but how do you fix the second index ?
'' (Say $a is two-dimensional and I want all elements of the form $a{whatever}{6

You ask a question before the context. Now, I am confused, and cannot
answer.

[Fully quoted articled deleted]


Abigail
-- 
perl  -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
          for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
          print chr 0x$& and q
          qq}*excess********}'


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

Date: 11 Jul 2000 17:52:59 +0100
From: nobull@mail.com
Subject: Re: Multiple values per key
Message-Id: <u9wvis6238.fsf@wcl-l.bham.ac.uk>

deno <jdNOjdSPAM@syncon.ie.invalid> writes:

> tie %h, 'DB_File', 'DN_Status', O_CREAT|O_RDWR, 0640, $DB_HASH
> or die "Cannot open database file: $!\n";

> 	push (@{$h {$dname}}, $mailsent, $sendtime, $response,
> $mailsys, $recv_time );

A tied hash can contain only strings - it can't contain an array ref.

It wouldn't really make sense for it to do so anyhow - what's the
point of storing the address of an in-memory structure in a file?

What are you trying to achieve?

Did you perhaps want to say:

  $h{$dname} = join ( $DELIMITER, $mailsent, $sendtime, $response,
                    $mailsys, $recv_time );
-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 11 Jul 2000 11:02:49 -0500
From: Bill Webster <billw@dal.asp.ti.com>
Subject: Re: need post/lwp example
Message-Id: <396B4529.A4A69844@dal.asp.ti.com>

Malcolm Dew-Jones wrote:

> Bill Webster (billw@dal.asp.ti.com) wrote:
> : Hello folks,
>
> :    My goal is to fill out a form for a given URL which uses the POST
> : method,
> : without the use of a browser.  I understand using LWP is a good way to
> : go.
> : Looking through LWPCOOK, I found:
>
> :         #!/usr/bin/perl
> :          use LWP::UserAgent;
> :          $ua = LWP::UserAgent->new;
>
> :          my $req = HTTP::Request->new(POST =>
> : 'http://www.perl.com/cgi-bin/BugGlimpse');
> :          $req->content_type('application/x-www-form-urlencoded');
> :          $req->content('match=www&errors=0');
>
> :          my $res = $ua->request($req);
> :          print $res->as_string;
>
> :   ...well http://www.perl.com/cgi-bin/BugGlimpse no longer exists, so
> : its hard for me to
> : play with this example.  I would like an example program that will work,
>
> : so I can make
> : sure I'm starting at the right point to debug my program ( which I think
>
> : my problems my name/value pairs...).
>
> :   Can someone send me an example similar to the one above that will
> : work?
>
> I really think you should install your own web server to receive the POST
> data for this sort of testing.  It's not very polite to be sending bogus
> requests to someone elses server when you're developing routines.
>
> You would have the added benefit of being able to check both ends of the
> connection to see what's really happening.
>
> Your URL would be something like
> 'http://localhost/cgi-bin/my_test_cgi.pl'
>
> and my_test_cgi.pl could be as simple as (untested)
>
>         #!/usr/bin/sh
>         echo 'new request received' >> /tmp/my_test_cgi.log
>         date >> /tmp/my_test_cgi.log
>         cat  >> /tmp/my_test_cgi.log
>
> This just dumps the incoming POST data into a log file (make sure its
> writable by the cgi script running account) so you can examine it.  You
> might also want to dump the environment variables.  I forget how, but
> 'printenv', or 'set' probably work.
>
> Windows would be a bit different, but the idea is the same.  Find a
> utility that copies its standard input into a file and run that as the cgi
> script.  Perhaps its as easy as 'TYPE CON >> file 'in a batch file.

  Hi Malcom,

  Thanks for your help.  My little novice-self is slowly catching on.
I started messing with my linux box at home last night not having
much idea of what you meant by, http://localhost.  When I typed
that in my browser - it said "congratulations for having Apache
installed in your Red Hat machine ".  Oh!  I guess my machine can
act just like an apache server.  If you want to give me one more little
nudge, I assume - somehow I can copy the program you wrote above
into the pathway you suggested ( ....cgi-bin/my_test_cgi.pl) which
will reside somewhere on my computer.  I'm sure all this is in the
apache doc - but this is the idea, right?     Then I can use LWP
stuff to try post calls.

  Also, what about specific web pages with forms that use the POST
method out there that I want to access using the LWP.  Is there a
way I can copy their cgi to my computer so that I can practice
my routines?  I'm thinking probably not....since they're accessing their
own huge databases...etc...etc....

Thanks,

Bill Webster (billw@dal.asp.ti.com)




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

Date: Tue, 11 Jul 2000 11:05:54 -0500
From: Bill Webster <billw@dal.asp.ti.com>
Subject: Re: need post/lwp example
Message-Id: <396B45E2.79E322D1@dal.asp.ti.com>

Debjit wrote:

> A couple of of days back I faced the same situation! I pasted the example
> code and it gave bad luck this time. So I posted(well not to usenet) to
> another cgi script residing in a different machine. It succeeded.
> --------------------------- first program(lib-www-test.pl)
> print qq`content-type: text/html
>
> `;
> # Create a user agent object
> use LWP::UserAgent;
> $ua = new LWP::UserAgent;
> $ua->agent("AgentName/0.1 " . $ua->agent);
>
> # Create a request
> my $req = new HTTP::Request POST =>
> 'http://192.168.1.20:8001/oyebin/develop/ad_serving/libtest.pl';
> $req->content_type('application/x-www-form-urlencoded');
> $req->content('fname=Debjit&lname=Mukherjee');
>
> # Pass request to the user agent and get a response back
> my $res = $ua->request($req);
>
> # Check the outcome of the response
> if ($res->is_success) {
>  print $res->content;
>  } else {
>  print "Bad luck this time\n";
> }
>
> ---------libtest.pl-----------------
> use CGI 'param','header';
> use CGI::Carp qw(fatalsToBrowser);
> my $cgi = new CGI;
> print $cgi->header;
> my $fname = $cgi -> param('fname');
> my $lname = $cgi -> param('lname');
> print qq`Hi $fname $lname how are you?`;
> -------------------------------------------------------
>
> and output
> http://127.0.0.1/cgi-bin/lib-www-test.pl
> gives
> Hi Debjit Mukherjee how are you?
> of course you can test in the same server as well.

Thanks for your input, but my browser can't seem to find
http://192.168.1.20:8001/.......

Regards,

Bill




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

Date: Tue, 11 Jul 2000 11:08:13 -0500
From: Bill Webster <billw@dal.asp.ti.com>
Subject: Re: need post/lwp example
Message-Id: <396B466D.422945B3@dal.asp.ti.com>

Ilmari Karonen wrote:

> In article <396A3D30.DEC49AD3@dal.asp.ti.com>, Bill Webster wrote:
> >        #!/usr/bin/perl
> >         use LWP::UserAgent;
> >         $ua = LWP::UserAgent->new;
> >
> >         my $req = HTTP::Request->new(POST => 'http://www.perl.com/cgi-bin/BugGlimpse');
> >         $req->content_type('application/x-www-form-urlencoded');
> >         $req->content('match=www&errors=0');
> >
> >         my $res = $ua->request($req);
> >         print $res->as_string;
> >
> >  ...well http://www.perl.com/cgi-bin/BugGlimpse no longer exists, so
> >its hard for me to play with this example.
>
> Well, just pick any old script.  It'd probably be best for you to run
> your own test script, but you can play with one of mine if you want:
>
>   my $req = HTTP::Request->new(POST => 'http://www.sci.fi/~iltzu/cgi-bin/figlet.pl');
>   $req->content_type('application/x-www-form-urlencoded');
>   $req->content('text=Hello,+world!&font=big');
>
> --
> Ilmari Karonen - http://www.sci.fi/~iltzu/
> "The screwdriver *is* the portable method."  -- Abigail
> Please ignore Godzilla and its pseudonyms - do not feed the troll.

Thanks alot, Illmari,


  I've found it on my browser here at work, and will try it at home
tonight on my linux box.  Just what I was after.  A simple example
to test whether or not I'm in the right ballpark.....


Regards,
Bill







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

Date: Tue, 11 Jul 2000 15:39:33 GMT
From: yong321@yahoo.com
Subject: Re: Net::SMTP question
Message-Id: <8kff3i$nor$1@nnrp1.deja.com>

In article <963304657.28169@itz.pp.sci.fi>,
  Ilmari Karonen <usenet11149@itz.pp.sci.fi> wrote:
> In article <8ke7rf$rgh$1@nnrp1.deja.com>, yong321@yahoo.com wrote:
> >Just found that some email addresses in our database are so wrong
that
> >they're even syntactically incorrect, for example, "test@". I wonder
if
> >my program aborts the loop rather than skips (ignores) these bad
> >addresses.
>
> Don't wonder, check if it does.  And then take a look at the Net::SMTP
> docs, especially the part about "SkipBad"..
>
> --
> Ilmari Karonen - http://www.sci.fi/~iltzu/
> "The screwdriver *is* the portable method."  -- Abigail
> Please ignore Godzilla and its pseudonyms - do not feed the troll.

Ilmari,

I can't find the word "skip", "skipbad", "bad" by case-insensitive
search in the perldoc. (perdoc Net::SMTP | col -b > SMTP.man; vi
SMTP.man). You're not joking, are you? This SkipBad thing is very
interesting to me. Thanks.

--
Yong Huang

(yong321@yahoo.com)


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 11 Jul 2000 17:40:23 GMT
From: moria6@my-deja.com
Subject: Newbie - Read in chunks of data
Message-Id: <8kfm69$900$1@nnrp2.deja.com>

I have a file of hex data that I would like to
read in 4 bytes at a time and perform a hex-->
decimal conversion on.  Then I'd like to write
these decimal numbers out to a file.

When I went to open the file and store it to an
array I discovered that the file is one 18K+
chars long line.  I was hoping to 'while-loop' my
way through that 4 bytes at a time and then write
to an array and subsequently an ASCII file with a
newline char after each decimal number.

I have the 'easy' parts done in knowing how to
open the original file for read, check to see if
the output file exists (if not create it) and
open it for write access.  I also 'think' I know
how to accomplish the hex-->dec conversion.

Any help is greatly appreciated!

Maurie Reed


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 11 Jul 2000 16:13:48 GMT
From: charles.0272@worldnet.no.spam.att.net (Charles Wilt)
Subject: Newbie, do 'prog2.pl' vs. $rc = system("perl prog2.pl")
Message-Id: <MPG.13d51258194b5569989926@netnews.worldnet.att.net>

Ok, I've played around with Perl in the the past but for a recent project 
we brought in some outside help.  We are working with the ActiveState 
port of Perl on Windows NT PC and I'm trying to get a better understand 
of what is being done.

Currently, the project has a lot of calls to Perl programs from other 
Perl programs in the following form

$rc = system("perl prog2.pl");

It seems to me that there should be a better method than going back to 
the OS and starting the perl interpreter again to call a Perl Program 
from another Perl program.  Unless I'm misunderstanding exactly what is 
going on here.

From other posts in this group and from the documentation, I understand 
that the following method would work also

do 'prog2.pl';

Seems to me this is the better way, is this true?  What about the return 
code from prog2.pl?

Lastly, it may matter that prog2.pl could be called from prog1.pl or 
directly from the command line.

Any comments, tips, pointer to man pages appreciated.

Thanks in advance,
Charles Wilt


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

Date: Tue, 11 Jul 2000 18:31:33 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Newbie, do 'prog2.pl' vs. $rc = system("perl prog2.pl")
Message-Id: <jeimms0maj3qegq799bconc59q9a9d73gr@4ax.com>

Charles Wilt wrote:

>Currently, the project has a lot of calls to Perl programs from other 
>Perl programs in the following form
>
>$rc = system("perl prog2.pl");
>
>It seems to me that there should be a better method than going back to 
>the OS and starting the perl interpreter again to call a Perl Program 
>from another Perl program.  Unless I'm misunderstanding exactly what is 
>going on here.

Fair enough.

>From other posts in this group and from the documentation, I understand 
>that the following method would work also
>
>do 'prog2.pl';
>
>Seems to me this is the better way, is this true?

It's in a different league altogether. The second script is run while
sharing all variables with the original script. It may be what you want,
but it may be annoying too, if both scripts use a lot of global
variables then they may end up changing each-other's variables.

>What about the return code from prog2.pl?

Eh? The result of the do statement is the last expression evaluated in
that other script. You should also check $@ to see if something went
wrong.

>Lastly, it may matter that prog2.pl could be called from prog1.pl or 
>directly from the command line.

Try caller(). If run from the command line, caller() will return an
empty list (false), if tested in the main body of the script. It will be
true (a list of 3 items if in list context: package = "main", script
name and line number) if called through do().

-- 
	Bart.


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

Date: Tue, 11 Jul 2000 17:11:44 GMT
From: arthur <star@sonic.net>
Subject: open and show immediatly on the web an html page
Message-Id: <B58FFA7F.33E6%star@sonic.net>

in article slrn8m16p4.bnv.efflandt@efflandt.xnet.com, David Efflandt at
efflandt@xnet.com wrote on 7/3/00 4:56 AM:

> On 2 Jul 2000 21:55:52 -0600, arthur <star@sonic.net> wrote:
> :Good Day,
> :
> :Does anyone know how I can redirect a user to a html page on the web. I want
> :a perl program to open a web page "on the fly" but I do not know how to
> :redirect the user?
> :
> :Thanks,
> :~arthur
> :star@sonic.net
> 
> In Perl:
> 
> print "Location: http://domain/path/file.html\n\n";
> 
> or see redirect in 'perldoc CGI' if using CGI.pm
> 
> The secret is not to print any other headers before this one, or at least
> do not terminate them with a blank line or double newline.  Note:
> terminate the URL with a trailing slash if not referencing a specific file
> (if just a domain or dir).


I could not get the above suggestion to work so I tried moving the document.
That still did not work. Does any of you Pearl experts out there know why
and would be willing to let me know! I commented  out a few attempts that
only led to that dreaded Malformed header error.I can open an html file but
I can not make it open immediatly on the web.



here is the script
--------------------------
#!/usr/bin/perl -w

use CGI qw(:standard);
use IO File;
use strict;
use File::Copy;

print header;



print start_html('A Simple Example'),
    h1('A Simple Example'),
    '<body bgcolor=green><b>Please....fill in the following form, with
questions and answers.</b>
    <p> ',
        hr,
    start_form,
    "What are your questions? ",textfield('question'),
    p,
    "What are your answers? ",textfield('answer'),
    p,
    submit,
    end_form,
    hr;
    
    if (param()) {
    print 
 "Your questions are: ",em(param('question')),
 p,
 "The answers are: ",em(param('answer')),
 p,
    #I opened a file here but I want it to open
    #a page on the web (on the fly) but I can't
    #figure it out-I get that dreaded Malformed header
 open (HOPE, ">dot.html") || die print "cant open:";
print (HOPE "<html>\n<head>\n<title>this is the working copy</title>\n<body
bgcolor=black text=WHITE>\n");
    
print (HOPE (param('$question')));
print (HOPE "\n");
print (HOPE (param('$answer')));
p;
print (HOPE "\n</body>\n</html>");
close HOPE;
    #mv (/nfs/httpd/cgi-bin/star/dat.html /home/www_pages/dat.html);
    #mv dot.html dat.html;
    #move("dat.html" "/home/WWW_pages/star/dot.html") ||
    #    die ("could not move file: $! ");

 hr;


print end_html;

}

------
Thank yoy,
~arthur
star@sonic.net



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

Date: Tue, 11 Jul 2000 17:00:19 GMT
From: jcushma@my-deja.com
Subject: problem with 'do file'
Message-Id: <8kfjr4$7va$1@nnrp2.deja.com>

I am writing a cgi script
(apache/mod_perl/embperl) that reads settings
information from a file:

 $file = 'config.dat';
 do $file or die "Error running $file: ".$@.$!;
 print OUT "Dat file loaded " if $loaded;
 print OUT &testfunc;

 ...where $loaded and &testfunc are defined in
config.dat. The actual work of the script is done
in another function, defined in config.dat,
called &pages. The problem is that more than half
the time, &pages seems to be undefined, and
sometimes $loaded or &testfunc are as well.
Reloading often enough fixes the error, until
next time.

In effect, my declarations seem to fail at
random, one at a time or all together. What could
be happening?

Thanks,
Jack


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 11 Jul 2000 16:38:30 +0000
From: "Paul Taylor" <pap@sotonians.org.uk>
Subject: Re: question regarding file locking
Message-Id: <LeHa5.537$%B1.76842@nnrp4.clara.net>

In article <396B3AFE.98B82302@one.net.au>, Thomas Haenel
<thaenel@one.net.au> wrote:
> Hi, could someone tell me the best way to lock files so that only one
> process at a time can read/write a file. At the moment I'm using a
> simple
> 
> while ( -e "datalock" ) {sleep 1;};
>  system ("touch datalock"); open (OUTFILE, ">$REGISTER_FILE") ||
>  &Fatal_Error("Error_017"); #tell
> user to contact admin
> 
>   $line  = "data";
>   print OUTFILE $line;
>  }
>  close(OUTFILE); system("rm datalock");
> 
> Is there a better way ?
> 
> Thanks, Tom.
> 

Look at :-

perldoc -f flock

Pap.


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

Date: Tue, 11 Jul 2000 12:00:34 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: question regarding file locking
Message-Id: <slrn8mmh52.3mg.tadmc@magna.metronet.com>

On Tue, 11 Jul 2000 23:19:28 +0800, Thomas Haenel <thaenel@one.net.au> wrote:


>could someone tell me the best way to lock files so that only one
>process at a time can read/write a file. 


   perldoc -f flock


   perldoc -q "\block"

      "How can I lock a file?"

      "Why can't I just open(FH, ">file.lock")?"

      "I still don't get locking.  I just want to
       increment the number in the file.  How can I do this?"


>At the moment I'm using a
>simple
>
>while ( -e "datalock" ) {sleep 1;};


You lock files to avoid a "race condition".

You have just *created* a race condition.

This code will NOT protect your data from corruption.


There is more info about file locking in:

   perldoc perlopentut


> system ("touch datalock");


What if the "touch" fails?

Wouldn't you like to know if that happens?

If so, then:

   !system ("touch datalock") || die "problem touching datalock   $!";
   ^                                                              ^^
   ^                                                              ^^


>Is there a better way ?


As your way does not avoid the situation that you are trying do
avoid (i.e. it does not work), just about any "way" would be "better" :-)



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


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

Date: Tue, 11 Jul 2000 16:51:16 +0100
From: "Cal Henderson" <cal@iamcal.com>
Subject: Re: qw and delimiter usage
Message-Id: <NnHa5.11161$_O.187459@news2-win.server.ntlworld.com>

> #!/usr/local/bin/perl
> chomp($i=<STDIN>);
> @words=qw/$i/;
>
> foreach $j (@words)
> {
>         print("\n $j \n");
> }
>
> This fails because 'qw' construct uses '$i' itself as a element in the
> array instead of interpolating it.  Is there any way I can acheive this
> without using regular expressions or 'split'.
> This is one of my perl class assignments. Any help will be appreciated.
> Thanks

qw does not interpolate variables. to avoid using a regex or split,
why not loop through a character at a time?

Cal Henderson





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

Date: Tue, 11 Jul 2000 18:17:03 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: qw'...' throws off Perl parser
Message-Id: <qhhmms8grnuhddib4gpsgs5n7rg8v6e9iq@4ax.com>

For the silly reason that my simple-minded Perl syntax highlighter shows
the string in a nice way, I've grown the habit of using

	qw'this that the-other'

But perl complains about it. Yes, it does work properly, as in:

	@ary = qw'this that the-other';
	$" = ":";
	print "@ary\n";

but if you try something more fancy, like

	@foo{qw'a b c'} = qw'alpha beta gamma';

then I get the complaint (warning only, but extremely anoying)

	Scalar value @foo{qw'a b c'} better written as $foo{qw'a b c'}
	at ...

Oi! This is not a scalar! Stupid Perl!

BTW using Perl 5.6.0, but I've seen this in older Perls too.

p.s. In a way, qw'...' makes sense, because Perl doesn't interpolate
what's between the delimiters. And often, code is allready stuffed with
lots of nested () [] {} so using "'" it stands out a lot better.


-- 
	Bart.


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

Date: Tue, 11 Jul 2000 15:19:16 GMT
From: undergronk@yahoo.com
Subject: Re: Redirect External Program's output on Windows ?
Message-Id: <8kfdsv$mqb$1@nnrp1.deja.com>

In article <8kf6j5$gmr$1@nnrp1.deja.com>,
  joerg@sql.de wrote:
> Dear Perl users,
>
> I ask for hints when porting a Perl program from Unix to Win32:
>
> I need to call external programs that write to their "standard
> output", but I need to keep that text in files.
> I would prefer to include "standard error" with the output.
>
> On Unix, I call "system" with a string parameter that contains
> redirection characters:
>    system "program arg1 arg2 > result"
> or even
>    system "program arg1 arg2 > result 2>&1"
> which does exactly what I want.
<snip.
> What is the best way to achieve the desired effect ?

You could use backticks to capture all the output of the program and
then print that, if you don't mind STDOUT and STDERR mixed together

$output = `someprogram.exe`;
print $output;

Look in the perlop manpage for qx/STRING/ as well (though this may be
of limited use under NT)

> AFAIK, "cmd" does support redirection of standard output;
> "zsh" definitely does (and it works when using the command line).

Command redirection works under NT for native programs (like dir or
findstr) but not for Perl.

HTH
Scott Kirk



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 11 Jul 2000 15:22:59 GMT
From: joerg@sql.de
Subject: Re: Redirect External Program's output on Windows ?
Message-Id: <8kfe3s$mtl$1@nnrp1.deja.com>

Dear Perl users,

In article <8kf6db$glc$1@nnrp1.deja.com>,
  joerg@sql.de (= I myself) wrote:
> [...]
>
> I post via Deja [...]

Please excuse it appearing four times - I had connection problems
and could not see the first try had already succeeded, so the
"Reload" button had this very bad effect.

Still hoping for your tips,
Joerg Bruehe

--
Joerg Bruehe, SQL Datenbanksysteme GmbH, Berlin, Germany
     (speaking only for himself)
mailto: joerg@sql.de


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 11 Jul 2000 18:42:37 +0200
From: Jan Bessels <jbessels@planet.nl>
Subject: Req: Traceroute module/script which doesn NOT use Unix traceroute
Message-Id: <396B4E7D.E6628980@planet.nl>

I'm looking for a traceroute script written entirily in Perl. In my
search on the web, CPAn and dejanews so far I found the Net::Traceroute
module and a script on http://quake.skif.net/RawIP/. The former uses the
standard Unix traceroute prog (not installed) and the latter uses its
own RawIP module. Because I don't want the install more modules then
abs. necessary on the machines of my employee (ISP). Script will be
called using mod_perl.  I'm looking for a module or script which
preferable uses relatively standard modules like Sockets or the Net::
modules. These are intalled. Anyone any hints/tips of where to look. It
seems most suites like webtools use standard Unix progs, not nice....

Jan Bessels
-----------



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

Date: Tue, 11 Jul 2000 15:34:20 GMT
From: kmhanser@my-deja.com
Subject: Re: running system command as root from perl
Message-Id: <8kfepr$ndb$1@nnrp1.deja.com>

Okay, now I've got a killhttpd file:
-r-sr-x---    1 root     www            60 Jul 11 11:24 killhttpd
which looks like this:

#!/bin/sh
kill -USR1 `cat /usr/local/apache/logs/httpd.pid`

However, when I run this program as www, it tells me:
kill: (2476) - Not owner

If I run as root, it works (obviously).


In article <brian-ya02408000R1007002308000001@news.panix.com>,
  brian@smithrenaud.com (brian d foy) wrote:
> In article <8ke1rg$nf7$1@nnrp1.deja.com>, ynotssor@my-deja.com posted:
>
> > The killhttpd program is a trivial script:
> >
> > #!/bin/sh
> > kill -HUP `ps -aef | grep httpd | grep -v grep | awk '{print $2}'`
>
> that won't work for many reasons, and it's just dumb.  if you had
> read the apache docs, you would have discovered that you want the
> USR1 signal and the PID file.
>
> kill -USR1 `cat /etc/httpd.pid`
>
> --
> brian d foy
> CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
> Perl Mongers <URL:http://www.perl.org/>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 11 Jul 2000 10:02:56 -0700
From: Stephen Carpenter <stephen_carpenter@hp.com>
Subject: slow learner needs help with splice ()
Message-Id: <396B5340.89E05CF4@hp.com>

Hello,

    I am using ActiveState Perl build 522 on Windows 2000. Anyway, I am
slowly learning Perl but I am having problems with the splice function.
My book, Programming Perl 2nd Edition, says on page 198 about pop that I
should use splice to pop multiple elements of an array. On page 219 I
read about splice, but I guess I am too slow on the uptake. What I am
trying to do is something like this:

@x = "aa","bb","cc","dd";
$x, $y, $z = splice (@x, 0, 3);

to get the first three elements. The book says that splice returns the
elements removed from the array, but I just can't seem to figure it out.

StephenC.
PS. I don't know C either, so please don't tell me it is just like C.



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

Date: Tue, 11 Jul 2000 17:14:23 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: slow learner needs help with splice ()
Message-Id: <x7zonolhci.fsf@home.sysarch.com>

>>>>> "SC" == Stephen Carpenter <stephen_carpenter@hp.com> writes:

  SC> @x = "aa","bb","cc","dd";
  SC> $x, $y, $z = splice (@x, 0, 3);

  SC> to get the first three elements. The book says that splice returns
  SC> the elements removed from the array, but I just can't seem to
  SC> figure it out.

well, you have the splice part correct. but the assignment is wrong. you
are assigning a list of values (the splice results) to $z.

that line is really the same as:

	$x; $y; $z = splice (@x, 0, 3);

as the comma operator just separates expressions. you need a list of
vars to assign to which is the same thing but inside parens:

	($x, $y, $z) = splice (@x, 0, 3);

read perldata for more on this.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 11 Jul 2000 17:52:09 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: split NONSENSE
Message-Id: <begmms0m1lrckdfvrm2063av46lg1dq9ss@4ax.com>

Abigail wrote:

>-- 	$\ = "\n"; $, = "\t";
>-- 	for my $i (0 .. 5) {
>-- 	    $_ = ':' x $i;
>-- 	    my @a = split /:/, $_, -1;
>-- 	   print $i, scalar @a;
>-- 	}
>-- -->
>-- 	0	0
>-- 	1	2
>-- 	2	3
>-- 	3	4
>-- 	4	5
>-- 	5	6
>--
>-- There is no way to make split() return a list of one item, if the string
>-- parts are empty strings.
>
>
>Sure there is.
>
>    @a = split /:/ => ":", 1;
>    print scalar @a;
>    __END__
>    1

I ment using -1 as a third parameter.

With ":" as string, you have two emtpy strings separated by a colon. But
a string consisting of one empty element, is a concept that split()
isn't familiar with.

This is the kludge I ended up using:

	@items  = split /:/, "$_:", -1;
	pop @items;

-- 
	Bart.


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

Date: 11 Jul 2000 13:54:37 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: split NONSENSE
Message-Id: <slrn8mmosa.am3.abigail@alexandra.delanet.com>

Bart Lateur (bart.lateur@skynet.be) wrote on MMDVI September MCMXCIII in
<URL:news:begmms0m1lrckdfvrm2063av46lg1dq9ss@4ax.com>:
() Abigail wrote:
() 
() >-- 	$\ = "\n"; $, = "\t";
() >-- 	for my $i (0 .. 5) {
() >-- 	    $_ = ':' x $i;
() >-- 	    my @a = split /:/, $_, -1;
() >-- 	   print $i, scalar @a;
() >-- 	}
() >-- -->
() >-- 	0	0
() >-- 	1	2
() >-- 	2	3
() >-- 	3	4
() >-- 	4	5
() >-- 	5	6
() >--
() >-- There is no way to make split() return a list of one item, if the string
() >-- parts are empty strings.
() >
() >
() >Sure there is.
() >
() >    @a = split /:/ => ":", 1;
() >    print scalar @a;
() >    __END__
() >    1
() 
() I ment using -1 as a third parameter.

*shrug*. Supposed "split /:/, "", -1" returned a list of a single empty
string. Then someone would ask "there's no way to have split return an
empty list with -1 as a third parameter".

() With ":" as string, you have two emtpy strings separated by a colon. But
() a string consisting of one empty element, is a concept that split()
() isn't familiar with.

It's an arbitrary choice. Sometimes you want it to return 0 elements,
sometimes 1. You can't do both.

() This is the kludge I ended up using:
() 
() 	@items  = split /:/, "$_:", -1;
() 	pop @items;

Why not just:
        @items = split /:/ => $_, -1;
        @items = ("") unless @items?

Or in one line:
        @items = split (?:? => $_, -1) ? @_ : ("");


The latter of course distroys your @_, and despite the use of ?:? indicating
you really want to split into @_, it still gives a warning of implicit split
to @_.



Abigail
-- 
perl -Mstrict -we '$_ = "goto M.print chop;\n=rekcaH lreP rehtona tsuJ";M1:eval'


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

Date: Tue, 11 Jul 2000 00:05:10 -0400
From: EPROM <eprom007@hotmail.com>
Subject: stupid perl question
Message-Id: <396A9CF6.D3317900@hotmail.com>

ok...

this should be simple:

what is the equivelent of the shell command `ls` in Perl?

I've tried opendir( )

such as:

% ls
total 23
drwx--x--x     9 eprom  guest     512 Jul 11 11:54 .
drwxr-xr-x  7406 root   wheel  121344 Jul  6 22:29 ..
drwxr-xr-x     2 eprom  guest     512 Jul 11 11:55 .cfdir
-rw-------     1 eprom  guest     300 Jul  7 13:56 .cshrc
drwx------     2 eprom  guest     512 Mar 15  1999 .elm
-rwxr-xr-x     1 eprom  guest      44 Jul 10 13:15 .forward
%


oh..and no I haven't read the man pages...but I did get the
book "learning perl" (the llama book) and its clear as mud.

Thanks,





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

Date: Tue, 11 Jul 2000 17:04:22 +0100
From: "Cal Henderson" <cal@iamcal.com>
Subject: Re: stupid perl question
Message-Id: <3AHa5.11180$_O.187697@news2-win.server.ntlworld.com>

"EPROM" <eprom007@hotmail.com> wrote...
> ok...
>
> this should be simple:
>
> what is the equivelent of the shell command `ls` in Perl?
>
> I've tried opendir( )
>
> such as:
>
> % ls
> total 23
> drwx--x--x     9 eprom  guest     512 Jul 11 11:54 .
> drwxr-xr-x  7406 root   wheel  121344 Jul  6 22:29 ..
> drwxr-xr-x     2 eprom  guest     512 Jul 11 11:55 .cfdir
> -rw-------     1 eprom  guest     300 Jul  7 13:56 .cshrc
> drwx------     2 eprom  guest     512 Mar 15  1999 .elm
> -rwxr-xr-x     1 eprom  guest      44 Jul 10 13:15 .forward
> %
>
>
> oh..and no I haven't read the man pages...but I did get the
> book "learning perl" (the llama book) and its clear as mud.
>
> Thanks,

read up on opendir, readdir and closedir

Cal Henderson




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

Date: 11 Jul 2000 16:32:11 GMT
From: L.Schalkwyk@z138-234.iop.kcl.ac.uk (Leo Schalkwyk)
Subject: Re: stupid perl question
Message-Id: <slrn8mmj4f.3vu82vr.L.Schalkwyk@leoschalkwyk.iop.kcl.ac.uk>

On Tue, 11 Jul 2000 00:05:10 -0400, EPROM <eprom007@hotmail.com> wrote:
>
>this should be simple:
>
>what is the equivelent of the shell command `ls` in Perl?
>
>I've tried opendir( )
>
well you seem to have ls aliased to 'ls -l', but the simplest
ls behaviour is easy to get with a glob:

perl -le'$,="\n";print<*>'

>
>

Leo

-- 



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

Date: Tue, 11 Jul 2000 11:53:15 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: stupid perl question
Message-Id: <slrn8mmgnb.3mg.tadmc@magna.metronet.com>

On Tue, 11 Jul 2000 00:05:10 -0400, EPROM <eprom007@hotmail.com> wrote:

>what is the equivelent of the shell command `ls` in Perl?


I would start by looking the the Perl Power Tools project's
implementation of 'ls':


   http://language.perl.com/ppt/src/ls/index.html




>oh..and no I haven't read the man pages


Then do not post here.

This in not a man page reading service.


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


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

Date: 11 Jul 2000 16:09:25 GMT
From: newsposter@cthulhu.demon.nl
Subject: Re: this newsgroup
Message-Id: <8kfgrl$lmp$1@internal-news.uu.net>

Juergen Pfann <Juergen.pfann@t-online.de> wrote:
> Abigail wrote:
>> 
>> Day (reui@fdd.ff) wrote on MMDV September MCMXCIII in
>> <URL:news:8kdm15$iho$9@sunce.iskon.hr>:
>> ,,
>> ,, What for exactly is this news group?
>> 
>> To discuss the effect of broken beaks on the sexlife of woodpeckers.

> I thought we're talking about camels here...
> One never ends learning. 

After the woodpeckers finished killing all trees the camels will
have more desert habitat. Until then discussions about camels
should take place in the .deforested group.

Erik



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

Date: 11 Jul 2000 15:32:37 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: utf-8 and perl 5.6.0...
Message-Id: <8kfeml$kbf$1@pegasus.csx.cam.ac.uk>

Joel SEGUILLON  <Joel.Seguillon@uhb.fr> wrote:
>    Hi,
>  I have many problems to translate beetween ISO-Latin1 and utf-8.
>I tried to use the tr /UC and tr /CU operator but i had the error  :
>Malformed UTF-8 character at utf82.pl line 19 for the instruction
>tr/\0-\xff//CU;
>Furthermore the tr operator seems to be deprecated...
>Can someone give me tips and examples ?

The utf8 support for tr() is very broken in perl5.6.0.   Wait for
perl5.6.1.

And not that tr /UC and tr/CU  have been suppressed in perl5.6.1 .


Mike Guy


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3622
**************************************


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