[6993] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 619 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 16 18:07:23 1997

Date: Mon, 16 Jun 97 15:03:00 -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           Mon, 16 Jun 1997     Volume: 8 Number: 619

Today's topics:
     problem with a database script. <metalhead@mhv.net>
     Re: Reading Cookies <xrcc0494@dcaca037.ca.boeing.com>
     Re: Regex lookahead help (Pythagoras Watson)
     Re: regexp needed <ajohnson@gpu.srv.ualberta.ca>
     Re: Removing spaces (Sylvain Robitaille)
     Re: request: "goto" perl script <perlprogrammer@hotmail.com>
     Re: RFD: comp.lang.perl reorganization <heading_anthony@jpmorgan.com>
     Re: RFD: comp.lang.perl reorganization (Mark Bainter)
     Re: run-time eval efficiency question (Kjetil Skotheim)
     Search & Replace Multiple Lines <dralph01@shadow.net>
     Re: Search & Replace Multiple Lines <rootbeer@teleport.com>
     Time comparisons <cmt@ucla.edu>
     Re: Un-taint a variable how? <rootbeer@teleport.com>
     Re: What is wrong with this? <rootbeer@teleport.com>
     what would cause an eval to halt the entir program? (Keith Kwiatek)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Jun 1997 23:31:00 -0700
From: James Esler <metalhead@mhv.net>
Subject: problem with a database script.
Message-Id: <339F97A4.6BBF@mhv.net>

I have recently written a CGI script in Perl which is designed to take
information from an HTML form and place it into a DBM database file. 
The form is processed correctly by my Perl CGI library and the array I
used to reference the DBM receives the info properly.  But when I go to
the UNIX command prompt to access the DBM, nothing appears on the
screen.  I believe the DBM has the information, but is not displaying
it.  Does anyone know why this may be happening?


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

Date: Thu, 12 Jun 1997 23:30:51 GMT
From: "robert c. combs" <xrcc0494@dcaca037.ca.boeing.com>
Subject: Re: Reading Cookies
Message-Id: <33A086AB.5381@dcaca037.ca.boeing.com>

> 
> I'm trying to create a CGI script which, among other things, reads
> cookies.  I came across the following shell script on the Netscape site:
> 
> >#! /bin/sh
> >
> >echo "Content-type: text/html"
> >echo ""
> >echo "Here is your cookie (munch munch):<P>"
> >echo "$HTTP_COOKIE<P>"
> 
> It works fine as shell, but my perl equivilant ignores the $HTTP_COOKIE
> 
> >#!/usr/bin/perl
> >
> >print "Content-type: text/html\n\n";
> >print "Here is your cookie (munch munch):<P>\n";
> >print "$HTTP_COOKIE<P>\n";
> 
> Any ideas on how to read cookies?  Please send email.
> 
> Mark

Try:

 print "$ENV{HTTP_COOKIE}";

or 
 use Env qw(HTTP_COOKIE);
 ...
 print "$HTTP_COOKIE";

the problem is that the perl script thinks that $HTTP_COOKIE is a local
variable. You need to explicitly tell it that it is an Environment
variable.

-bob


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

Date: 16 Jun 1997 21:18:59 GMT
From: py@ecst.csuchico.edu (Pythagoras Watson)
Subject: Re: Regex lookahead help
Message-Id: <5o4ak3$f4d@charnel.ecst.csuchico.edu>

I am following up to Abigail's post, since the original hasn't made it to
my site yet.

According to Abigail <abigail@fnx.com>:
:On 30 May 1997 17:16:00 GMT, Jeff Stampes (stampes@xilinx.com) wrote in
:comp.lang.perl.misc
:<URL: news:5mn20g$mcq$1@neocad.com>:
:++ so here's the problem.  I have some strings that are in the form
:++ 'data/foo/bar/not.this'  I want to NOT match these strings.  
:++ However, the regex needs to be plugged into a positive assertion
:++ match.  There could be anywhere from 3-6 levels before the 
:++ 'not.this'.    
:++ 
:++ I was hoping to use a negative lookahead, but can't seem to find
:++ something that works.  For example:
:++ 
:++ m{(.+/)+(?!not.this)}
 
Note that the second '+' is unnecessary, since the '.+' will happily
consume slashes.

:++ this may work, but it also results in a non-match for
:++ 'data/foo/bar/this'.  

As Abagail's post pointed out, it certainly does match (at least with perl
5.003).  Your problem is that it matches too much, i.e. it will match:
  data/foo/bar/not.this
since "data/foo/" is not followed by "not.this".  Something like the
following might work for you, but it is hard to say without knowing more
about what exactly it is you don't want to match:

