[7135] in Perl-Users-Digest
Perl-Users Digest, Issue: 760 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 24 00:07:15 1997
Date: Wed, 23 Jul 97 21:00:32 -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 Wed, 23 Jul 1997 Volume: 8 Number: 760
Today's topics:
Re: Arrays, FILEHANDLES, and Efficiency <rootbeer@teleport.com>
Re: Cant seem to reset $1, $2 $3... <rootbeer@teleport.com>
Re: Cant seem to reset $1, $2 $3... <brandon@physics.utexas.edu>
Re: Checking for valid Email... <sfairey@adc.metrica.co.uk>
Re: Checking for valid Email... <rootbeer@teleport.com>
Help: problem with ftp.pl and chat2.pl <ba.wrr@rlg.org>
Re: How to call a package/method from a variable? <guenther@lunen.gac.edu>
Re: how to reverse substitution order ? <rootbeer@teleport.com>
Re: How to round numbers in perl (Bob Wilkinson)
JED Editor for Perl--Keypad problem <pociask@maricopa.edu>
Re: Little problem with tr dcd@k12-dev.arc.nasa.gov
Looking for..... <dean@somehost.gvis.net.au>
Re: LWP <rootbeer@teleport.com>
Making an optional backreference (Kevin Swope)
Re: Making an optional backreference <rootbeer@teleport.com>
Memory leak using IIS (John J. Kerwin)
Re: Mysterious new error? <rra@stanford.edu>
Re: National Medal of Technology: Let's nominate Larry! (Bob Shair)
NNTP Access <serginho@alpha.hydra.com.br>
Re: Performance benefits for homogeneous structures? <rra@stanford.edu>
Re: Perl 5.004 Install Problem <rra@stanford.edu>
Perl for PalmPilot? <fillmore@nrn1.nrcan.gc.ca>
Pre-Announce: Tie::Handle 1.0 in the making (Steffen Beyer)
problem searching w/ string ridden with metachars. dcd@k12-dev.arc.nasa.gov
Re: Problem using CGI.pm -- "Can't find ... 'END_OF_AUT <rootbeer@teleport.com>
Re: read last line without reading previous lines, how? <jwilson@ic.ac.uk>
Re: Regex: Email address format <rra@stanford.edu>
Re: Some problem! <sfairey@adc.metrica.co.uk>
Stumped by a regexp <anneke@intranet.org>
Re: text processing <rootbeer@teleport.com>
Re: WWWlib-perl5 module or a better way? <nick@alekto.co.il>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 23 Jul 1997 06:36:44 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "J. Paul Reed" <preed@psd.k12.co.us>
Subject: Re: Arrays, FILEHANDLES, and Efficiency
Message-Id: <Pine.GSO.3.96.970723063046.12052B-100000@kelly.teleport.com>
On 23 Jul 1997, J. Paul Reed wrote:
> I need to have the functionality of changing one line. Is there anyway to
> do this?
There's some information about this in the FAQ, but basically you usually
want to re-write the file.
> Is there some kind of cool open() statment I can use to tell perl to
> both read in the file and write to it at the same time.
Yes, although its drawback is that you can't easily lock the file while
you're updating it.
@ARGV = qw(my list of files);
$^I = '.bak'; # backup extension
while (<>) {
# Do some updating
s/old line/new data/;
print;
}
Details in perlvar(1) and perlop(1). 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: Wed, 23 Jul 1997 15:30:55 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Kevin Swope <obsidian@shore.net>
Subject: Re: Cant seem to reset $1, $2 $3...
Message-Id: <Pine.GSO.3.96.970723152742.19613F-100000@kelly.teleport.com>
On 23 Jul 1997, Kevin Swope wrote:
> I need to reset the backreference variables but nothing is happening.
I don't know why you would want to reset them, but they're automatically
localized. So you can do this. Hope this helps!
{ # Naked block makes new scope
"some string" =~ /(\w+)\s(\w+)/;
print qq{\$1 and \$2 are "$1" and "$2".\n};
}
print qq{\$1 and \$2 are back to being "$1" and "$2".\n};
--
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: Wed, 23 Jul 1997 16:42:39 -0500
From: "Brandon W. Metcalf" <brandon@physics.utexas.edu>
To: Kevin Swope <obsidian@shore.net>
Subject: Re: Cant seem to reset $1, $2 $3...
Message-Id: <33D67ACF.167E@physics.utexas.edu>
Kevin Swope wrote:
>
> what am I doing wrong.
>
> I need to reset the backreference variables but nothing is happening.
>
The variables are reset automatically on the next successful pattern
match.
--
Brandon Metcalf
UNIX Systems Administrator
Department of Physics - UT Austin
brandon@physics.utexas.edu
------------------------------
Date: Wed, 23 Jul 1997 17:18:38 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: Gabor <gabor@vinyl.quickweb.com>
Subject: Re: Checking for valid Email...
Message-Id: <33D62EDE.1FC319F7@adc.metrica.co.uk>
Gabor wrote:
> Simon Fairey (sfairey@adc.metrica.co.uk) wrote:
>
> [snip]
>
> : PS: $string =~ tr/\s//; #One alternative to the answer you will find
> at
> : DejaNews for removing spaces.
>
> Unfortunately your answer is wrong. It will return a count of matched
> backslashes and s's.
> $string =~ tr/ \n\r\f\t//d;
> will do the trick. And if you found that answer somewhere then it's
> wrong!
>
> --
> Gabor Egressy : gabor@quickweb.com
> No, I am not going to explain it. If you can't figure it out, you
>
> didn't want to know anyway... -- Larry Wall, 1991
Ooops, I forgot to use ' ' rather than '\s' ( I was just going from my
obviously poor memory and too busy thinking about regexps). I didn't
however think you would need to use the 'd' operator. Granted I have
tried it and you do but I am a bit bemused as to why, I must confess I
very rarely use tr///
Simon
------------------------------
Date: Wed, 23 Jul 1997 10:37:59 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Brian - DKOnline <Brian@dkonline.com>
Subject: Re: Checking for valid Email...
Message-Id: <Pine.GSO.3.96.970723103541.23677G-100000@kelly.teleport.com>
On Wed, 23 Jul 1997, Brian - DKOnline wrote:
> if ($input{'Email'} =~ /,/) # a real problem with
> some Compuserver people
> {
> #email needs no commas
> &CgiDie ("Sorry","Your Internet e-mail address
> seems to be wrong<br>e.g.<br>name\@isp.com<br> (no commas)") ;
> }
That's going too far. Valid e-mail addresses may contain commas.
> while (<MAILFILE>)
> {
> s/\b[\w\.]*\@[\w\.]*\b/$Mail{$&}=1/gie;
> }
:-P I _really_ don't like that.
--
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: Wed, 23 Jul 1997 15:27:22 -0700
From: Wes Ramirez <ba.wrr@rlg.org>
Subject: Help: problem with ftp.pl and chat2.pl
Message-Id: <33D6854A.4C20@rlg.org>
On a Solaris 2.5 sys I am trying to run a automatic ftp script. It uses
"require "ftp.pl" which in turn makes a call to chat2.pl. One of the
manuals mentioned a problem with chat2.pl and System5. The script dies
immediately after its request to resolve dns name of the target ftp
site. It never even attempts to make a tcp ftp call. Yes, I don't have
a clue why. Help anyone, please? Thanks
Wes Ramirez
------------------------------
Date: 22 Jul 1997 12:30:30 -0500
From: Philip Guenther <guenther@lunen.gac.edu>
Subject: Re: How to call a package/method from a variable?
Message-Id: <e69pvsbgfk8.fsf@lunen.gac.edu>
Ruben Schattevoy <schattev@imb-jena.de> writes:
> I want to use something like this:
>
> require "DIR/$package.pm";
> $object = DIR::$package->new();
>
> Perl complains:
>
> "Bad name after DIR:: at my_program line nnn."
...
To use a variable in a class name requires the run-time compilation of eval:
$object = eval "DIR::${package}->new()";
Philip Guenther
----------------------------------------------------------------
Philip Guenther UNIX Systems and Network Administrator
Internet: guenther@gac.edu Voicenet: (507) 933-7596
Gustavus Adolphus College St. Peter, MN 56082-1498
------------------------------
Date: Wed, 23 Jul 1997 07:48:01 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Proux Jean-Philippe <proux@geocities.com>
Subject: Re: how to reverse substitution order ?
Message-Id: <Pine.GSO.3.96.970723074010.14902A-100000@kelly.teleport.com>
On Wed, 23 Jul 1997, Proux Jean-Philippe wrote:
> I don't find in faq.
> I don't find in man.
Thanks for looking before you posted!
> so how to reverse order of substitution in pattern matching in perl
> for instance:
> $chemin=toto/titi/tutu/../dudu/./data
>
> My goal is to obtain:
> $chemin=toto/titi/dudu/tata
> like in ls unix !
I think you're saying that you have a file or directory path and you wish
to reduce it to eliminate redundant references to . and .. within it. You
should know that symbolic links can make the parent directory of
foo/bar/.. something other than foo. So, one way to do what you want may
be to use the readlink() function to resolve symbolic links.
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: Wed, 23 Jul 1997 14:38:42 +0100
From: b.wilkinson@pindar.co.uk (Bob Wilkinson)
Subject: Re: How to round numbers in perl
Message-Id: <b.wilkinson-2307971438420001@ip57-york.pindar.co.uk>
In article <33CA2300.1701@nortel.ca>, James Phillips <phillips@nortel.ca> wrote:
> Hi Folks,
>
> Does anyone know how to round numbers in perl?
>
> If you do please post.
>
>
>
> #We want x to be 62 and y to be 61 on the screen
>
> $x = 61.7;
> $y = 61.2;
>
> print "$x, $y\n";
>
>
>
> Jim Phillips
> phillips@nortel.ca
Hello,
1. Add 0.5 to each number.
2. Use sprintf (or printf) to print number out (format string definition
left as exercise for the questioner).
2. (alternative) - strip all characters after and including the decimal
point using a regexp. e.g. $x =~ s/\..+$//;
Bob
--
.sig file on holiday
------------------------------
Date: Tue, 22 Jul 1997 21:02:34 -0600
From: Jason Pociask <pociask@maricopa.edu>
Subject: JED Editor for Perl--Keypad problem
Message-Id: <33D5744A.431A@maricopa.edu>
I'm trying to use the JED editor on Win95 to edit PERL sources
using the EDT (VAX'ish) mode. The numlock key won't lock in to
applications mode even though I ran the recommended MSUGOLD.COM
TSR program first. Can someone tell me if I will ever get this
to work under Win95 or WinNT, or was it a Win 3.1 only thing?
TIA, and sorry if this is tangential to the topic at hand.
-JP
------------------------------
Date: Wed, 23 Jul 1997 16:22:41 -0600
From: dcd@k12-dev.arc.nasa.gov
Subject: Re: Little problem with tr
Message-Id: <869692641.7555@dejanews.com>
I'm not sure I fully understand the question, but I'll try to help
anyway. As far as I can tell, you have a list of a bunch of numbers in
two columns. Your job is to multiply the numbers in the first column
with the ones in the second yeilding one answer per line. Well, Try
this.....
@data = <DATA>;
foreach (@data) {
push @answers, $1*$2 if /([\d.]+)\s+([\d.]+)p/;
};
print join("\n", @answers);
__DATA__
2.5 12p
3.5 33p
4.5 09p
5.5 44p
6.5 43p
7.5 22p
8.5 43p
of course, this assumes that your numbers are always in a "correct"
numeric format (i.e. 23.5 or 33, not 2.3.45 or ...234). But anyway, hope
that helps (I also hope I got the question right :) ).
-David
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 23 Jul 1997 13:20:43 GMT
From: Dean Brandt <dean@somehost.gvis.net.au>
Subject: Looking for.....
Message-Id: <5r50fb$is5@news.mel.aone.net.au>
Hi there,
I am looking for the following scripts.....
1. A script that people can use to change their passwords in /etc passwd
via a web page.
2. Another script that enables root to email all users using one username.
ie
create a master userlist and email all recipients.
Does anyone know where I can find these? Any help is greatly appreciated.
Regards,
--
Dean Brandt
Goulburn Valley Internet Services
Shepparton, Victoria
+61-3-58318100
------------------------------
Date: Wed, 23 Jul 1997 07:54:11 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Zaheed Haque <zaheed.haque@ein.ericsson.se>
Subject: Re: LWP
Message-Id: <Pine.GSO.3.96.970723075225.14902C-100000@kelly.teleport.com>
On Wed, 23 Jul 1997, Zaheed Haque wrote:
> Can someone help to collect h1 and h2 from
> a web page..
Have you seen the HTML::Parse module? 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: 23 Jul 1997 20:17:20 GMT
From: obsidian@shore.net (Kevin Swope)
Subject: Making an optional backreference
Message-Id: <5r5osg$eph@fridge-nf0.shore.net>
I cant seem to make a backreference optional in a regex. This is the sample code I'm
experimenting on. If I take out the '?', then the b is captured in $3, but then it cant be
optional. If I put in the '?' then it become optional and the whole string matches, but there
is nothing in $3. There must be a way. By the way, the 'b' will probably be a larger string
in practice- thats why I leave the parens in there when I add the '?'. THANKS.
$TheString="abc";
$TheString=~ s/((a).*(b)?.*(c))/++++$1++++/x;
print "\n\n$TheString\n\n";
print "\n\n\$1=$1\n\n";
print "\n\n\$2=$2\n\n";
print "\n\n\$3=$3\n\n";
print "\n\n\$4=$4\n\n";
------------------------------
Date: Wed, 23 Jul 1997 20:27:22 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Kevin Swope <obsidian@shore.net>
Subject: Re: Making an optional backreference
Message-Id: <Pine.GSO.3.96.970723202106.9621F-100000@kelly.teleport.com>
On 23 Jul 1997, Kevin Swope wrote:
> I cant seem to make a backreference optional in a regex. This is the
> sample code I'm experimenting on. If I take out the '?', then the b is
> captured in $3, but then it cant be optional. If I put in the '?' then
> it become optional and the whole string matches, but there is nothing in
> $3.
> $TheString="abc";
>
> $TheString=~ s/((a).*(b)?.*(c))/++++$1++++/x;
I think you want to make the first .* minimally matching, so that the b
will match at the earliest opportunity. (And the /x modifier does nothing
on this expression.)
s/((a).*?(b)?.*(c))/++++$1++++/;
You should note that this will still not always find a match with a 'b' in
it, such as in the string 'acabc'. (There are more complex regular
expressions which can do that, though.)
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: 23 Jul 1997 14:30:13 GMT
From: kerwin@cs.buffalo.edu (John J. Kerwin)
Subject: Memory leak using IIS
Message-Id: <5r54hl$3lh@prometheus.acsu.buffalo.edu>
I am running IIS and just using simple CGI/PERL scripts.
My inetinfo.exe process uses more and more memory and
eventually fills up all the virtual memory on the box.
Has any one else run into this ?
Any suggestions on how to fix this ??
jk
------------------------------
Date: 23 Jul 1997 02:18:15 -0700
From: Russ Allbery <rra@stanford.edu>
To: gregory douglas fast <g-fast@ux4.cso.uiuc.edu>
Subject: Re: Mysterious new error?
Message-Id: <m3sox6yvmw.fsf@windlord.Stanford.EDU>
[ Posted and mailed. ]
gregory douglas fast <g-fast@ux4.cso.uiuc.edu> writes:
> Now I've traced the problem to my AUTOLOAD routine, where I was doing
> Bad Things with my $self, and made the error go away, but I'm now
> curious as to the why of perl calling my AUTOLOAD routine for DESTROY.
> It doesn't get called for BEGIN or END... am I just not understanding
> something gutsy?
DESTROY is a method call, so it's subject to autoloading. BEGIN and END
are syntactic sugar for subs, and are a different sort of thing.
If you're implementing AUTOLOAD yourself for an object that doesn't have
its own DESTROY methods, you'll always have to deal with the case where
DESTROY is requested.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 23 Jul 1997 22:32:22 GMT
From: rmshair@uiuc.edu (Bob Shair)
Subject: Re: National Medal of Technology: Let's nominate Larry!
Message-Id: <5r60pm$nic$1@vixen.cso.uiuc.edu>
dbc@tc.fluke.com (Dan Carson) writes:
>I think it would be more appropriate for Larry to receive the Nobel prize.
>Both Nobel and Wall created tools of great utility (dynamite and perl),
>and both were dismayed that their creations weren't always used for the
>good of mankind (blowing up people and e-mailing 100,000 people how to
>"MAKE CA$H FA$T!!!!!!!!!").
When you look at the nature of the World-Wide Web, and the role
Perl has played, a National medal does seem parochial.
But I don't think there's a Nobel prize in Technology.
--
Bob Shair Open Systems Consultant
1018 W. Springfield Avenue rmshair@uiuc.edu
Champaign, IL 61821 217/356-2684
< Not employed by or representing the University of Illinois >
------------------------------
Date: 23 Jul 1997 14:46:33 GMT
From: "Sergio Stateri Jr" <serginho@alpha.hydra.com.br>
Subject: NNTP Access
Message-Id: <01bc9777$aa3c1d20$ca75e7c8@Term104>
Hi ! Does anyone here know where I can find a Perl Script that access a
NNTP server ? I'd like a script that use only default perl modules, because
I want to use this in a server that I can only to put my scripts, but I
can't to install new modules.
Thanks in advance,
--
--------------------------------------------
Sergio Stateri Jr
Sco Paulo (SP) - Brazil
e-mail: serginho@usa.net
--------------------------------------------
------------------------------
Date: 23 Jul 1997 02:21:44 -0700
From: Russ Allbery <rra@stanford.edu>
To: over@the.net
Subject: Re: Performance benefits for homogeneous structures?
Message-Id: <m3oh7uyvh3.fsf@windlord.Stanford.EDU>
[ Posted and mailed. ]
dave <over@the.net> writes:
> With perl I can create a hash of hashes. Is there performance benefits
> gained by making each hash within the hash have the same keys (different
> values for each key)?
Not that I know of, nor can I think of any particular reason why there
should be.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 23 Jul 1997 02:15:45 -0700
From: Russ Allbery <rra@stanford.edu>
To: Shashidhar Rajamani <rajamani@ee.tamu.edu>
Subject: Re: Perl 5.004 Install Problem
Message-Id: <m3wwmiyvr2.fsf@windlord.Stanford.EDU>
[ Posted and mailed. ]
Shashidhar Rajamani <rajamani@ee.tamu.edu> writes:
> I am unable to install 5.004_01 on solaris 2.5.1
> I get the following error when running make test:
[snip]
> sh: ar: not found
Add /usr/ccs/bin to your path.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Wed, 23 Jul 1997 18:19:00 -0400
From: Bob Fillmore <fillmore@nrn1.nrcan.gc.ca>
Subject: Perl for PalmPilot?
Message-Id: <33D68353.B5DC2F91@nrn1.nrcan.gc.ca>
Is anyone porting Perl to the USR PalmPilot?
------------------------------
Date: 23 Jul 1997 00:11:07 GMT
From: sb@sdm.de (Steffen Beyer)
Subject: Pre-Announce: Tie::Handle 1.0 in the making
Message-Id: <5r3i6r$l8d$1@en1.engelschall.com>
Dear Perl users,
no need to write a "Tie::Handle" module anymore to tie filehandles
to (arbitrary) objects!
("Tie::Handle" is one of the modules which was still missing in the
"Tie::..." series of modules)
Since tying of filehandles is a very recent feature, this module needs
Perl 5.004 in order to run.
I am currrently preparing the release of that module, which should come
out any day now (probably end of the week is more realistic).
I wrote this module because I needed it for my "Data::Locations" module
which will come out at the same time.
I will post a more detailed announcement to this newsgroup again as soon
as the modules will be available.
Watch http://www.engelschall.com/u/sb/download/ if you want to have a
copy "fresh out of the factory".
Yours sincerely,
--
Steffen Beyer <sb@sdm.de> http://www.engelschall.com/u/sb/
"There is enough for the need of everyone in this world,
but not for the greed of everyone." - Mahatma Gandhi
>> Unsolicited commercial email goes directly to /dev/null <<
------------------------------
Date: Wed, 23 Jul 1997 16:51:45 -0600
From: dcd@k12-dev.arc.nasa.gov
Subject: problem searching w/ string ridden with metachars.
Message-Id: <869694342.8915@dejanews.com>
The snippet of code below is supposed to search through the text from an
html file (in $data), for a search string ($search_string) of more html
text. Previously I had the problem that the spacing of the text in
$search_string was different than when it appeared in $data. I had
several helpful suggestions and fixed the problem by saying
$search_string =~ s/\s/\\s+/g; and $data =~ s/$search_string/$text/g;
It struck me that there were probably tons of other meta characters
that could appear in $search_string, and so I added some lines to
backslash them out. But the resulting code below, which by my estimations
should work, doesn't. If anyone could figure out why and explain it to
me, I'd be very grateful.
Thanks,
David
--------------------
$data=join("",<DATA>);
$text='THIS WAS THE HEADER!!'; #test replacement text
$search_string = '<p>
<center>
<a href="/neuron/credits.html"><img border=0
src="/neuron/images/credits.gif"></a>
</center><p>
'; #multi-line search string
$search_string =~ s/^\s+//; #kill leading /
$search_string =~ s/\s+$//; # / trailing white space
$search_string =~ s/\s/\\s+/g; #collapse white space.
$search_string =~ s/\\(?!s\+)/\\\\/g; #quote non-used backslashes
$search_string =~ s/([^\\\w])/\\$1/g; #quote non-'/' metachars
print "Search string is:!!$search_string!!\n";
<stdin>;
$data =~ s/$search_string/$text/gi;
print $data;
__DATA__
<p>
<center>
<a href="/neuron/credits.html"><img border=0
src="/neuron/images/credits.gif"></a>
</center><p>
<map name="neuron">
<AREA SHAPE=rect COORDS="3,95, 85,117" HREF="/neuron">
<AREA SHAPE=rect COORDS="98,96, 158,117" HREF="/cgi-bin/neuron/survey.pl">
<AREA SHAPE=rect COORDS="166,96, 243,117"
HREF="/cgi-bin/neuron/postcard.pl">
<AREA SHAPE=rect COORDS="258,96, 344,117"
HREF="/cgi-bin/neuron/neuron-wais.pl">
<AREA SHAPE=rect COORDS="358,96, 420,117" HREF="/neuron/overview.html">
<AREA SHAPE=rect COORDS="431,95, 502,118" HREF="/">
<AREA SHAPE=default HREF="/neuron">
</map>
</body>
</html>
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Wed, 23 Jul 1997 15:34:55 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Matt Holsen <mholsen@esmprods.com>
Subject: Re: Problem using CGI.pm -- "Can't find ... 'END_OF_AUTOLOAD', [etc.]"
Message-Id: <Pine.GSO.3.96.970723153127.19613G-100000@kelly.teleport.com>
On Thu, 24 Jul 1997, Matt Holsen wrote:
> Can't find string terminator "END_OF_AUTOLOAD" anywhere before EOF at
> CGI.pm line 645
You've got some other character on the line that looks like it only has
that token. Probably it's a leftover carriage return. Has that file been
on a DOS/Windows machine? When you transfer a text file via FTP to or from
a non-Unix machine, be sure to use text mode. This command on your Unix
machine will strip carriage returns from the file. Does that help? Good
luck!
perl -pi.bak -e "s/\r//g" CGI.pm
--
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: 23 Jul 1997 09:24:41 GMT
From: "Jeff Wilson" <jwilson@ic.ac.uk>
Subject: Re: read last line without reading previous lines, how?
Message-Id: <01bc974a$3fc57310$1d34c69b@leicester>
Try ...
open(TXT,"<textfile");
@fred=<TXT>;
print @fred[$#fred],"\n";
--
Jeff Wilson
London - UK
Helmut Jarausch <jarausch@numa1.igpm.rwth-aachen.de> wrote in article
<5qnrki$jfd$1@news.rwth-aachen.de>...
: In article <5qjj3s$11$1@coranto.ucs.mun.ca>, chuan@engr.mun.ca (Chuan
Wang) writes:
: |> Hi,
: |>
: |> I wonder how to reading the last line of a text file, without
going through
: |> the previous lines. Thanks.
:
: Look up the man pages for 'seek', there is a mode to seek to the end
of a file.
: --
: Helmut Jarausch
: Lehrstuhl f. Numerische Mathematik
: Institute of Technology, RWTH Aachen
: D 52056 Aachen, Germany
:
------------------------------
Date: 23 Jul 1997 02:28:33 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Regex: Email address format
Message-Id: <m3k9iiyv5q.fsf@windlord.Stanford.EDU>
Randal Schwartz <merlyn@stonehenge.com> writes:
> As has been said Oh So Many Times here, just about any character on the
> planet is permitted on the left side of the @. See tchrist's chkaddr
> script for something MUCH much closer than what you've written.
Tom's chkaddr script rejects:
"Russ Allbery"@eyrie.org
which although it isn't currently a valid e-mail address (I got tired of
having the alias around), it was for a very long time.
You really can't win on this one.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Wed, 23 Jul 1997 17:23:01 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: nick <nick@alekto.co.il>
Subject: Re: Some problem!
Message-Id: <33D62FE5.F94D8FCB@adc.metrica.co.uk>
nick wrote:
> Hi!
> I've installed PerlIS and Perl 5 on my windows NT 4.0 and tried to run
> a
> very
> simple script:
>
> foreach (%ENV){
> print "The Env Variable $_ value is \"$ENV($_)\"\n";
> }
>
> when I run this script (as a CGI) I get only value for variable
> "PERLXS value is PerlIS"
>
> but when I do :
>
> print "REMOTE ADDRESS : \"$ENV(REMOTE_ADDR)\"\n";
> foreach (%ENV){
> print "The Env Variable $_ value is \"$ENV($_)\"\n";
> }
>
> I already get 2 variables in the loop and so on...
>
> What is the problem, why don't I get all the vairables in the first
> script?
>
> Nick
You need to be doing:
foreach( keys %ENV )
The foreach() is expecting an array and %ENV is a hash so you want a
list of all the keys in the hash so that you can then go ahead and print
them.
Look at the perldata, perldsc and perllol man pages for further info.
Simon
------------------------------
Date: Tue, 22 Jul 1997 19:15:39 -0700
From: Anneke Floor <anneke@intranet.org>
Subject: Stumped by a regexp
Message-Id: <33D5694B.54B7@intranet.org>
I've been trying to think of a regular expression that would find a
record in a text file (all records are separated by \n). What the regexp
would look for is the prefix of a filename (ie: "file" if the filename =
"file.xxx"), followed (but not immediately) by the extension ("xxx").
The thing is, the filenames in this list can look like this:
file.www,xxx,yy
if the file has multiple formats.
I want it to match only one specified format.
What I have is:
/^$prefix\..*\W$suffix\W.*/
The \W's were to ensure that a word like "oops" later on in the record
wouldn't cause the regexp to match for an extension like "ps". However,
this means that file.ps,yy wouldn't match. So, that's a no go.
The first field in the record contains the filename. This field is
delineated by "::". Is there any way to ensure the regexp doesn't look
further than the first "::"?
Thanks for any help,
Anneke.
anneke@intranet.org
"Curious people are interesting people. Why is that?" -Bill Maher.
------------------------------
Date: Wed, 23 Jul 1997 16:00:18 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Mehmet Demirkol <demirkol@sgs-server.Stanford.EDU>
Subject: Re: text processing
Message-Id: <Pine.GSO.3.96.970723155444.19613K-100000@kelly.teleport.com>
On Wed, 23 Jul 1997, Mehmet Demirkol wrote:
> How can I remove all "^M"s from a piece of text?
>
> I guess I can use
>
> $text =~ s/\x??//g;
>
> but what should "??" be? Is there a web page that has a list of those
> substitude values?
Probably. But you can peek in the file to see the hex values, with or
without perl. (This is without. I think that this command is pretty
standard on Unix machines. If you can't find od on your machine, we could
cook up some perl to do the same job.)
od -xc somefile | more
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: Wed, 23 Jul 1997 22:00:18 +0300
From: nick <nick@alekto.co.il>
Subject: Re: WWWlib-perl5 module or a better way?
Message-Id: <33D654C1.BDD9071E@alekto.co.il>
Tom Phoenix wrote:
> On 22 Jul 1997, Mwebernet wrote:
>
> > Do you know how to retrieve web pages on remote systems with perl?
> The
> > only way I know of is with the libwww module. Is there another way?
>
> Is there some reason you don't want to use the module? If I knew what
> you
> don't like about it, I might be able to offer a way around those
> shortcomings. But the reason you see it suggested so often is because
> it's
> generally the best way.
>
> If you must have another way, here's one. But it may be a little
> buggy. I
> think it may have some undesirable shortcomings of its own. :-)
>
> $url = q{http://www.perl.com/CPAN/};
> print qq{Could you please retrieve this web page?\n
> $url\n\nThank you. :-)\n};
>
> Seriously, you'll need to tell more about why you don't like a
> solution
> which is already coded, documented, and debugged for you. Thanks!
>
> --
> 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/
Is this outspoken libwww available for windows NT?
Where can I get it?
Nick
------------------------------
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 760
*************************************