[24416] in Perl-Users-Digest
Perl-Users Digest, Issue: 6604 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 25 00:05:39 2004
Date: Mon, 24 May 2004 21:05:07 -0700 (PDT)
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, 24 May 2004 Volume: 10 Number: 6604
Today's topics:
Getting an IP address <sean_berry@cox.net>
Re: Getting an IP address <ittyspam@yahoo.com>
Re: Getting an IP address <sean_berry@cox.net>
Re: How to pass input from perl to shell programming? (Swamy)
Re: Komodo as a editor? (krakle)
Re: Map or Regex and Sorting <krahnj@acm.org>
Re: Map or Regex and Sorting <uri@stemsystems.com>
Re: Pari lib with Math-BigInt (win32) <kalinaubears@iinet.net.au>
Re: Password scheme/Persistent session... (krakle)
Re: Password scheme/Persistent session... (krakle)
Re: Password scheme/Persistent session... (krakle)
Re: Password scheme/Persistent session... (krakle)
Re: Password scheme/Persistent session... (krakle)
Re: Perl inplace editing <krahnj@acm.org>
Re: Perl vs PHP (krakle)
Re: Perl vs PHP (Sam Holden)
Re: Perl work? (krakle)
Regex srch & repl only executing once (Ethan)
Re: Regex srch & repl only executing once <uri@stemsystems.com>
Request for help with search & replace script (Ethan)
Re: Request for help with search & replace script <tadmc@augustmail.com>
Re: String search/match question (Kevin Potter)
Re: String search/match question (Sam Holden)
Re: Using Cookies With Perl <ittyspam@yahoo.com>
Re: Using Cookies With Perl (krakle)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 24 May 2004 15:34:07 -0700
From: "Sean Berry" <sean_berry@cox.net>
Subject: Getting an IP address
Message-Id: <zLusc.6382$wH1.2441@fed1read02>
I am fairly new to Perl, doing most of my stuff in Python.
But, I really like Perl's CGI capabilities.
I have a Perl CGI program that I am running that I would like to be
extremely secure. It will require a password, using htaccess. But, I would
also like to limit it to computers on our network as well as a few
individual IP addresses.
I thought of setting up an array of acceptable IP addresses and checking
whether the requesting IP address is in the array. Let them through if they
are. Boot them if they are not.
How can I do this? How can I harvest the IP address of the reuqesting
computer?
Thanks in advance.
------------------------------
Date: Mon, 24 May 2004 19:10:43 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Getting an IP address
Message-Id: <20040524190845.R338@dishwasher.cs.rpi.edu>
On Mon, 24 May 2004, Sean Berry wrote:
> I am fairly new to Perl, doing most of my stuff in Python.
>
> But, I really like Perl's CGI capabilities.
>
> I have a Perl CGI program that I am running that I would like to be
> extremely secure. It will require a password, using htaccess. But, I would
> also like to limit it to computers on our network as well as a few
> individual IP addresses.
>
> I thought of setting up an array of acceptable IP addresses and checking
> whether the requesting IP address is in the array. Let them through if they
> are. Boot them if they are not.
>
> How can I do this? How can I harvest the IP address of the reuqesting
> computer?
Well, from your CGI script, you can use the REMOTE_ADDR key of the %ENV
hash:
print "Your IP Address is: $ENV{REMOTE_ADDR}\n";
However... if you're already using htaccess, might it not be a better idea
to use that to limit the IP addresses, as that functionality is already
built in? Just a suggestion, it may or may not apply to your situation.
Paul Lalli
------------------------------
Date: Mon, 24 May 2004 18:01:11 -0700
From: "Sean Berry" <sean_berry@cox.net>
Subject: Re: Getting an IP address
Message-Id: <TUwsc.5791$_o.1136@fed1read05>
I was thinking about that but I already have programs in the directory that
shoud be able to be accessed from anywhere.
How does it work if I have an .htaccess in ./domain/private and another in
./domain/private/restricted
Are both passwords going to be required to access
./domain/private/restricted?
Many thanks. I know this has turned into a non-perl question, but hate to
start another post on another newsgroup for a simple question like this.
"Paul Lalli" <ittyspam@yahoo.com> wrote in message
news:20040524190845.R338@dishwasher.cs.rpi.edu...
> On Mon, 24 May 2004, Sean Berry wrote:
>
> > I am fairly new to Perl, doing most of my stuff in Python.
> >
> > But, I really like Perl's CGI capabilities.
> >
> > I have a Perl CGI program that I am running that I would like to be
> > extremely secure. It will require a password, using htaccess. But, I
would
> > also like to limit it to computers on our network as well as a few
> > individual IP addresses.
> >
> > I thought of setting up an array of acceptable IP addresses and checking
> > whether the requesting IP address is in the array. Let them through if
they
> > are. Boot them if they are not.
> >
> > How can I do this? How can I harvest the IP address of the reuqesting
> > computer?
>
> Well, from your CGI script, you can use the REMOTE_ADDR key of the %ENV
> hash:
>
> print "Your IP Address is: $ENV{REMOTE_ADDR}\n";
>
>
> However... if you're already using htaccess, might it not be a better idea
> to use that to limit the IP addresses, as that functionality is already
> built in? Just a suggestion, it may or may not apply to your situation.
>
> Paul Lalli
------------------------------
Date: 24 May 2004 17:02:00 -0700
From: swamyb@hotmail.com (Swamy)
Subject: Re: How to pass input from perl to shell programming?
Message-Id: <1aaaeaf0.0405241602.20b0e635@posting.google.com>
swamyb@hotmail.com (Swamy) wrote in message news:<1aaaeaf0.0405240916.b70ffcd@posting.google.com>...
> swamyb@hotmail.com (Swamy) wrote in message news:<1aaaeaf0.0405210846.302f71dd@posting.google.com>...
> > I have a perl program which executes a shell program using system
> > call. This shell program needs user input for several questions it
> > asks. How can I automate the user input so that user don't have to key
> > in the input?
> >
> > thanks
> > Swamy
>
> Thanks a lot for your advice. I found IO->React more useful which is
> docmented in CPAN.
>
> regards
> swamy
I tried perl expect also, which seems to be more useful. I am trying
to start a ssh session, login, and spawn another program(installation
program). It has "more based text", and some user input. I could not
grab control of the program nor send or expect anything. It just stays
at first "--More10%" prompt.
Can you please tell me how to do it?
thanks
Swamy
------------------------------
Date: 24 May 2004 18:29:11 -0700
From: krakle@visto.com (krakle)
Subject: Re: Komodo as a editor?
Message-Id: <237aaff8.0405241729.6e4ca0b2@posting.google.com>
Robert <catcher@linuxmail.org> wrote in message news:<hJGdnQRF9eMnhAXdRVn-jw@adelphia.com>...
> I am evaluating Komodo as an editor for work. I am doing a lot of Perl
> work as a sysadmin and am starting to get into Perl/Tk as well. We use
> PVCS for version control and I see Komodo integrates with that.
>
> All that to say "Do you use it and what do you think about it?".
>
> Robert
Scite.
------------------------------
Date: Tue, 25 May 2004 01:16:36 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Map or Regex and Sorting
Message-Id: <40B29E7D.B307BDC8@acm.org>
Herr Hardy wrote:
>
> I have some working code, but I think, there's more than one better
> way to solve the task:
>
> I have some given Data that should be sorted first on appearance of
> string OPEN (on top) and second after the values of the first
> occurence of digits, here e.g. 31 to 40.
> How can I 'regex' or 'map' this to sort them in one loop already?
>
> Thanks
> Hardy
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> my @digitlist;
> my @openlist;
> my @clsdlist;
>
> while(<DATA>){
> /(\d{1,3})/;
> push (@digitlist,$1.$_);
> }
>
> @digitlist = sort @digitlist;
>
> for(@digitlist){
> if (/OPEN/){
> push(@openlist,$_);
> }else{
> push(@clsdlist,$_);
> }
> }
>
> for(@openlist){
> print;
> }
> for(@clsdlist){
> print;
> }
> 1;
> # EOF
>
> __DATA__
> SBruhrtal32PER09CLSD
> SBsorpe31PER19IN18last
> RBruhrII33PER11OPEN
> RBruhrI34PER14CLSD
> RBharkortI40PER09OPEN
#!/usr/bin/perl
use warnings;
use strict;
my ( @openlist, @clsdlist );
push @{ /OPEN/ ? \@openlist : \@clsdlist }, $_ for
map substr( $_, 3 ),
sort
map sprintf( '%03d%s', /(\d{1,3})/, $_ ),
<DATA>;
print @openlist, @clsdlist;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 25 May 2004 01:52:04 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Map or Regex and Sorting
Message-Id: <x7u0y5nuik.fsf@mail.sysarch.com>
>>>>> "JWK" == John W Krahn <krahnj@acm.org> writes:
JWK> #!/usr/bin/perl
JWK> use warnings;
JWK> use strict;
JWK> my ( @openlist, @clsdlist );
JWK> push @{ /OPEN/ ? \@openlist : \@clsdlist }, $_ for
JWK> map substr( $_, 3 ),
JWK> sort
JWK> map sprintf( '%03d%s', /(\d{1,3})/, $_ ),
JWK> <DATA>;
JWK> print @openlist, @clsdlist;
i like it, an GRT written on the fly. but you now owe me royalties! for
payment, i expect you to test Sort::Maker before its public release.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 25 May 2004 10:14:18 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Pari lib with Math-BigInt (win32)
Message-Id: <40b29109$0$16599$5a62ac22@freenews.iinet.net.au>
gnu valued customer wrote:
>
> warning:
> Cannot load outdated Math::BigInt::Pari v1.10, please
> upgrade at ... (points to about 'use')
>
Version 1.10 was put on CPAN earlier this year, and is the latest
available ... calling it "outdated" seems a little severe to me :-)
I get the same. The error is produced by Math::BigInt-1.70 - search
'BigInt.pm' for "outdated". I tried Math::BigInt-1.64 and the error did
not arise, though 'nmake test' threw up some other errors. Perhaps using
version 1.69 or 1.68 instead of 1.70 would provide a temporary workaround.
The M::BI::P author (Tels), who is also currently maintaining M::BI,
might be able to provide some insight if you don't get a satisfactory
answer here. (He should at least be informed of the problem.)
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: 24 May 2004 15:50:58 -0700
From: krakle@visto.com (krakle)
Subject: Re: Password scheme/Persistent session...
Message-Id: <237aaff8.0405241450.45237b1c@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c8pvae$6f8$1@mamenchi.zrz.TU-Berlin.DE>...
> I do, and so does Google. Your aggressive arrogance is quite memorable.
And I don't see a thread like it via google. Perhaps you can post the
link if you feel it's neccessary to prove nothing..
> Fine. If you want to be known as a self-confessed parasite and pick
> useful scraps out of piles of shit thrown your way, be my guest.
Isn't that what you did.. Pick out tibets of my post...
> I prefer a little respect myself.
And you were disrespected by myself how? I don't recall every
directing a post your way or ever making references to you.
> Identifying and eliminating ticks is always on topic.
Not when it exceeds 40+ posts.
------------------------------
Date: 24 May 2004 15:52:13 -0700
From: krakle@visto.com (krakle)
Subject: Re: Password scheme/Persistent session...
Message-Id: <237aaff8.0405241452.23f6dec6@posting.google.com>
"John W. Kennedy" <jwkenne@attglobal.net> wrote in message news:<9QUrc.23950$cz5.7312278@news4.srv.hcvlny.cv.net>...
> You are obviously ineducable.
Thanks for being on topic.
------------------------------
Date: 24 May 2004 15:53:29 -0700
From: krakle@visto.com (krakle)
Subject: Re: Password scheme/Persistent session...
Message-Id: <237aaff8.0405241453.32b06066@posting.google.com>
"gnari" <gnari@simnet.is> wrote in message news:<c8dnrg$ks3$1@news.simnet.is>...
> "krakle" <krakle@visto.com> wrote in message
> news:237aaff8.0405181107.162a37c6@posting.google.com...
> > Sherif Zaroubi <blah@blah.com> wrote in message
> news:<opr7z5yhkqcx74rp@news.videotron.ca>...
>
> > > You don't need a session. All you need is a password file.
> >
> > I need a session. .htpasswd does linear style look ups. Users
> > beginning with 'Z' will take longer to look up than users beginning
> > with the letter 'A'. It doesn't make sense to have hundreds of
> > thousands or even 10's of thousands of usernames in a plaintext file.
> > Imagine how poor performance will be. I also need session control to
> > be able to set time limits, expire as well as some other general
> > session tasks. Apaches .htpasswd just isn't enough or performance
> > driven.
>
> did you look at the other apache auth_* modules
> like mod_auth_dbm or mod_auth_db ?
>
> these provide much better performance with large user sets.
>
> there are also extentions that allow the use of full-blown DBMS's,
> if you need better management of your user database.
>
> gnari
Thank you. It was a consideration.
------------------------------
Date: 24 May 2004 15:56:58 -0700
From: krakle@visto.com (krakle)
Subject: Re: Password scheme/Persistent session...
Message-Id: <237aaff8.0405241456.5ff6252f@posting.google.com>
"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in message news:<Pine.LNX.4.53.0405222058100.31187@ppepc56.ph.gla.ac.uk>...
> On Sat, 21 May 2004, krakle wrote:
>
> > What I ended up doing is setting a cookie that md5 encrypted time +
> > random number + process ID as the session id (sid). Then it looks up
> > the data of that user in a mySQL table using the SID in the cookie.
>
> Which seems to be no different from what your original proposal had
> been at the start of this thread. And I still don't see anything
> Perl-specific in it.
It was the idea originally suggested to me that I decided to take and
put into effect. My original question was pertaining to any Perl
module to mantain state (like ASP has a feature).
> That's what (AFAICS) a number of well-intentioned folks have been
> trying, unsuccessfully, to communicate to you, despite your hostility.
> And now that it's failed, you go back into the killfile until the next
> round of housekeeping.
I simply asked a question dealing with perl in a perl newsgroup (if
there's any perl m odules to mantain state). That is all.
Takes to to tango. I'm just nice enough to reply to all responses. :)
Killfile away. Makes no difference to me.
------------------------------
Date: 24 May 2004 20:51:56 -0700
From: krakle@visto.com (krakle)
Subject: Re: Password scheme/Persistent session...
Message-Id: <237aaff8.0405241951.16fda0a0@posting.google.com>
"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in message news:<Pine.LNX.4.53.0405222219170.31304@ppepc56.ph.gla.ac.uk>...
> On Sat, 22 May 2004, norfernuman wrote:
>
> > Wow, this same guy still got answers from this group. You all either
> > didn't know of him, remember him, or your very forgiving. He's got some
> > nerve even showing his 'face' back here.
>
> What you're missing is that the regulars are responding as much for
> the potential benefit of the rest of the Usenet audience, as for the
> individual who provoked the issue.
:)
All my posts are on topic and never go offtopic unless someone brings
it off. Like this one.
------------------------------
Date: Tue, 25 May 2004 01:39:19 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl inplace editing
Message-Id: <40B2A3D2.64BC6542@acm.org>
Sundaram Ramasamy wrote:
>
> I want to check in file line start with HOSTNAME, then I want to
> replcae HOSTNAME value to linux.com, if line is not there I want add
> new line HOSTNAME=linux.com
>
> Using inplace editing I was not able to add new line.
>
> Here is my one liner inplace editing script
>
> perl -i.old -ne '$ne=0; if( /^\s*HOSTNAME\s*=/ ) {
> s/=.*$/=linux.com/; $nx++; print $_; }else { print $_; } END { if( $nx
> ==0 ){ $_="HOSTNAME=linux.com\n"; print $_; } }' network
>
> Requirment:
>
> 1) orginal file:
> NMAE=myname
> IP=234.56.43.23
> HOSTNAME=abcde.com
>
> I need out put:
> NMAE=myname
> IP=234.56.43.23
> HOSTNAME=linux.com
>
> 2) orginal file:
> NMAE=myname
> IP=234.56.43.23
>
> I need out put:
> NMAE=myname
> IP=234.56.43.23
> HOSTNAME=linux.com
>
> Any tips for this
perl -i.old -0pe'
s/(?<=HOSTNAME)(\s*=\s*.+)/=linux.com/
||
s/\z/HOSTNAME=linux.com\n/
' network
John
--
use Perl;
program
fulfillment
------------------------------
Date: 24 May 2004 15:45:43 -0700
From: krakle@visto.com (krakle)
Subject: Re: Perl vs PHP
Message-Id: <237aaff8.0405241445.2e5ccbf9@posting.google.com>
"David H. Adler" <dha@panix2.panix.com> wrote in message news:<slrncb3ep1.qnp.dha@panix2.panix.com>...
> If you were to compare a perl program to a php program in terms of
> speed, they'd have to do the same thing if you wanted a meaningful
> comparison - in which case saying "a PHP CGI program [may be] faster
> than a Perl CGI program" would make sense, but to say that PHP is
> "faster than CGI" makes no sense whatsoever.
I see your point. But since we are comparing Perl vs PHP (an internet
language) I assumed that most people would think when using CGI in
THIS threat they were referring to Perl and not C++ or any other
language (since it's irrelevant to topic)...
------------------------------
Date: 24 May 2004 23:16:53 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Perl vs PHP
Message-Id: <slrncb50j5.gsp.sholden@flexal.cs.usyd.edu.au>
On 24 May 2004 15:45:43 -0700, krakle <krakle@visto.com> wrote:
> "David H. Adler" <dha@panix2.panix.com> wrote in message news:<slrncb3ep1.qnp.dha@panix2.panix.com>...
>> If you were to compare a perl program to a php program in terms of
>> speed, they'd have to do the same thing if you wanted a meaningful
>> comparison - in which case saying "a PHP CGI program [may be] faster
>> than a Perl CGI program" would make sense, but to say that PHP is
>> "faster than CGI" makes no sense whatsoever.
>
> I see your point. But since we are comparing Perl vs PHP (an internet
> language) I assumed that most people would think when using CGI in
> THIS threat they were referring to Perl and not C++ or any other
> language (since it's irrelevant to topic)...
But php should be compared with mod_perl, unless you think that people
would also assume that PHP means "PHP CGI"...
--
Sam Holden
------------------------------
Date: 24 May 2004 16:01:04 -0700
From: krakle@visto.com (krakle)
Subject: Re: Perl work?
Message-Id: <237aaff8.0405241501.403d735@posting.google.com>
Charlton Wilbur <cwilbur@mithril.chromatico.net> wrote in message news:<87lljj24hm.fsf@mithril.chromatico.net>...
> They're also people in foreign countries where $2/hour is a very good
> wage. Someone who lives in a region where $2000/year is a comfortable
> income is probably doing quite well to be making $3 or $4 an hour.
ermmm.. I would have to disagree. I don't think someone who makes
$2,000 a year able to live off from $3 an hour even has a computer
with internet access and a programming education background to do the
work. I would of thought common sense would of ruled that out...
------------------------------
Date: 24 May 2004 19:36:25 -0700
From: elektrophyte@yahoo.com (Ethan)
Subject: Regex srch & repl only executing once
Message-Id: <55447041.0405241836.4d63deef@posting.google.com>
This is adding more detail to my previous post. As mentioned, I'm
trying to write a simple search and replace script. My current version
is copied below. When I run it on a directory tree of files, for each
file the first occurance of the search string IS replaced, but NONE of
the others are replaced.
If I could just get it to replace all of the occurances, then I'd be
in business. Any help or information would be greatly appreciated.
Thanks!
E
sub doReplace
{
my @outLines; #Data we are going to output
my $line; #Data we are reading line by line
# Only parse files that end in .htm
if ( $File::Find::name =~ /\.htm$/ )
{
print "\nprocessing $_\n";
open (FILE, $File::Find::name ) or
die "Cannot open file: $!";
$backupFileName = $File::Find::name . ".bak";
system("cp $File::Find::name $backupFileName");
while ( $line = <FILE> )
{
print " |"; # To show that something's happening
#$line =~ s/\.jsp/.htm/; # Only works the first time
# Rest of the ".jsp"s untouched
push(@outLines, $line);
}
close FILE;
open ( OUTFILE, ">$File::Find::name" ) or
die "Cannot open file: $!";
print ( OUTFILE @outLines );
close ( OUTFILE );
undef( @outLines );
}
}
------------------------------
Date: Tue, 25 May 2004 03:18:30 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Regex srch & repl only executing once
Message-Id: <x7d64tnqih.fsf@mail.sysarch.com>
use File::Slurp ;
sub replace {
my( $file_name, $from, $to ) = @_ ;
my $text = read_file( $file_name ) ;
$text =~ s/$from/$to/g ;
rename( $file_name, "$file_name.bak" ) ;
write_file( $file_name, $text ) ;
}
untested and assumes $from is a legal regex.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 24 May 2004 18:15:54 -0700
From: elektrophyte@yahoo.com (Ethan)
Subject: Request for help with search & replace script
Message-Id: <55447041.0405241715.17164ab9@posting.google.com>
Hi. I'm trying to write a script that will search through files in a
website and replace certain strings with others (in some cases just
delete them). My overall goal is to convert a JSP site to plain html
removing all the JSP code and adding some SSIs.
I adapted the subroutine below which was posted on 10/8 to devshed.com
by "raklet". When I run it there are no error messages and the print
statements work as expected. However when I go to look at the files,
in some files it appears that nothing has happened, and in other cases
all data in the file has been removed.
I would be grateful for any comments or information on why this isn't
working.
Alternately, if anyone could point me in the direction of a better
solution altogether that would be great too.
I'm not a Perl expert sorry to say.
Thanks,
E
#----------------------------------------------------------
sub doReplace
{
my @outLines; #Data we are going to output
my $line; #Data we are reading line by line
# Only parse files that end in .htm
if ( $File::Find::name =~ /\.htm$/ )
{
print "\nprocessing $_\n";
open (FILE, $File::Find::name ) or
die "Cannot open file: $!";
while ( $line = <FILE> )
{
$line =~ s/\.jsp$/.htm/i;
$line =~ s/<jsp:setProperty.+\>//i;
$line =~ s/<jsp:useBean.+\>//i;
push(@outLines, $line);
}
close FILE;
open ( OUTFILE, ">$File::Find::name" ) or
die "Cannot open file: $!";
print ( OUTFILE @outLines );
close ( OUTFILE );
undef( @outLines );
}
}
------------------------------
Date: Mon, 24 May 2004 21:04:08 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Request for help with search & replace script
Message-Id: <slrncb5aco.r02.tadmc@magna.augustmail.com>
Ethan <elektrophyte@yahoo.com> wrote:
> Hi. I'm trying to write a script that will search through files in a
> website and replace certain strings with others (in some cases just
> delete them).
> I adapted the subroutine below which was posted on 10/8 to devshed.com
> by "raklet".
> I would be grateful for any comments or information on why this isn't
> working.
Too much "greed" perhaps...
> Alternately, if anyone could point me in the direction of a better
> solution altogether that would be great too.
Perl has features that support in-place editing for you. Let
perl do the administrative housekeeping stuff for you.
> I'm not a Perl expert sorry to say.
I don't think raklet is either.
> #----------------------------------------------------------
>
> sub doReplace
> {
> my @outLines; #Data we are going to output
> my $line; #Data we are reading line by line
>
> # Only parse files that end in .htm
> if ( $File::Find::name =~ /\.htm$/ )
> {
> print "\nprocessing $_\n";
>
> open (FILE, $File::Find::name ) or
> die "Cannot open file: $!";
>
> while ( $line = <FILE> )
> {
> $line =~ s/\.jsp$/.htm/i;
> $line =~ s/<jsp:setProperty.+\>//i;
^^
^^ should be non-greedy?
> $line =~ s/<jsp:useBean.+\>//i;
^
^ useless use of backslash
I am suspicious of programmers who don't know what needs
backslashing and what doesn't need backslashing...
> push(@outLines, $line);
> }
> close FILE;
>
> open ( OUTFILE, ">$File::Find::name" ) or
> die "Cannot open file: $!";
>
> print ( OUTFILE @outLines );
> close ( OUTFILE );
>
> undef( @outLines );
I am suspicious of programmers that don't know how scoping works...
> }
> }
My rewrite:
# untested!
sub doReplace {
return unless /\.htm$/; # save a level of indent
local @ARGV = $_; # load filename for inplace edit
local $^I = ''; # enable inplace editing. No backup!
while ( <> ) {
s/\.jsp$/.htm/i;
s/<jsp:setProperty.+?>//i;
s/<jsp:useBean.+?>//i;
print;
}
}
You can read up on Perl's variables such as @ARGV and $^I in:
perldoc perlvar
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 24 May 2004 20:02:57 -0700
From: krpotter@co.douglas.or.us (Kevin Potter)
Subject: Re: String search/match question
Message-Id: <64f69747.0405241902.12e5a8c8@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c8tgia$dm9$2@mamenchi.zrz.TU-Berlin.DE>...
> John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
> > Anno Siegel wrote:
> > >
> > > John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
> > > >
> > > > perl -le'
> > > > $_ =
> "abcdefg[extra]hijklmn[texas]opqrstuvwxYZabc[tex]defghijklmnopqrstuvwxyz";
> > > > /x(?=[^]]*\[)/ && print $-[0]
> > > > '
> > > > 37
> > >
> > > That fails when no "[" follows the valid "x".
> >
> > perl -le'
> > $_ =
> > "abcdefg[extra]hijklmn[texas]opqrstuvwYZabc[tex]defghijklmnopqrstuvwxyz";
> > /x(?=[^]]*(?:\[|$))/ && print $-[0]
> > '
> > 67
>
> Yup.
>
> Anno
Wow... for myself and other less regular expression savy folks, could
I get a step by step walk-thru of exactly what this expression is
saying:
/x(?=[^]]*(?:\[|$))/ && print $-[0]
Thank you....!
------------------------------
Date: 25 May 2004 03:17:01 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: String search/match question
Message-Id: <slrncb5eld.jpo.sholden@flexal.cs.usyd.edu.au>
On 24 May 2004 20:02:57 -0700, Kevin Potter <krpotter@co.douglas.or.us> wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c8tgia$dm9$2@mamenchi.zrz.TU-Berlin.DE>...
>> John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
>> > Anno Siegel wrote:
>> > >
>> > > John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
>> > > >
>> > > > perl -le'
>> > > > $_ =
>> "abcdefg[extra]hijklmn[texas]opqrstuvwxYZabc[tex]defghijklmnopqrstuvwxyz";
>> > > > /x(?=[^]]*\[)/ && print $-[0]
>> > > > '
>> > > > 37
>> > >
>> > > That fails when no "[" follows the valid "x".
>> >
>> > perl -le'
>> > $_ =
>> > "abcdefg[extra]hijklmn[texas]opqrstuvwYZabc[tex]defghijklmnopqrstuvwxyz";
>> > /x(?=[^]]*(?:\[|$))/ && print $-[0]
>> > '
>> > 67
>>
>> Yup.
>>
>> Anno
>
> Wow... for myself and other less regular expression savy folks, could
> I get a step by step walk-thru of exactly what this expression is
> saying:
>
> /x(?=[^]]*(?:\[|$))/ && print $-[0]
x -> match character 'x'
(?= ... ) -> zero-width positive lookahead assertion
[^]]* -> match zero or more characters which are anything except ']'
(?: ... ) -> grouping without capturing
\[|$ -> match either the character '[' or the end of the string.
So it matches an x for which there is no following ] unless a
[ is found first.
So if [] come in non-nested pairs it matches an x which isn't inside
such a pair of [].
--
Sam Holden
------------------------------
Date: Mon, 24 May 2004 18:15:10 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Using Cookies With Perl
Message-Id: <20040524181103.Q338@dishwasher.cs.rpi.edu>
On Mon, 24 May 2004, James Hunt wrote:
> Does anyone have a good web reference for setting up and accessing cookies
> with Perl?
perldoc CGI
or
http://www.perldoc.com/perl5.8.4/lib/CGI.html
Paul Lalli
------------------------------
Date: 24 May 2004 20:47:06 -0700
From: krakle@visto.com (krakle)
Subject: Re: Using Cookies With Perl
Message-Id: <237aaff8.0405241947.31017fb6@posting.google.com>
"James Hunt" <jameskorea2003@hotmail.com> wrote in message news:<d6udnXeKBqsK9y_dRVn-hQ@comcast.com>...
> Does anyone have a good web reference for setting up and accessing cookies
> with Perl?
>
> - James Hunt
This isn't a Perl question and has no excuse to be here.
Right on Tad?
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V10 Issue 6604
***************************************