#!/usr/local/bin/perl -w

# my $regex = '(.+/)+(?!not.this)';            # Yours
my $regex = '([^/]+/)+(?!([^/]+/)*not.this)';  # Mine
while(<DATA>){
  chomp;
  print "$_:    \t";
  if (/$regex/) {
    print "Match: [$1]\n";
  }
  else {
    print "No match\n";
  }
}

__DATA__
data/foo/bar/not.this
data/foo/bar/but.this
matchme/foo/bar//not.this
matchme/not_this/hithere
data/foo/bar/not_this
datafoobar/not.this
datafoo/bar/not.this

-- 
Py -- 3.141592653589793238462643383279502884197169399375105...
Pythagoras Watson -- "Live long and may all your kernels pop."
INET: py@ecst.csuchico.edu ============ COMPUSERVE: 72162,2676


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

Date: Thu, 12 Jun 1997 13:05:03 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: regexp needed
Message-Id: <33A03A4F.2E245A5B@gpu.srv.ualberta.ca>

! webadmin wrote:
! >
! > Hi
! >
! > I have the following line
! >
! > www.domain.co.uk,   19.87  6.03       253526      153 | /
! >
! > I need to split it. the thing is that I have several lines, but the
no.
! > of spaces in between the elements variies, so I can't have a fixed
! > split. The number I am interested in getting is the one before the
pipe
! > symbol.
! >
! > How can i get this.
! >
! > Iqbal
! 
! Two options spring to my novice mind:
! 
! 1. You can use a regexp along the lines of:
!   /^\s*\S+\s+\S+\s+\S+\s+\S+\s+(\S+)\s+\|\s+\/\s*$/
!   This is assuming the number of items and general layout of the line
is
!   the same each time.

if the number is the only one followed by a space (perhaps
optionally many) and a pipe then;

$_="www.domain.co.uk,   19.87  6.03       253526      153 |/";
/(\d+)\s*\|/;
print $1;

 
! or
! 
! 2. You can actually split on a regexp, so the following would work:
!   split( /\s+/, $dataline )

this one's better as you have all the fields available
in your array if needed---assuming there is always the same
number of fields and your number of interest is always in the
same position.

$_="www.domain.co.uk,   19.87  6.03       253526      153 |/";
@array=split /\s+/;
print $array[4];

regards
andrew


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

Date: 13 Jun 1997 17:51:54 GMT
From: sp_robi@alcor.concordia.ca (Sylvain Robitaille)
Subject: Re: Removing spaces
Message-Id: <slrn5q325n.36a.sp_robi@Elvira.home>

On Thu, 12 Jun 1997 10:14:18 -0500, Robert Saunders <robert@duey.iminet.com>
wrote:

>I have a record that I wish to remove 4 leading spaces from, here is a
>example of the record
>
>This|donuts|    apples||||
>
>I need to remove the spaces from the apples area.. What would be the
>best and correct way of doing this in perl. I am using Perl 5.x ...

Whether this would be the "best" way, I'll leave open for discussion. The
simplest way I can think of would be:

$record =~ s/\s//;

This will substitute any whitespace in the record with null, (effectively
removing the spaces).

Hope that helps...

-- 
----------------------------------------------------------------------
Sylvain Robitaille                          sp_robi@alcor.concordia.ca

Assistant to the System Manager
Computing Services Department
Concordia University                          Montreal, Quebec, Canada
----------------------------------------------------------------------


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

Date: Sat, 14 Jun 1997 03:49:35 -0700
From: perl guy <perlprogrammer@hotmail.com>
Subject: Re: request: "goto" perl script
Message-Id: <33A2773F.5A16@hotmail.com>

Larry D'Anna wrote:
> 
> Empire Net wrote:
> 
> > Does anyone have a perl script that will allow me to use a drop down
> > box
> > and a "go" button to travel to another page??
> > Please post it if you do, or point me to a link.
> >
> > Thanks in advance,
> > --Robert
> 
> This is a javaScript question.
> 
> --
> Larry D'Anna
> javaGuy

Why even use java?. that is an HTML question... can't get more simple
then that.. :o)


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

Date: 13 Jun 1997 04:25:17 -0700
From: Anthony Heading <heading_anthony@jpmorgan.com>
Subject: Re: RFD: comp.lang.perl reorganization
Message-Id: <s4vwwnyiw2q.fsf@et-sun4.uk.jpmorgan.com>

deckers@man.ac.uk (A. Deckers) writes:
> All discussion of this proposal should be posted to news.groups.

Hmm.  Never followed up to one of these before.  The follow-up line
seems to be directed to clpm, and I seem unable to post to
news.groups.  Oh well.  Hope this gets through somehow...


