[30091] in Perl-Users-Digest
Perl-Users Digest, Issue: 1334 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 5 11:09:45 2008
Date: Wed, 5 Mar 2008 08:09:06 -0800 (PST)
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, 5 Mar 2008 Volume: 11 Number: 1334
Today's topics:
Re: CGI file based logging <devnull4711@web.de>
Re: CGI file based logging <BLOCKSPAMfishfry@your-mailbox.com>
Re: CGI file based logging <devnull4711@web.de>
Re: CGI file based logging xhoster@gmail.com
Re: CGI file based logging <john@castleamber.com>
Re: Does LWP::UserAgent download images himanshu.garg@gmail.com
Re: evaluating shared rescources on remote system. <ramakrishnadeepak@gmail.com>
Re: FAQ 4.53 How do I manipulate arrays of bits? sheinrich@my-deja.com
new CPAN modules on Wed Mar 5 2008 (Randal Schwartz)
Re: Parsing natural language timestamps <peter@makholm.net>
Re: Rename File Using Strring Found in File? <m@rtij.nl.invlalid>
Re: Rename File Using Strring Found in File? <cartercc@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 05 Mar 2008 07:33:18 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: CGI file based logging
Message-Id: <636t5gF25rikvU6@mid.individual.net>
howa wrote:
>
> I have a CGI which is targeted to log some messages to a file, since
> Apache are running at multi-process, are there any modules which can
> handle file locking issue if I received many requests?
Why use a module? It's simple to implement with Perl's
file locking interface. See "perldoc -f flock".
use strict;
use warnings;
use Fcntl qw/:flock/;
open my $fh,'>>','file.log' or die $!; # open file
flock $fh,LOCK_EX or die $!; # lock file
print $fh "message\n" or die $!; # write file
close $fh or die $!; # close file
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: Tue, 04 Mar 2008 22:58:23 -0800
From: fishfry <BLOCKSPAMfishfry@your-mailbox.com>
Subject: Re: CGI file based logging
Message-Id: <BLOCKSPAMfishfry-967A6B.22582304032008@comcast.dca.giganews.com>
In article <636t5gF25rikvU6@mid.individual.net>,
Frank Seitz <devnull4711@web.de> wrote:
> howa wrote:
> >
> > I have a CGI which is targeted to log some messages to a file, since
> > Apache are running at multi-process, are there any modules which can
> > handle file locking issue if I received many requests?
>
> Why use a module? It's simple to implement with Perl's
> file locking interface. See "perldoc -f flock".
>
> use strict;
> use warnings;
>
> use Fcntl qw/:flock/;
>
> open my $fh,'>>','file.log' or die $!; # open file
> flock $fh,LOCK_EX or die $!; # lock file
> print $fh "message\n" or die $!; # write file
> close $fh or die $!; # close file
>
Of course in real life you don't want your cgi to die just because it
can't obtain a lock on the logfile. It should wait and retry, or just
return a normal response to the enduser. Losing a log message is less
important than servicing the enduser. Writing through a logging service
is the way to solve this issue in real world, high volume applications.
------------------------------
Date: Wed, 05 Mar 2008 08:25:59 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: CGI file based logging
Message-Id: <637088F25rikvU7@mid.individual.net>
fishfry wrote:
> In article <636t5gF25rikvU6@mid.individual.net>,
> Frank Seitz <devnull4711@web.de> wrote:
>>howa wrote:
>>>
>>>I have a CGI which is targeted to log some messages to a file, since
>>>Apache are running at multi-process, are there any modules which can
>>>handle file locking issue if I received many requests?
>>
>>Why use a module? It's simple to implement with Perl's
>>file locking interface. See "perldoc -f flock".
>>
>>use strict;
>>use warnings;
>>
>>use Fcntl qw/:flock/;
>>
>>open my $fh,'>>','file.log' or die $!; # open file
>>flock $fh,LOCK_EX or die $!; # lock file
>>print $fh "message\n" or die $!; # write file
>>close $fh or die $!; # close file
>
> Of course in real life you don't want your cgi to die just because it
> can't obtain a lock on the logfile. It should wait and retry, or just
> return a normal response to the enduser.
It is example code. The OP can do whatever he want
in case of an error.
> Losing a log message is less important than servicing the enduser.
It depends on the application.
> Writing through a logging service
> is the way to solve this issue in real world, high volume applications.
Yes, but in this case a simple solution may be more appropiate.
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: 05 Mar 2008 15:23:11 GMT
From: xhoster@gmail.com
Subject: Re: CGI file based logging
Message-Id: <20080305102312.945$ts@newsreader.com>
fishfry <BLOCKSPAMfishfry@your-mailbox.com> wrote:
> In article <636t5gF25rikvU6@mid.individual.net>,
> Frank Seitz <devnull4711@web.de> wrote:
>
> > howa wrote:
> > >
> > > I have a CGI which is targeted to log some messages to a file, since
> > > Apache are running at multi-process, are there any modules which can
> > > handle file locking issue if I received many requests?
> >
> > Why use a module? It's simple to implement with Perl's
> > file locking interface. See "perldoc -f flock".
> >
> > use strict;
> > use warnings;
> >
> > use Fcntl qw/:flock/;
> >
> > open my $fh,'>>','file.log' or die $!; # open file
> > flock $fh,LOCK_EX or die $!; # lock file
> > print $fh "message\n" or die $!; # write file
> > close $fh or die $!; # close file
> >
>
> Of course in real life you don't want your cgi to die just because it
> can't obtain a lock on the logfile. It should wait and retry, or just
> return a normal response to the enduser. Losing a log message is less
> important than servicing the enduser.
In that case, why bother locking at all?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: 5 Mar 2008 15:54:47 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: CGI file based logging
Message-Id: <Xns9A5864D71CAA9castleamber@130.133.1.4>
xhoster@gmail.com wrote:
[locking a log file]
> In that case, why bother locking at all?
Because you don't want to mess up your log file? There is a difference
between missing a log entry and a messed up log file.
--
John
http://johnbokma.com/
------------------------------
Date: Tue, 4 Mar 2008 22:23:52 -0800 (PST)
From: himanshu.garg@gmail.com
Subject: Re: Does LWP::UserAgent download images
Message-Id: <e73c2ce2-5d82-451b-9229-edae7ca5fe14@e10g2000prf.googlegroups.com>
On Mar 4, 7:19 pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> himanshu.g...@gmail.com wrote:
> > Will the following code alsodownloadthe images on
> >search.cpan.org, if any :-
>
> It will get whatever resource you ask it to get. If you ask for an HTML pa=
ge
> then it will get that HTML page, if you ask for a picture then it will get=
> that picture. It doesn't care about the different content types.
>
> jue
Thanks for the replies. I don't have to worry about unnecessary image
downloads now.
Will also check WWW::Mechanize and the documentation of LWP.
Thanks,
Himanshu.
------------------------------
Date: Tue, 4 Mar 2008 23:40:37 -0800 (PST)
From: deepak <ramakrishnadeepak@gmail.com>
Subject: Re: evaluating shared rescources on remote system.
Message-Id: <9a828e98-148c-4a79-889d-c1c66f0ca07c@d21g2000prf.googlegroups.com>
Basically i'm devoloping a tool as part of my project, that scans a
range of computers and tells if there are any vulnerabilities on the
remote machine.In this manner i hav to check for the dictionary
passwords.
For example i have to check if remote registry , remote telnet, remote
sshd..etc are accesible for this set of passwords.For this the only
thing i hav to do is just establish a connection for each of the
password. If the connection is established then the remote system is
vulnerable else not vulnerable.
In the same manner i want to test whether i can just connect to the
RDP service on the remote machine.
------------------------------
Date: Wed, 5 Mar 2008 00:52:49 -0800 (PST)
From: sheinrich@my-deja.com
Subject: Re: FAQ 4.53 How do I manipulate arrays of bits?
Message-Id: <33dc785b-c8d5-4dd0-b154-8a8be0f21309@h25g2000hsf.googlegroups.com>
On Mar 4, 7:14 pm, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "s" == sheinrich <sheinr...@my-deja.com> writes:
>
> s> On Mar 3, 10:12 pm, Uri Guttman <u...@stemsystems.com> wrote:
> >> >>>>> "bdf" == brian d foy <brian.d....@gmail.com> writes:
> >>
> bdf> In article
> bdf> <ca334bbf-a028-4179-bcac-6fe5105b1...@13g2000hsb.googlegroups.com>,
> bdf> <sheinr...@my-deja.com> wrote:
> >>
> >> >> On Feb 29, 9:03 pm, PerlFAQ Server <br...@stonehenge.com> wrote:
> >> >> <snip>
> >> >> > For example, this sets $vec to have bit N set if $ints[N] was set:
> >> >> >
> >> >> > $vec = '';
> >> >> > foreach(@ints) { vec($vec,$_,1) = 1 }
> >> >>
> >> and the code is wrong too.
>
> s> That depends on how you see it.
>
> huh? the code doesn't do what the comment says. and even if the comment
> were fixes, the example has bit offsets of only 1 and 0 so it will never
> touch any bits other than 1 (the second bit). it would be hard to find a
> use for that logic.
In my initial reply to the FAQ I've given a working example with
exactly the code you cited above.
It all depends on what the content of @ints is. In my eyes, not the
code is erroneous, but only the descriptive sentence.
It might be that someone has amended a formerly correct example. Maybe
someone with pack() on his mind.
>
> s> The use of vec() as a replacement for pack() on a ready list of bits
> s> has never occurred to me.
>
> s> Hence my 2nd example above with some distinct bit indices specified:
> s> my @ints = (5,0,2,4);
>
> but the CODE didn't have any indices other than 1 and 0. so it was
> useless as an example and it didn't even agree with the text. the whole
> thing is wrong.
>
The CODE didn't show the array to have only 1 and 0. It was only the
sentence that implied it. And the CODE implied that @ints should
contain something else.
As I said, it depends on your point of view.
steffen
------------------------------
Date: Wed, 5 Mar 2008 05:42:19 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Wed Mar 5 2008
Message-Id: <Jx8t6J.23Do@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Acme-ReturnValue-0.05
http://search.cpan.org/~domm/Acme-ReturnValue-0.05/
report interesting module return values
----
Apache2-ASP-1.36
http://search.cpan.org/~johnd/Apache2-ASP-1.36/
Perl extension for ASP on mod_perl2.
----
CPAN-Dependency-0.14
http://search.cpan.org/~saper/CPAN-Dependency-0.14/
Analyzes CPAN modules and generates their dependency tree
----
Catalyst-Plugin-AuthenCookie-0.02
http://search.cpan.org/~drolsky/Catalyst-Plugin-AuthenCookie-0.02/
Plugin for cookie-based authentication
----
Catalyst-View-Download-0.01
http://search.cpan.org/~gaudeon/Catalyst-View-Download-0.01/
----
Class-C3-Componentised-1.0002
http://search.cpan.org/~ash/Class-C3-Componentised-1.0002/
----
Class-ExtraAttributes-0.01
http://search.cpan.org/~elizabeth/Class-ExtraAttributes-0.01/
extra attributes for a class
----
Config-File-1.42
http://search.cpan.org/~gwolf/Config-File-1.42/
Parse a simple configuration file
----
DBIx-Class-Fixtures-1.000000
http://search.cpan.org/~mstrout/DBIx-Class-Fixtures-1.000000/
----
DBIx-Class-Fixtures-1.000001
http://search.cpan.org/~lsaunders/DBIx-Class-Fixtures-1.000001/
----
DBIx-Class-Fixtures-1.000002
http://search.cpan.org/~lsaunders/DBIx-Class-Fixtures-1.000002/
----
DateTime-Calendar-Discordian-0.9.5
http://search.cpan.org/~jaldhar/DateTime-Calendar-Discordian-0.9.5/
Perl extension for the Discordian Calendar
----
Decision-Depends-0.19
http://search.cpan.org/~djerius/Decision-Depends-0.19/
Perform actions based upon file dependencies
----
Devel-CheckLib-0.4
http://search.cpan.org/~dcantrell/Devel-CheckLib-0.4/
check that a library is available
----
Devel-NYTProf-Fixed-0.01
http://search.cpan.org/~akaplan/Devel-NYTProf-Fixed-0.01/
----
Devel-NYTProf-Fixed2-0.01
http://search.cpan.org/~akaplan/Devel-NYTProf-Fixed2-0.01/
----
Egg-Release-3.06
http://search.cpan.org/~lushe/Egg-Release-3.06/
Version of Egg WEB Application Framework.
----
File-SAUCE-0.24
http://search.cpan.org/~bricas/File-SAUCE-0.24/
A library to manipulate SAUCE metadata
----
GRID-Machine-0.088
http://search.cpan.org/~casiano/GRID-Machine-0.088/
Remote Procedure Calls over a SSH link
----
Gaim-Log-Parser-0.11
http://search.cpan.org/~mschilli/Gaim-Log-Parser-0.11/
Parse Gaim's Log Files
----
Ganglia-Gemtric-0.1
http://search.cpan.org/~fungus/Ganglia-Gemtric-0.1/
----
IO-Handle-Moose-0.0101
http://search.cpan.org/~dexter/IO-Handle-Moose-0.0101/
Moose reimplementation of IO::Handle with improvements
----
IP-Country-2.24
http://search.cpan.org/~nwetters/IP-Country-2.24/
fast lookup of country codes from IP addresses
----
KSx-Analysis-StripAccents-0.04
http://search.cpan.org/~sprout/KSx-Analysis-StripAccents-0.04/
Remove accents and fold to lowercase
----
LaTeX-Table-0.6.1
http://search.cpan.org/~limaone/LaTeX-Table-0.6.1/
Perl extension for the automatic generation of LaTeX tables.
----
Locale-Geocode-1
http://search.cpan.org/~diz/Locale-Geocode-1/
----
MIME-Charset-1.000
http://search.cpan.org/~nezumi/MIME-Charset-1.000/
MIME ??????????????
----
MojoMojo-0.999013
http://search.cpan.org/~mramberg/MojoMojo-0.999013/
A Catalyst & DBIx::Class powered Wiki.
----
NET-IPFilterSimple_V1.1
http://search.cpan.org/~senger/NET-IPFilterSimple_V1.1/
Perl extension accessing ipfilter.dat files the very simple way Warning: Please Update your Sources. Current Version fixed a very critical bug that prevents Program from working correctly.
----
NET-IPFilter_V1.1.2
http://search.cpan.org/~senger/NET-IPFilter_V1.1.2/
Perl extension for Accessing eMule / Bittorrent IPFilter.dat Files and checking a given IP against this ipfilter.dat IP Range. IT uses conversion from IP to long integers in Perl and afterwards compai
----
Net-OBEX-0.002
http://search.cpan.org/~zoffix/Net-OBEX-0.002/
implementation of OBEX protocol
----
Net-OBEX-FTP-0.001
http://search.cpan.org/~zoffix/Net-OBEX-FTP-0.001/
implemenation of OBEX File Transfer Profile
----
OOB-0.09
http://search.cpan.org/~elizabeth/OOB-0.09/
out of band data for any data structure in Perl
----
OOB-0.10
http://search.cpan.org/~elizabeth/OOB-0.10/
out of band data for any data structure in Perl
----
OpenResty-0.0.5
http://search.cpan.org/~agent/OpenResty-0.0.5/
General-Purpose Web Services for Web Applications
----
POE-Component-IRC-Plugin-CoreList-0.02
http://search.cpan.org/~bingos/POE-Component-IRC-Plugin-CoreList-0.02/
A POE::Component::IRC plugin that provides Module::CoreList goodness.
----
RDF-Trine-0.101
http://search.cpan.org/~gwilliams/RDF-Trine-0.101/
An RDF Framework for Perl.
----
RT-Action-LinearEscalate-0.06
http://search.cpan.org/~ruz/RT-Action-LinearEscalate-0.06/
will move a ticket's priority toward its final priority.
----
RT-Client-Console-0.0.6
http://search.cpan.org/~dams/RT-Client-Console-0.0.6/
Text based RT console
----
RT-Client-REST-0.34
http://search.cpan.org/~dams/RT-Client-REST-0.34/
talk to RT installation using REST protocol.
----
SVN-Notify-Config-0.0909
http://search.cpan.org/~jpeacock/SVN-Notify-Config-0.0909/
Config-driven Subversion notification
----
String-LCSS_XS-0.7
http://search.cpan.org/~limaone/String-LCSS_XS-0.7/
Find The Longest Common Substring of Two Strings.
----
Symbol-Approx-Sub-2.04
http://search.cpan.org/~davecross/Symbol-Approx-Sub-2.04/
Perl module for calling subroutines by approximate names!
----
WWW-CpanRecent_V1.0
http://search.cpan.org/~senger/WWW-CpanRecent_V1.0/
Perl extension for getting news from http://search.cpan.org/recent
----
WWW-Futurezone_V1.0
http://search.cpan.org/~senger/WWW-Futurezone_V1.0/
Perl extension for getting news http://futurezone.orf.at/
----
WWW-GameStar_V1.0
http://search.cpan.org/~senger/WWW-GameStar_V1.0/
Perl extension for getting news from Gamestar.de
----
WWW-GameStar_V1.1
http://search.cpan.org/~senger/WWW-GameStar_V1.1/
Perl extension for getting news from Gamestar.de
----
WWW-GameStar_V1.2
http://search.cpan.org/~senger/WWW-GameStar_V1.2/
Perl extension for getting news from Gamestar.de
----
WWW-Golem_V1.0
http://search.cpan.org/~senger/WWW-Golem_V1.0/
Perl extension for getting news from http://www.golem.de/
----
WWW-Heise_V1.0
http://search.cpan.org/~senger/WWW-Heise_V1.0/
Perl extension for getting news from heise.de
----
WWW-Heise_V1.1
http://search.cpan.org/~senger/WWW-Heise_V1.1/
Perl extension for getting news from heise.de
----
WWW-Heise_V1.2
http://search.cpan.org/~senger/WWW-Heise_V1.2/
Perl extension for getting news from heise.de
----
WWW-Lengthen-0.02
http://search.cpan.org/~ishigaki/WWW-Lengthen-0.02/
lengthen 'shortened' urls
----
WWW-Newsgrabber_V1.0
http://search.cpan.org/~senger/WWW-Newsgrabber_V1.0/
Perl extension for getting news from a general news site
----
WWW-Pcgames_V1.0
http://search.cpan.org/~senger/WWW-Pcgames_V1.0/
Perl extension for getting news http://www.pcgames.de/?menu=0001
----
WWW-Popurls_V1.0
http://search.cpan.org/~senger/WWW-Popurls_V1.0/
Perl extension for getting news from http://popurls.com/
----
WWW-Shorten-urlTea-0.01
http://search.cpan.org/~bgilmore/WWW-Shorten-urlTea-0.01/
Perl interface to urltea.com
----
WWW-Spiegel_V1.0
http://search.cpan.org/~senger/WWW-Spiegel_V1.0/
Perl extension for getting news http://www.spiegel.de/
----
WWW-Teamxbox_V1.0
http://search.cpan.org/~senger/WWW-Teamxbox_V1.0/
Perl extension for getting news http://www.teamxbox.com/
----
XML-OBEXFTP-FolderListing-0.002
http://search.cpan.org/~zoffix/XML-OBEXFTP-FolderListing-0.002/
parse OBEX FTP x-obex/folder-listing XML
----
XML-RSS-JavaScript-0.62
http://search.cpan.org/~bricas/XML-RSS-JavaScript-0.62/
serialize your RSS as JavaScript
----
Yahoo-Marketing-4.01
http://search.cpan.org/~shenj/Yahoo-Marketing-4.01/
an interface for Yahoo! Search Marketing's Web Services.
----
parent-0.220
http://search.cpan.org/~corion/parent-0.220/
Establish an ISA relationship with base classes at compile time
----
sys-0.1
http://search.cpan.org/~asksh/sys-0.1/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 05 Mar 2008 07:49:22 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: Parsing natural language timestamps
Message-Id: <87tzjlzk3h.fsf@hacking.dk>
"comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com> writes:
> A Date::Manip concoction could help if you're say, trying to normalize
> "today".
>
> If "today" is the --from:
>
> UnixDate(UnixDate(ParseDate("today"),"%b%e%Y")"%s)
But I'm not trying to normalize 'today', that is easy even without
using Date::Manip. I'm trying to handle anything the user would like
to write as a time.
More precisely I would like to have the start and end of whatever
fuzzy natural language timestamp the user would use. So I have to
figure out which precision the given timestamp has (a day, an hour, a
minute) and the return the a interval of 86400, 3600, or 60 seconds.
//Makholm
------------------------------
Date: Wed, 5 Mar 2008 09:02:39 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Rename File Using Strring Found in File?
Message-Id: <pan.2008.03.05.08.02.39@rtij.nl.invlalid>
On Wed, 05 Mar 2008 02:45:34 +0000, Ben Morrow wrote:
>> >>If you had used proper indentation, you would be able to see that
>> >>comments like this are completely useless.
>> >
>> >Not sure what you mean?
>
> If you write your code like this
>
> while (<>) {
> #lots of code
> #lots of code
> #lots of code
> #lots of code
> }
>
> then there is no need for any '#end while' comments: you can see it's
> the end of the while from the indentation. Any half-decent editor will
> find matching braces for you, as well. The comment just becomes noise
> that obscures the important bits of the code.
Also, if it really is "lots of code" you should put that code in subs.
The while loop instantly becomes much more readable:
while (<>) {
do_this();
do_that(param, param);
if (check_something(param)) {
log_error();
last;
}
remainder_of_processing();
}
HTH,
M4
------------------------------
Date: Wed, 5 Mar 2008 07:55:13 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Rename File Using Strring Found in File?
Message-Id: <5f1064ea-bfa0-4805-9e32-33ea49439774@s37g2000prg.googlegroups.com>
On Mar 3, 11:01 pm, He Who Greets With Fire
<Entwaduma...@HyenaKiller.com> wrote:
> I am trying to write a little script to access many files in folder,
> parse each file and then if a certain string is found, rename the file
> using a substring of that found string.
It's important that you follow a methodology that self-corrects itself
each step of the way. If you could post a sample of a file that you
want to look at, it would be easier to see what you want to do. Also,
the format of the file is important. I assume that you want to reat
ASCII files.
The first step would be as follows. I would recommend a very small
subset of files in the beginning, one having the string you want and
one not.
1. begin your file examination loop that iterates through all files
2. open each file (in turn)
3. print each line
4. close each file (in turn)
5. end the loop.
When you run this, you can redirect the output to a text file for your
convenience. This will show you EXACTLY what Perl sees and will match
to your regular expression. It will also form the logic for your
program. Once you get this working to your satisfaction, you can start
to match your regular expression.
> I have a file directory named E:/personalinjury. In the file directory
> are 821 files named from 1.htm to 821.htm
You want to run your script from this directory.
> I want to access each file in turn, and use a regex to parse the file
> contents to see if a string similar to this one is found in it:
> Citation: 20-333 Dorsaneo, Texas Litigation Guide =A7 333.103
> Some files will not have a string similar to the above string. I am
> not interesting in renaming those files.
What I would do (for starters, anyway) is this. Create a $counter.
Search each line for the string '333.nnn '. That is, a literal of two
3s followed by a digit followed by a literal period followed by three
digits and a space. If that string is found, rename the file like
this: 'TLG__33n_nnn_${counter}.txt' Obviously, if this string can be
found over multiple lines, you will have to fine tune your regex, but
I doubt that you will ever have a line break dividing a section
number, and I also doubt that you will have many false positives.
> Anyone got any ideas?
Yeah, do it a piece at a time and make sure the prior part works
perfectly before you take the next step. You don't want to do this
project is one fell swoop unless you have plenty of practice.
Also, post a piece of your source file so we can see what it looks
like.
CC
------------------------------
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 V11 Issue 1334
***************************************