[17357] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4779 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 31 18:15:53 2000

Date: Tue, 31 Oct 2000 15:15:36 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973034136-v9-i4779@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 31 Oct 2000     Volume: 9 Number: 4779

Today's topics:
    Re: pop: strange results and errors (Mark-Jason Dominus)
        regexp substitution help needed <Aidan.Finn@ucd.ie>
    Re: regexp substitution help needed (Mark-Jason Dominus)
    Re: regexp substitution help needed <Aidan.Finn@ucd.ie>
        regular expression <emerado@wpi.edu>
    Re: regular expression (Clay Irving)
    Re: regular expression <adamf@box43.gnet.pl>
    Re: Session or Sessionless? (Ameen Dausha)
    Re: Session or Sessionless? (Ameen Dausha)
    Re: Session or Sessionless? (Richard J. Rauenzahn)
        Shrinking a DBM file <quantum_mechanic@my-deja.com>
    Re: Socket not autoflush-ing? ActiveState 618 on NT <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: Unterminated <> operator? what the heck? <ianb@ot.com.au>
    Re: using regex to insert data <lr@hpl.hp.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 31 Oct 2000 20:24:40 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: pop: strange results and errors
Message-Id: <39ff2a88.338c$b6@news.op.net>
Keywords: betatron, graft, puck, tubular

In article <39FF09B7.8FE350FC@bt.com>,  <mark.c.hamlin@bt.com> wrote:
>I've learnt the hard way that it
>only shrinks the array if you use pop in an assignment.  

Definitely not true.

>The problem now
>is it seems to be zappin the hole array.  What I see now just doesn't
>make sense, If I skip the story and just give you the impossible bit

Oops you didn't show the code.  How can anyone explain what is wrong
with your code when you didn't show it?

>I know I'm doing something fundamentally silly!!!!

Yeah, too bad you didn't show us what it was!



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

Date: Tue, 31 Oct 2000 20:32:54 -0000
From: "Aidan" <Aidan.Finn@ucd.ie>
Subject: regexp substitution help needed
Message-Id: <newscache$mutw2g$eva$1@weblab.ucd.ie>


Hi,
I'm new to perl and I'm writing a script that processes html files that have
had the tags replaced by the word TAG.
i.e <title> My Page </title> becomes TAG My Page TAG.
I need to replace all the text words in the file with another tag.
e.g. TAG TEXT TEXT TAG
I've found some ways of doing this that dont always succeed so I'm looking
for a simple substitution that will do this.