> CHARTER: comp.lang.perl.data-structure
> Submission address: clp-data@perl.com

> CHARTER: comp.lang.perl.inter-process
> Submission address: clp-interprocess@perl.com

There's a lack of consistency between the newsgroup and the submission
address, which seems pointless.  Further, the names are long-winded
and out of kilter with the de-facto general convention for newsgroups of
using short unambiguous abbreviations which don't require one to remember
punctuation conventions.

More specifically, an example of an alternative...

The manual pages already provide a subdivision of language topics, and
it's not unreasonable IMHO to expect people posting questions about
inter-process communication to at least be aware of the perlipc manual
page/pod documentation.  So what is wrong with comp.lang.perl.ipc?


-- 
Anthony J.R. Heading    J.P. Morgan Securities Ltd, London
Email: heading_anthony@jpmorgan.com  Tel: +44 171 325 5962


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

Date: Fri, 13 Jun 1997 18:29:08 GMT
From: mark@michiana.net (Mark Bainter)
Subject: Re: RFD: comp.lang.perl reorganization
Message-Id: <33a3914a.151593279@news.michiana.net>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


 --Quoted Message--

On 13 Jun 1997 04:25:17 -0700, Anthony Heading
<heading_anthony@jpmorgan.com>
wrote:

>deckers@man.ac.uk (A. Deckers) writes:
>All discussion of this proposal should be posted to news.groups.

Hmm.  Never followed up to one of these before.  The follow-up line
seems to be directed to clpm, and I seem unable to post to
news.groups.  Oh well.  Hope this gets through somehow...
>
>
>> CHARTER: comp.lang.perl.data-structure
>> Submission address: clp-data@perl.com
>
>> CHARTER: comp.lang.perl.inter-process
>> Submission address: clp-interprocess@perl.com
>
There's a lack of consistency between the newsgroup and the submission
address, which seems pointless.  Further, the names are long-winded
and out of kilter with the de-facto general convention for newsgroups
of using
short unambiguous abbreviations which don't require one to remember
punctuation conventions.
>
More specifically, an example of an alternative...
>
The manual pages already provide a subdivision of language topics, and
it's not unreasonable IMHO to expect people posting questions about
inter-process communication to at least be aware of the perlipc manual
page/pod documentation.  So what is wrong with comp.lang.perl.ipc?

>
 -- 
Anthony J.R. Heading    J.P. Morgan Securities Ltd, London
Email: heading_anthony@jpmorgan.com  Tel: +44 171 325 5962

 --End Quoted Message--

I agree.  I like the proposal overall, but I like his suggestion for
the name
of the newsgroups, as opposed to those originally suggested.

__
Mark A. Bainter          MCP, A+
Technical Engineer    mailto:mark@turnergroup.com
Turner Group          WWW: http://www.turnergroup.com
Key Print: CF87 F5AA 26AB 9FA2 BBF3  90D0 0DD1 D14C B2DF AD43


-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBM6GtSA3R0Uyy361DEQJLqgCg5UoEDxn0aveKum6sgVTKr6+2jTQAn1tQ
R6biHEc7trqfNzSwJLNY69cq
=ABLg
-----END PGP SIGNATURE-----



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

Date: 13 Jun 1997 14:43:36 GMT
From: kjetil.skotheim@usit.uio.no (Kjetil Skotheim)
Subject: Re: run-time eval efficiency question
Message-Id: <5nrmao$plt$2@ratatosk.uio.no>

In article <33A06E0F.452F@calarts.edu>, web@calarts.edu says...
>
>Does anyone know just how intelligent perl is about not recompiling code
>passed to an eval function when that code doesn't need to be
>recompiled?  e.g. I know that in
>
>foreach (1..10) { eval 'print "Hello!";'; }
>
>the 'print "Hello!";' gets compiled at runtime; but does it get compiled
>once at runtime, or does it get compiled ten times?  What about:
>
>foreach (1..10) { eval $some_code; }
>
>Since $some_code is never modified in the loop

How can perl know if the code in $some_code does not modify $some_code?
Perl would have to analyze the code to determine that...which cant be
done always I think.



, Perl _could_ compile it
>just once -- but does it?  What about:
>
>$f1 = sub { eval $some_code; }
>foreach (1..10) { &$f1; }
>
>or
>
>$f1 = eval "return sub { $some_code }";
>foreach (1..10) { &$f1; }
>
>?  
>
>Let me explain why I'm asking:  I'm currently working on a script to
>search a database file according to various user-defined criteria.
>(Needless to say, these criteria are not known until runtime.) The
<stuff deleted>

