[15931] in Perl-Users-Digest
Perl-Users Digest, Issue: 3344 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 13 14:15:42 2000
Date: Tue, 13 Jun 2000 11:15:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <960920121-v9-i3344@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 13 Jun 2000 Volume: 9 Number: 3344
Today's topics:
Reading Files <john@tcs-web.fsnet.co.uk>
Re: Simple Question ~ How to perform a directory recurs <kennylim@techie.com>
Re: Simulating a key press using PERL <rootbeer@redcat.com>
Re: smtpstats shel script to perl <rootbeer@redcat.com>
Re: sorting an array <blah@nospam.com>
Re: sorting an array <raphaelp@nr1webresource.com>
Re: web page and serial port <rootbeer@redcat.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Jun 2000 18:56:15 +0100
From: "John Leatherbarrow" <john@tcs-web.fsnet.co.uk>
Subject: Reading Files
Message-Id: <8i5suj$q41$1@newsg2.svr.pol.co.uk>
This is a multi-part message in MIME format.
------=_NextPart_000_0008_01BFD569.0CE6D500
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Ok,
I've written a script that reads in a html file and then outputs it =
again as part of a template.
This works fine if its a file on the same server
However it doesn't work if I want to read in a file from another =
location i.e. a URL
This is how I'm doing it
sub Prop
{
open (BODY, "template/prop.htt");
local($/) =3D undef;
$Body =3D <BODY>;
close(BODY);
}
$Body is then passed to the main template file and the contents of the =
prop.htt file are output.
If I want to use the URL eg www.tduncan.com/prop.htt this file does =
not exist in this location
then it doesn't work
HELP
------=_NextPart_000_0008_01BFD569.0CE6D500
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Ok,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I've written a script that reads in a =
html file and=20
then outputs it again as part of a template.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>This works fine if its a file on the =
same=20
server</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>However it doesn't work if I want to =
read in=20
a file from another location i.e. a URL</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>This is how I'm doing it</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>sub Prop<BR>{<BR>open (BODY,=20
"template/prop.htt");<BR>local($/) =3D undef;<BR>$Body =3D=20
<BODY>;<BR>close(BODY);<BR>}</FONT></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$Body is then passed to the main =
template file and=20
the contents of the prop.htt file are output.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>If I want to use the URL eg =
<A=20
href=3D"http://www.tduncan.com/prop.htt">www.tduncan.com/prop.htt</A> =
<EM>this=20
file does not exist in this location</EM></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>then it doesn't work</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D5><STRONG>HELP</STRONG></FONT></DIV></BODY></HTML>
------=_NextPart_000_0008_01BFD569.0CE6D500--
------------------------------
Date: Tue, 13 Jun 2000 10:17:48 -0700
From: "Kenny Lim" <kennylim@techie.com>
Subject: Re: Simple Question ~ How to perform a directory recursive search ?
Message-Id: <p%t15.48672$5k2.93874@dfw-read.news.verio.net>
Hi All,
First and foremost, I want to Thank You for all your time and advise in
regards to the
issue that I had submitted to the newsgroup.
Second of all, I apologize if I wasn't clear interms of describing the
actual problem.
My objective is rather simple here,..
(a) Search a given directory (including subdirectories) for the following
file extension.
.dsp
.def
.rc
.h
.cpp
(b) Search the contents of the file that matches the extension as above
on a given string. (ie. "productv10")
ie. to search for a matching strings "productv10" on all the files that met
the extension criteria in (a)
(c) Subsitute ALL matching "productv10" strings with "productv20" found.
(d) Save changes to the original file permanently. (Including the matches
files found in the subdirectories)
(e) Generate a report on the files and the strings that had been changed.
ie.
Found in File ETProj.dsp :
Before: TargetPath=\WorkReleaseUnicode\etproj50
After: TargetPath=\WorkReleaseUnicode\etproj60U.dll
===============================================================
(i) The only reason as to why I am using different methods to search the
directory
is because I am not too sure how to actually use the find:file
utilities to search
for only a given extension and not all the files in the entire
directories and subdirectories.
ie.
Use File::Find;
find sub {print "Found One: $File::Find::name\n" if !-d}, '.';
Questions: It would be very nice to know how to actually customize my sub
routine
to only search for only the extensions that I needed. (do you have sample
that I can abide to ?)
(ii) What would be the simplest methods to only save changes onto the
original files that only matches and subsitute the "productv10" to
"productv20" strings.
(Including the matching file found in subdirectories)
my code :
rename ($filename, "$filename.orig") or die "Can't rename`$filename': $!";
rename ($new_filename, $filename) or die "Can't rename `new_$filename': $!";
#As you can see, I am actually renaming all the files that matches the
extension criteria
and not the files that matches the string name. This would be inefficient.
(iii) Out of curiosity,..
The sample regular expression search strings that you gave me so far, yield
no results.
find /my/dir -regex '.*\.\(cpp\|dsp\|rc\)'
The following simple statement works but are only searching for one
extensions.
find d:/vss_test/etproject/ -regex '.*cpp' -print > result.log
$ find d:/vss_test/etproject/ -regex '.*cpp'
d:/vss_test/etproject/AddFilesDlg.cpp
d:/vss_test/etproject/BuildConfirmationDlg.cpp
Question : Is thre anything that I am missing in able to yield the results
that I needed.
Is there a way to run this in a script and not in the shell mode ?
Any advise would be greatly appreciated !
Thanks All and you have pleasant evening.
Kenny-
"Neil Kandalgaonkar" <nj_kanda@alcor.concordia.ca
<mailto:nj_kanda@alcor.concordia.ca>> wrote in message
<news:8i234d$udl$1@newsflash.concordia.ca>...
> In article <yBZ05.11109$907.272697@newsread2.prod.itd.earthlink.net
<mailto:yBZ05.11109$907.272697@newsread2.prod.itd.earthlink.net>>,
> Kenny Lim <kennylim@techie.com <mailto:kennylim@techie.com>> wrote:
>
> >(a) Is there a method to perform a directory recursive search (including
> >subdirectories) "without having to use the File::Find standard module" ?
> >(Snippets of my code is enclosed below)
>
> Why would you not want to use File::Find?
>
> Anyway, of course the answer is yes; you could simply reinvent what
> File::Find does, perhaps in a less generalized way.
>
> Or simply get the results of a 'find', if you are on unix.
>
>
> >(b) Is there a method to only change the name of the file only when a
> >criteria is met.
> >
> >Eg.
> >
> >Search for a matching strings called "old" and replace it with "new" in a
> >file with
> >*cpp *dsp *rc extension.
>
> I got confused. Are you trying to change the filename or alter the
contents?
> Your code opened a second filehandle. I didn't understand the comments you
> added after your code.
>
> Anyway, perl has a rename().
>
> Here's one way of modifying file *contents* which leans on shell tools
> rather than File::Find. (n.b. this is GNU find 4.1)
>
> $ find /my/dir -regex '.*\.\(cpp\|dsp\|rc\)' -print \
> | xargs perl -pi.bak -e 's/search/replace/g'
>
> This has the advantage of simplicity and safety. You'd have to do a lot
> of wheel-reinventing to get something safe like perl -pi.bak; it makes
> backups while modifying the file "in-place".
>
> If you just wanted to rename it:
>
> $ find /my/dir -regex '.*\.\(cpp\|dsp\|rc\)' -print \
> | perl -wlne '(my $new = $_) =~ s/search/replace/; rename $_, $new'
>
> See man find, and man perlrun for further explanation.
>
> Or, find a good intro to unix shell scripting if everything here is
> totally baffling to you.
>
> --
> Neil Kandalgaonkar
> neil@brevity.org <mailto:neil@brevity.org>
"Kenny Lim" <kennylim@techie.com> wrote in message
news:yBZ05.11109$907.272697@newsread2.prod.itd.earthlink.net...
>
> Hi All,
>
> I am just a beginner and are wondering :
>
> (a) Is there a method to perform a directory recursive search (including
> subdirectories) "without having to use the File::Find standard module" ?
> (Snippets of my code is enclosed below)
>
> (b) Is there a method to only change the name of the file only when a
> criteria is met.
>
> Eg.
>
> Search for a matching strings called "old" and replace it with "new" in a
> file with
> *cpp *dsp *rc extension.
>
> Any help would be greatly appreciated. Thanks All and you have a pleasant
> evening !
>
> Kenny-
>
>
> #Snippets of my code
>
> my $filename;
>
> #==================================#
> # Get list of specified Filename in the directory #
> #==================================#
>
> while (<*.dsp *.def *.rc *.h *.cpp>) # *.pl is used for test purposed
>
> #This method enable me to search for all the file with the following
> extension,
> #but I am not able to perform a search for the file within a
subdirectories.
>
> #If using the FIle:Standard module would be a better approach, do you know
> #how can I search the extension enclosed as above including the
> subdirectories then.
>
> #Either way is fine with me..
>
>
> {
>
> #print "$_\n";
> $filename = $_;
> OPEN_FILE ();
> print "$filename\n";
>
> }
>
> sub OPEN_FILE
> {
>
> $new_filename = $filename . ".new_ext";
>
> open(OLD_FILE, "< $filename") or die "Can't open `$filename': $!";
> open(NEW_FILE, "> $new_filename") or die "Can't open
> `$new_filename':$!";
> #select (NEW_FILE);
>
> while (<OLD_FILE>)
> {
> chomp;
> if (s/$search/$replace/i)
> {
> print "Found One !:\nBefore:$search After:$_\n";
> }
>
> print NEW_FILE "$_\n" or die "Can't write `$new_filename': $!";
>
> }
> close (OLD_FILE) or die "Can't close `$filename': $!";
> close (NEW_FILE) or die "Can't open `$new_filename': $!";
> rename ($filename, "$filename.orig") or die "Can't rename`$filename':
> $!";
> rename ($new_filename, $filename) or die "Can't rename `new_$filename':
> $!";
>
>
> # The problem is when I overwrite the old files with the new one, it also
> includes
> #all the files that matches the extensionc name criteria but "not" the
> matching strings
> #contents. (This is kinda inefficient,..I am thinking just removing all
the
> files at the end
> of the transaction)
>
>
> };
>
>
>
> Thanks in advance.
>
> Kenny-
>
>
>
>
>
------------------------------
Date: Tue, 13 Jun 2000 08:29:35 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Simulating a key press using PERL
Message-Id: <Pine.GSO.4.10.10006130828010.18837-100000@user2.teleport.com>
On Tue, 13 Jun 2000, Mike Rizzo wrote:
> Newsgroups: comp.lang.perl, comp.lang.perl.misc, comp.lang.perl.modules
If your news administrator still carries comp.lang.perl, please let him
or her know that that newsgroup has not existed since 1995. If you
have such an outdated newsgroup listing, you are probably missing out
on many other valid newsgroups as well. You'll be doing yourself and
many others a favor to use only comp.lang.perl.misc (and other valid
Perl newsgroups) instead.
> Is there a way to simulate a key press through perl.
Section eight of the FAQ has a question about "How do I do fancy stuff
with the keyboard/screen/mouse?" Does that answer your question?
> The situation is as follows, a piece of code runs and
> then it prompts the user with a Message box that needs
> to be cleared in order to continue. I would like to have
> the Perl code "press" the enter key so that the script
> can continue.
Do you want Expect.pm?
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 13 Jun 2000 08:23:50 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: smtpstats shel script to perl
Message-Id: <Pine.GSO.4.10.10006130823110.18837-100000@user2.teleport.com>
On Tue, 13 Jun 2000, Marshal Benton wrote:
> Has anyone located a perl script which
> does a similar job to the shell script
> smtpstats?
#!/usr/bin/perl
exec 'smtpstats';
:-)
If you're wishing merely to _find_ (as opposed to write) programs,
this newsgroup may not be the best resource for you. There are many
freeware and shareware archives which you can find by searching Yahoo
or a similar service. Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 13 Jun 2000 17:13:48 +0200
From: Marco Natoni <blah@nospam.com>
Subject: Re: sorting an array
Message-Id: <39464FAC.89D33CB7@nospam.com>
Eric,
Eric Bohlman wrote:
>> Ok stupid question time, what the heck is RTFM?
> Read The Free Manual.
^^^^
Is it just Christmas time again? :)
Best regards,
Marco
------------------------------
Date: Tue, 13 Jun 2000 17:24:30 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Re: sorting an array
Message-Id: <8i5jnr$il2$1@news.online.de>
or maybe easter? But then again not everyone celebrates easter so not
everyone will get it for free! :-)
Marco Natoni <blah@nospam.com> wrote in message
news:39464FAC.89D33CB7@nospam.com...
> Eric,
>
> Eric Bohlman wrote:
> >> Ok stupid question time, what the heck is RTFM?
> > Read The Free Manual.
> ^^^^
> Is it just Christmas time again? :)
>
>
> Best regards,
> Marco
------------------------------
Date: Tue, 13 Jun 2000 08:54:35 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: web page and serial port
Message-Id: <Pine.GSO.4.10.10006130851300.18837-100000@user2.teleport.com>
On Tue, 13 Jun 2000 ringo4269@my-deja.com wrote:
> Hi, Can someone tell me how to access the serial port from a web page
> on a local machine?
No; web pages aren't programs, and thus can't access the serial port.
What do you really want to do? Do you want to use a CGI program to write
to the serial port on the program's own machine? That's perhaps possible.
Do you want the program to access the serial port on a remote machine?
That's not likely to work without a lot of help from the remote machine.
But if you're writing a CGI program, you may want to search for the docs,
FAQs, and newsgroups about CGI programming, including reading
comp.infosystems.www.authoring.cgi. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
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 3344
**************************************