s/[\w'-]+/ TEXT /gis;
will substitute TEXT for all words including TAG;
Can I get this to substitute all words in the text except for the word TAG.

Thanks to anybody who can help.






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

Date: Tue, 31 Oct 2000 20:35:40 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: regexp substitution help needed
Message-Id: <39ff2d1b.33c0$15e@news.op.net>

In article <newscache$mutw2g$eva$1@weblab.ucd.ie>,
Aidan <Aidan.Finn@ucd.ie> wrote:
>s/[\w'-]+/ TEXT /gis;
>will substitute TEXT for all words including TAG;
>Can I get this to substitute all words in the text except for the word TAG.

I suggest

        s{[\w'-]+}{($& eq 'TAG') ? 'TAG' : 'TEXT'}gise;

Note the 'e' on the end.  It says that the substitution replacement,
which is normally a plain string, is instead a piece of Perl code to
be executed.  Here we ask if $&, the string you matched, is equal to
TAG; if so, we replace it with 'TAG', and if not, with 'TEXT'.



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

Date: Tue, 31 Oct 2000 22:03:56 -0000
From: "Aidan" <Aidan.Finn@ucd.ie>
Subject: Re: regexp substitution help needed
Message-Id: <newscache$d2yw2g$2dc$1@weblab.ucd.ie>



That does the job nicely, thanks for the help.

"Mark-Jason Dominus" <mjd@plover.com> wrote in message
news:39ff2d1b.33c0$15e@news.op.net...
> In article <newscache$mutw2g$eva$1@weblab.ucd.ie>,
> Aidan <Aidan.Finn@ucd.ie> wrote:
> >s/[\w'-]+/ TEXT /gis;
> >will substitute TEXT for all words including TAG;
> >Can I get this to substitute all words in the text except for the word
TAG.
>
> I suggest
>
>         s{[\w'-]+}{($& eq 'TAG') ? 'TAG' : 'TEXT'}gise;
>
> Note the 'e' on the end.  It says that the substitution replacement,
> which is normally a plain string, is instead a piece of Perl code to
> be executed.  Here we ask if $&, the string you matched, is equal to
> TAG; if so, we replace it with 'TAG', and if not, with 'TEXT'.
>




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

Date: Tue, 31 Oct 2000 17:13:23 -0500
From: Edwin Mercado <emerado@wpi.edu>
Subject: regular expression
Message-Id: <Pine.OSF.4.21.0010311707210.15374-100000@reno.WPI.EDU>

Is there a way to do the following in perl?

$re = 'string';
while (<>) {
	if (/value of $re/sm) { # instead of having----> if (/'string'/sm) {
	... do something
	}
}

I want to search for the value of $re, that is 'string', but I want to be
able to control the $re's value.  I have no idea if this is possible to do
at all.  Any ideas?

Thanks
Ed



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

Date: 31 Oct 2000 22:29:26 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: regular expression
Message-Id: <slrn8vuhu6.2ul.clay@panix6.panix.com>

On Tue, 31 Oct 2000 17:13:23 -0500, Edwin Mercado <emerado@wpi.edu> wrote:

>Is there a way to do the following in perl?

Did you try it?

>$re = 'string';
>while (<>) {
>	if (/value of $re/sm) { # instead of having----> if (/'string'/sm) {
>	... do something
>	}
>}
>
>I want to search for the value of $re, that is 'string', but I want to be
>able to control the $re's value.  I have no idea if this is possible to do
>at all.  Any ideas?

  #!/usr/bin/perl -w
  
  $re = 'foobar';
  
  while (<DATA>) {
      chomp; 
      if (/$re/) {
          print "$re\n";
      }
  }
  
  __DATA__
  foo
  bar
  foobar
  
Result:

  foobar

-- 
Clay Irving <clay@panix.com>
A man's only as old as the woman he feels 
- Groucho Marx


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

Date: Tue, 31 Oct 2000 23:50:42 +0100
From: Adam <adamf@box43.gnet.pl>
Subject: Re: regular expression
Message-Id: <39FF4CC2.7621@box43.gnet.pl>

Edwin Mercado wrote:
> 
> Is there a way to do the following in perl?
> 
> $re = 'string';
> while (<>) {
>         if (/value of $re/sm) { # instead of having----> if (/'string'/sm) {
>         ... do something
>         }
> }
> 
> I want to search for the value of $re, that is 'string', but I want to be
> able to control the $re's value.  I have no idea if this is possible to do
> at all.  Any ideas?

since your question is a newbie one, i as another newbie 
can help you, not mislead - hopefully ;)

what you want is possible. use simply:
if ( /$re/ ) { ... }

but then all special RE character will be treated their usual (special
;) way.
what you may not always want. then use:
if ( /\Q$re\E/ ) { ... }

which will 'escape' all non-alphanumeric characters of $re.
and finally read in:
# perldoc -f quotemeta
# perldoc perlre

--
HTH
Adam.


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

Date: Tue, 31 Oct 2000 21:53:57 GMT
From: ameen @ dausha . net (Ameen Dausha)
Subject: Re: Session or Sessionless?
Message-Id: <39ff3ead.247957345@news>

No barbed wire yet, but I did see the othe side gathering up bricks
and mortar. They said something about a "Java Curtain" or something
like that. 

I suppose part of this is my own ignorance of sessions. I keep hearing
the 'Gnomes of Java" proclaim that Perl is not capable of the
sessioning they are. But, every time I look at it, the session does
seem to be nothing more than cookies and a continually running
instance of an application.

I received an automatically generated email as a result of my posting
here, and I think it had to do with this question. I thumbed through
the CGI.pm documentation and picked up on some things I was not before
aware of.

Thanks!

On Tue, 31 Oct 2000 10:33:58 -0000, "W Kemp" <bill.kemp@wire2.com>
wrote:

>> Is
>>Perl capable of sessions in a browser interface? If so, how?
>
>
>Surely its a question of server-browser interaction.
>Which might get called a CGI question-But java serverlets and mod_perl
>aren't CGI ().
>
>Does Java do some sort of magic server-browser interaction that I am not
>aware of?
>
>Other than that its the hidden field, query string, or cookie stuff.
>(hopefully with most session information in a database)
>The mod_perl "eagle" book talks about this, and some of the ideas can be
>used in standard perl or be applied to other languages.
>
>>
>>This seems to be the biggest issue with the shop's two factions.
>
>
>Oh for a bit of peace and understanding in the world.  Do you have a barbed
>wire line  in the office yet?
>
>



Ben Wilson (a.k.a. Ameen, Last of the Dausha)
____________________________
-"Ever heard of Aristotle . . . Plato . . . Socrates?!"
-"Yes."
-"Morons!"


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

Date: Tue, 31 Oct 2000 22:02:35 GMT
From: ameen @ dausha . net (Ameen Dausha)
Subject: Re: Session or Sessionless?
Message-Id: <39ff3f67.248143134@news>

Hmm, I believe by session I am implying that there is a constantly
running version of an applicaiton in the Server's memory that waits
patiently for browser response. I know this is possible through
FastCGI. I know that some technologies allow for 'session variables,'
but I don't want to pretend to know how that information is stored. 

When I have done something similar it has been to feed a cookie to the
user and to use hidden fields, as one of the posters has commented.

What I've seen is a session_id that is used by the system, I suppose
to remember the user for security purposes, in the URL hat is
irrelevant upon time-out.

Should I be posting this to a CGI newsgroup, even though I'm trying to
find the Perl way to do CGI sessions?


On Tue, 31 Oct 2000 03:51:36 GMT, ameen @ dausha . net (Ameen Dausha)
wrote:

>I work in a shop that has two different groups of developers. The
>first group are we Perl developers, and the other group comprises Java
>developers hamstrung by a rapid development tool. While it takes them
>months longer to develop the same basic type of application it would
>some of we Perl developers, 
>
>Knowing that Java is a system langauge and Perl a glue language, I
>still have a question that I have not yet found a clear answer. Is
>Perl capable of sessions in a browser interface? If so, how?
>
>This seems to be the biggest issue with the shop's two factions.
>
>Thanks in advance.
>
>
>Ben Wilson (a.k.a. Ameen, Last of the Dausha)
>____________________________
>-"Ever heard of Aristotle . . . Plato . . . Socrates?!"
>-"Yes."
>-"Morons!"



Ben Wilson (a.k.a. Ameen, Last of the Dausha)
____________________________
-"Ever heard of Aristotle . . . Plato . . . Socrates?!"
-"Yes."
-"Morons!"


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

Date: 31 Oct 2000 22:31:44 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: Session or Sessionless?
Message-Id: <973031503.609704@hpvablab.cup.hp.com>



ameen @ dausha . net (Ameen Dausha) writes:
>No barbed wire yet, but I did see the othe side gathering up bricks
>and mortar. They said something about a "Java Curtain" or something
>like that. 
>
>I suppose part of this is my own ignorance of sessions. I keep hearing
>the 'Gnomes of Java" proclaim that Perl is not capable of the
>sessioning they are. But, every time I look at it, the session does
>seem to be nothing more than cookies and a continually running
>instance of an application.

It doesn't even have to be a continually running application if you're
storing session data in a DBM file or something similar.

Rich
-- 
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant     | I speak for me,     |   19055 Pruneridge Ave. 
Development Alliances Lab|            *not* HP |                MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014


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

Date: Tue, 31 Oct 2000 20:55:13 GMT
From: Quantum Mechanic <quantum_mechanic@my-deja.com>
Subject: Shrinking a DBM file
Message-Id: <8tnbjd$d33$1@nnrp1.deja.com>

Is there a kosher way to shrink a DBM file between uses?

If I have a script that does a lot of inserts and deletes, but the final
DBM size is much less than the maximum intermediate size, how should I
reclaim the wasted disk space until next time?

Assume that I don't care about running time, like the overhead to grow
the DBM file while the script is running.

-QM
--
Quantum Mechanics: The dreams stuff is made of.


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


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

Date: Tue, 31 Oct 2000 12:51:59 -0800
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Socket not autoflush-ing? ActiveState 618 on NT
Message-Id: <39FF30EF.1338C890@jpl.nasa.gov>

Ran Talbott wrote:
> 
> Running ActiveState build 618 on NT 4.0 with SP6,  I did a cut-and-paste of
> the "simple client" and "simple server" from the perlipc man page to try
> out socket programming.  I commented out the "Command?" prompt in the
> server so I wouldn't have to modify the client to use sysread.
> 
> I can start the server,  and telnet to "localhost 9000" to talk to it (it
> works both with and without the prompt commented out).
> 
> If I try to run the simple client,  it connects correctly,  but stalls the
> first time I type in a line of text to send to the server.  By adding a
> couple of print statements before and after it,  I confirmed that the
> client is hung in the print to the socket.

I was able to get these examples to work using Cygwin on NT 4.0, so it
is likely to be a problem with the Windows port and not with Windows or
perl themselves.

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King


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

Date: Wed, 01 Nov 2000 08:57:25 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: Unterminated <> operator? what the heck?
Message-Id: <39FF4044.567B5049@ot.com.au>

oarend@my-deja.com wrote:

> Hi,
>
> my script gives me the following error report:
>
> > syntax error at searchaw.pl line 118, near "if"
> > Unterminated <> operator at searchaw.pl line 118.
>
> Is there a limit to how long a line in Perl can be? (I'm running
> ActivePerl 5.something on a Win98 system with OmniHTTPd as server)

Why on earth do you want to have such a $#%^% long line anyway?

> Or can you find the mistake in
>
> if (($obj{'frei'} == 1) and ($obj{'zm'} == $param{'zm'}) and ($obj
> {'gr'} > $mingr[$param{'gr'}]) and ($obj{'gr'} <= $maxgr[$param{'gr'}])
> and ($obj{'pr'} > $minpr[$param{'pr'}]) and ($obj{'pr'} <= $maxpr[$param
> {'pr'}]) and (($obj{'ort'} eq $param{'ort1'}) or ($obj{'ort'} eq $param
> {'ort2'}) or ($obj{'ort'} eq $param{'ort3'}) or ($obj{'ort'} eq $param
> {'ort4'}) or ($obj{'ort'} eq $param{'ort5'})) and (($obj{'jahr'} <
> $param{'jahr'}) or (($obj{'jahr'} < $param{'jahr'}) and ($obj{'monat'}
> <= $param{'monat'})))

Why don't you use multiple lines, and use the formatting facilities of your
editor to make this legible? Then you might even be able to solve the
problem yourself.

> (don't worry about the names of the variables or what the heck this is
> doing ;-)

Have no fear. I'm not in the slightest bit interested in what it's doing
when it looks like this...


Ian




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

Date: Tue, 31 Oct 2000 14:22:27 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: using regex to insert data
Message-Id: <MPG.1468e5fadeab350d98ae88@nntp.hpl.hp.com>

[Another success for the bogosity index.  Next time,  place your 
response after the question, as I have done below.]

In article <8tm3tj$lha@nntpb.cb.lucent.com> on Tue, 31 Oct 2000 10:38:26 
+0100, Michael Guenther <MiGuenther@lucent.com> says...
> Cam wrote in message <39fe8d56$0$25562@echo-01.iinet.net.au>...
> >I have another problem, which I am unable to answer.
> >
> >I need to search a string and each time $var1 occurs, insert an element
> >from an array in front of it, incrementing the array after each successful
> >insertion.
> 
> Try
> %search =~s/$var/$array[$number].$var/
> 
> means replace it with our Array element and itself

No it doesn't.

  %search is a hash, not a scalar.

  Your solution fails if there are regex metacharacters in $var.

  Expressions don't automatically evaluate in substitutions, so your
  solution inserts a '.' after the array-element interpolation.

  Your solution makes only one substitution and doesn't increment the
  array index.

  $search =~ s/\Q$var\E/$array[$i++]$var/g;

or

  $search =~ s/(?=\Q$var\E)/$array[$i++]/g;

If $var doesn't change, add the /o modifier.  Or one can use the qr() 
quoting mechanism.

A solution looping on index() and substr() is likely to be faster, but 
more verbose.

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


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

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


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