Why dont you include the loop-code in the eval string/code?

That is:

eval("for (1..1000) { $some_code }");

Instead of:

for (1..1000) { eval($some_code); }


--
ks

















































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

Date: Wed, 11 Jun 1997 20:35:38 -0400
From: David <dralph01@shadow.net>
Subject: Search & Replace Multiple Lines
Message-Id: <339F445A.2897@shadow.net>

Can someone tell me how to search and replace a string that spans
multiple lines?  I have been trying to do this for the last two weeks.

Thanks,

David Ralph


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

Date: Sat, 14 Jun 1997 08:09:10 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: David <dralph01@shadow.net>
Subject: Re: Search & Replace Multiple Lines
Message-Id: <Pine.GSO.3.96.970614080621.4940Q-100000@kelly.teleport.com>

On Wed, 11 Jun 1997, David wrote:

> Can someone tell me how to search and replace a string that spans
> multiple lines?  

Set $/ to a value allowing you to slurp paragraphs or the whole file, then
use /m (and maybe /s) as needed in your pattern matching. See perlvar and
perlop. Hope this helps! 

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 12 Jun 1997 20:41:56 GMT
From: "Chris " <cmt@ucla.edu>
Subject: Time comparisons
Message-Id: <01bc7770$8b93e820$ce1543a4@LEIBNIZ>

I've been writing a Perl script which extracts certain data from log files.
One of the issues I need to deal with concerns arithmetic manipulations of
time. That is, determining the difference between two or mor time stamps,
averaging time stamps, etc. For example, I have a couple of times (in an
hour:minute:second:hundreth of of sec. format):
12:10:14:60		
13:20:19:80

Now, I want a formula which will allow me to calculate time differences
between time stamps such as above. What I've been doing is a) multiply the
hour by
3600 b) multiply minutes by 60 c) add the them all together (including the
seconds as is) and do modulo division to get the difference. Does that
sound correct? Also: how do I deal with the hundreth of a second? My second
question: suppose I have two sets of timestamps such as above, e.g.:
12:10:14:60		
13:20:19:80
  and
11:09:13:30
13:12:45:90

How would one determine the average difference? By converting  all
timestamps into minutes, adding them together, then dividing by 2? How
would you deal with the remainder. From browsing the newsgroup I've seen
mention of Date manipulation functions, are there similiar functions or
modules for time manipulation which can be used for my tasks.Thanks for any
help

Chris


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

Date: Sat, 14 Jun 1997 08:28:45 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Tung-chiang Yang <tcyang@netcom.com>
Subject: Re: Un-taint a variable how?
Message-Id: <Pine.GSO.3.96.970614082626.4940T-100000@kelly.teleport.com>

On Thu, 12 Jun 1997, Tung-chiang Yang wrote:

> Pass it through a matching pattern like ($var = $1 if /(.*)/, though
> you have to guarantee it is really untainted after that.

That's a suboptimal way to do it since, as you point out, you have to do
another test. And besides, your pattern match will allow any bad data to
get through! The methods in perlsec(1) are better. Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 14 Jun 1997 08:05:05 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Shimpei Yamashita <shimpei@socrates.caltech.edu>
Subject: Re: What is wrong with this?
Message-Id: <Pine.GSO.3.96.970614080305.4940P-100000@kelly.teleport.com>

On 13 Jun 1997, Shimpei Yamashita wrote:

> Tom Phoenix  <rootbeer@teleport.com> writes:
> >    $file = '/mnt/web/guide/mav/nc/dvdepot/emails.txt';
> >    open FILE, ">> $file" or
>                 ^^^^^^^^^^
> >	die "Can't open '$file' for append: $!";
> 
> Wow. I did not know about this leading/trailing whitespace stripping
> business until I saw this post and RTFManpage'ed. Just out of curiosity,
> what is the rationale behind this design decision (aside from "who needs
> leading whitespaces in files anyway?")? Is it just for readability?

Isn't readability reason enough? :-)  (But people who haven't already read
it should see the perlfunc(1) section for open(), which has a note on how
to open files with leading whitespace and other weird characters.) 

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 13 Jun 1997 17:53:21 -0400
From: kkwiatek@nova.umuc.edu (Keith Kwiatek)
Subject: what would cause an eval to halt the entir program?
Message-Id: <5nsfgh$j0o@nova.umuc.edu>



For what reasons would this statement cause the
entire program to halt , without putting anything in
 the $@..............?

$myvar = '$secondvar = 10;'
eval ($myvar);
print $secondvar;


Please post/email me !

kkwiatek@nova.umd.edu 


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

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

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