[30090] in Perl-Users-Digest
Perl-Users Digest, Issue: 1333 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 5 00:09:42 2008
Date: Tue, 4 Mar 2008 21:09:07 -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 Tue, 4 Mar 2008 Volume: 11 Number: 1333
Today's topics:
CGI file based logging <howachen@gmail.com>
Re: Crypt::CBC vs individual cipher module differs? <tlviewer@VISTAyahoo.com>
Re: Crypt::CBC vs individual cipher module differs? <tlviewer@VISTAyahoo.com>
Re: evaluating shared rescources on remote system. <ben@morrow.me.uk>
Re: FAQ 4.53 How do I manipulate arrays of bits? <bik.mido@tiscalinet.it>
Re: FAQ 4.53 How do I manipulate arrays of bits? <uri@stemsystems.com>
Re: FAQ 4.53 How do I manipulate arrays of bits? <brian.d.foy@gmail.com>
Re: grep in file and date process <glex_no-spam@qwest-spam-no.invalid>
Re: grep in file and date process <glex_no-spam@qwest-spam-no.invalid>
Re: help with LWP and log in after redirect <eatmoreoats@gmail.com>
Latest XML Parsing/Memory Benchmark <crackeur@comcast.net>
Perl, Apache and Certificates am500803@gmail.com
Re: Perl, Apache and Certificates <smallpond@juno.com>
Re: php vs perl for RDBMS backend work <cartercc@gmail.com>
Re: Rename File Using Strring Found in File? <tadmc@seesig.invalid>
Re: Rename File Using Strring Found in File? <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 4 Mar 2008 19:59:53 -0800 (PST)
From: howa <howachen@gmail.com>
Subject: CGI file based logging
Message-Id: <09854ad7-d4ce-444f-a656-4c71ec3ada85@s12g2000prg.googlegroups.com>
Hello,
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?
Howard
------------------------------
Date: 05 Mar 2008 00:31:35 GMT
From: Mark Pryor <tlviewer@VISTAyahoo.com>
Subject: Re: Crypt::CBC vs individual cipher module differs?
Message-Id: <47cde9e7$0$16681$4c368faf@roadrunner.com>
On Sun, 02 Mar 2008 16:01:42 -0800, Waylen Gumbal wrote:
> I noticed that if I use a "CBC compatible" crypt module directly, I get
> a normal expected result. But if I use CBC with the same cipher type on
> the same key and plaintext I get a completely different result.
>
> I've been up and down the perldoc for Crypt::CBC and just can't figure
> out why the results differ so much. Because they differ so much you
> can't use one method to decrypt the other.
>
> For example:
>
> use Crypt::CBC;
> use Crypt::OpenSSL::AES;
>
> $key = 'secretpassphrase';
> $text = 'Crypt Test #0001';
>
> my $en1 = new Crypt::OpenSSL::AES($key)->encrypt($text);
>
> my $en2 = new Crypt::CBC(
> -key => $key, -cipher => 'Crypt::OpenSSL::AES'
> )->encrypt($text);
>
> my $en1h = unpack('H*', $en1);
> my $en2h = unpack('H*', $en2);
>
> print "OpenSSL AES\n[$en1h]\n\n";
> print "AES via CBC\n[$en2h]\n\n";
>
>
> __OUTPUT__
> OpenSSL AES
> [e1f461cdc00f4855b9b2c0367cd3a293]
>
> AES via CBC
>
[53616c7465645f5f36dd0b8d9b84e278382b8cd329f7020b545c3595c239284d37d4e3dc2d6a2fc97d375675b793b357]
>
Waylen,
try -literal_key => 1,
that way you prevent CBC from hashing your key. I don't have the info at
hand, but I remember that for AES
blocklength = 128
and keysize is much longer than the 16 bytes from MD5 (used by CBC).
Further your key length should be controlled, not simply some string. You
can control by hashing outside of CBC and inline of your code.
--
Mark
------------------------------
Date: 05 Mar 2008 02:18:01 GMT
From: Mark Pryor <tlviewer@VISTAyahoo.com>
Subject: Re: Crypt::CBC vs individual cipher module differs?
Message-Id: <47ce02d9$0$4955$4c368faf@roadrunner.com>
On Sun, 02 Mar 2008 16:01:42 -0800, Waylen Gumbal wrote:
> I noticed that if I use a "CBC compatible" crypt module directly, I get
> a normal expected result. But if I use CBC with the same cipher type on
> the same key and plaintext I get a completely different result.
>
> I've been up and down the perldoc for Crypt::CBC and just can't figure
> out why the results differ so much. Because they differ so much you
> can't use one method to decrypt the other.
>
> For example:
>
> use Crypt::CBC;
> use Crypt::OpenSSL::AES;
>
Waylen,
I've never used the above module for AES, but I've used
Crypt::Rijndael with/without Crypt::CBC.
Rijndael allows key lengths of (16,24,32)
AES is the new name for Rijndael
--
Mark
------------------------------
Date: Wed, 5 Mar 2008 02:49:45 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: evaluating shared rescources on remote system.
Message-Id: <9be1a5-a92.ln1@osiris.mauzo.dyndns.org>
Quoth deepak <ramakrishnadeepak@gmail.com>:
> Thanx Ben.What i mean about 'remote desktop' is whether there is any
> perl module that can connect to the remote desktop server, like we
> connect to a sshd server using Net::SSH and execute a simple linux
> command.
What protocol are you trying to use? Again, if you mean RDP then I doubt
there is a module for it: it would be *extremely* difficult to remotely
drive a GUI-based protocol like RDP in any case.
Once you've worked out which protocol you are trying to connect with,
you can search CPAN as well as I can.
Ben
------------------------------
Date: Wed, 05 Mar 2008 00:47:27 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 4.53 How do I manipulate arrays of bits?
Message-Id: <vrnrs3po5brjgtijim2u5rd9heqdbogkqg@4ax.com>
On Tue, 04 Mar 2008 18:14:18 GMT, Uri Guttman <uri@stemsystems.com>
wrote:
>and even using it for select is not a good example since IO::Select is
>so much easier to use. only people like me who know select very well
>(over 20 years of coding with it in c and perl) use it directly.
Surely true, but so crankish sounding...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 05 Mar 2008 00:20:55 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 4.53 How do I manipulate arrays of bits?
Message-Id: <x7lk4ydnrs.fsf@mail.sysarch.com>
>>>>> "MD" == Michele Dondi <bik.mido@tiscalinet.it> writes:
MD> On Tue, 04 Mar 2008 18:14:18 GMT, Uri Guttman <uri@stemsystems.com>
MD> wrote:
>> and even using it for select is not a good example since IO::Select is
>> so much easier to use. only people like me who know select very well
>> (over 20 years of coding with it in c and perl) use it directly.
MD> Surely true, but so crankish sounding...
you would be cranky if you had to write event loops with the select api
(in any language). if you go further back it used to only support 32
handles as they used a single word for the bit maps! sysv created the
much better poll api and more recent kernels have much improved apis and
speed. and there is a new perl module called EV that can use any of
several kernel apis for select and friends. libevent (a c lib) can also
do that. so there is little reason to delve into raw select except for
those crazy or experienced enough. perl exposed select it its own style
because when larry wrote perl it was the only common api for this.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Tue, 04 Mar 2008 18:29:16 -0600
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.53 How do I manipulate arrays of bits?
Message-Id: <040320081829162608%brian.d.foy@gmail.com>
In article <x78x0zqzpr.fsf@mail.sysarch.com>, Uri Guttman
<uri@stemsystems.com> wrote:
> >> > $vec = '';
> >> > foreach(@ints) { vec($vec,$_,1) = 1 }
>
> and the code is wrong too.
damn it. I had it right in my tests then didn't update the text. I've
committed the fix.
Thanks,
------------------------------
Date: Tue, 04 Mar 2008 16:59:51 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: grep in file and date process
Message-Id: <47cdd468$0$40266$815e3792@news.qwest.net>
Mr_Noob wrote:
> my @clientlog;
> open(FILE, "< $xferlog") or die "Can't open $xferlog : $!";
open( my $log, '<', $xferlog) or die "...";
> while(<FILE>)
while ( <$log> )
> {
> next unless /put \/$client/;
> push (@clientlog, $_);
>
> }
> # Display last element
> my $lastclientlog = $clientlog[$#clientlog];
> print $lastclientlog;
> close FILE;
close $log;
if ( @clientlog ) { print $clientlog[-1], "\n"; }
else { print "Didn't find anything in $xferlog for $client.\n"; }
>
>
> This works great but i cannot get rid of this error in apache's log
> file:
>
> "Use of uninitialized value in print..." (line 10)
Your definition of 'works great' is a little off. :-)
------------------------------
Date: Tue, 04 Mar 2008 17:31:04 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: grep in file and date process
Message-Id: <47cddbb8$0$37688$815e3792@news.qwest.net>
J. Gleixner wrote:
> Mr_Noob wrote:
>> my @clientlog;
>> open(FILE, "< $xferlog") or die "Can't open $xferlog : $!";
> open( my $log, '<', $xferlog) or die "...";
>> while(<FILE>)
> while ( <$log> )
>> {
>> next unless /put \/$client/;
>> push (@clientlog, $_);
>>
>> }
>> # Display last element
>> my $lastclientlog = $clientlog[$#clientlog];
>> print $lastclientlog;
>> close FILE;
>
> close $log;
> if ( @clientlog ) { print $clientlog[-1], "\n"; }
Slight correction.. Since you didn't chomp(), you don't
need the newline.
if ( @clientlog ) { print $clientlog[-1]; }
> else { print "Didn't find anything in $xferlog for $client.\n"; }
>
>>
>>
>> This works great but i cannot get rid of this error in apache's log
>> file:
>>
>> "Use of uninitialized value in print..." (line 10)
>
> Your definition of 'works great' is a little off. :-)
------------------------------
Date: Tue, 4 Mar 2008 14:22:00 -0800 (PST)
From: eatmoreoats <eatmoreoats@gmail.com>
Subject: Re: help with LWP and log in after redirect
Message-Id: <b1824b56-2912-4b23-b9ee-3255a1f4d2bf@e10g2000prf.googlegroups.com>
On Mar 4, 11:05 am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quotheatmoreoats<eatmoreo...@gmail.com>:
>
>
>
> > I'm trying to automate the log in to a website, which I've done before
> > successfully with lwp. However in this case I'm having problems and
> > need some help. After posting the username/password, a redirect
> > occurs to a new url where the username and password have been encoded.
> > With post redirects enabled, I end up back at the log in page, rather
> > than following the redirect.
>
> > Here are the request and response headers, as observed with Firefox
> > plugins (HTTP LIve Headers, and Tamper Data). These are observed
> > during a successful login with my firefox browser.
>
> > REQUEST HEADER
>
> <snip>
> > Referer=http://www.mywebsite.com/newmywebsite/logon.aspx
> <snip>
>
> > RESPONSE HEADER
>
> > Status=Moved Temporarily - 302
> <snip>
> > Location=http://www.mywebsite.com/newmywebsite/somenewurl/
> > somenewscript.wotever?
> > cmd=login&username=YWR2YW5jZWludGVybmV0&password=c2FuaXR5
> <snip>
>
> > Notice the Location in the response - if I take that url and do a get
> > request on it, I'm logged in. However, I can't seem to get the code to
> > follow the redirect down this url path. If I disable redirects, and
> > grab the Location header value, it is Location=http://
> >www.mywebsite.com/newmywebsite/somenewurl/somenewscript.wotever?
> > cmd=login&username=null.
>
> So whatever LWP is sending, the server doesn't like it and doesn't
> accept it as a valid logon.
>
> > I'd like the script to just follow the redirect to the new location
> > but its not clear why thats not working. Any ideas how to make this
> > work ?
>
> > Here is the code example :
>
> > use HTTP::Cookies;
> > use LWP::UserAgent;
>
> > $ua = LWP::UserAgent->new;
> > $cookies = new HTTP::Cookies();
> > $ua->cookie_jar($cookies);
> > $ua->timeout(300);
> > $ua->requests_redirectable (['GET', 'HEAD', 'POST']);
>
> You shouldn't need this. requests_redirectable refers to the method used
> to follow the redirect, not the method the redirect is a reply to; and
> LWP treats 302 as 'GET this URL' rather than 'repeat the previous
> request with a different URL', in line with the behaviour of most (all?)
> actual browsers (this is strictly against the letter of the standard,
> but RFC2616 recognises that this is the actual implemented behaviour).
>
> > # step 1 - hit the login page first
> > $response = $ua->get('http://www.mywebsite.com/newmywebsite/
> > logon.aspx');
>
> > # step 2 - post in the username/password
> > $response = $ua->post('http://www.mywebsite.com/newmywebsite/
> > logonvalidate.aspx',
> > [
> > username=>"theusername",
> > password=>"thepassword",
> > ]
> > );
>
> This will not set the Referer header. I would recommend using
> WWW::Mechanize instead, which tries as hard as possible to emulate an
> actual browser.
>
> Ben
Hi Ben,
Thanks for the suggestion and I will give it a try. However, I did
actually try setting all of the other header key-value pairs in the
post request but without success.
Dom
------------------------------
Date: Tue, 4 Mar 2008 17:03:32 -0800
From: "jimmy Zhang" <crackeur@comcast.net>
Subject: Latest XML Parsing/Memory Benchmark
Message-Id: <YL6dndN26Ov4bFDanZ2dnUVZ_remnZ2d@comcast.com>
The latest benchmark results are now available using the latest Intel Core2
Duo processor. In summary, VTD-XML using JDK 1.6's server JVM achieved an
astonishing 120MB/sec sustained throughput per core on a Core2 Duo 2.5 GHz
processor.
* Parsing/Memory:
http://www.ximpleware.com/2.3/benchmark_2.3_parsing_only.html
* XPath Only: http://www.ximpleware.com/2.3/benchmark_2.3_xpath.html
* Parsing/XPath/Update:
http://www.ximpleware.com/2.3/benchmark_2.3_update.html
* Indexing/XPath/Update:
http://www.ximpleware.com/2.3/benchmark_2.3_indexing.html
------------------------------
Date: Tue, 4 Mar 2008 14:05:46 -0800 (PST)
From: am500803@gmail.com
Subject: Perl, Apache and Certificates
Message-Id: <6ddfb106-b3a4-44f9-a291-b461aac25af1@o77g2000hsf.googlegroups.com>
Hi !
I am using Apache2 with self-signed certificates. I also made client
certificates and everything is cool.
Of course, i am also using mod_ssl.
But somehow I cannot get DN of the certificate into perl CGI code. It
ought to be in an SSL... environment variables, but its not. If I set
SSLOptions in apache config to FakeAuth, I can see full certificate
description in access file, but yet not in a perl script. Do i need to
'use' some special library ?
No direct documentation provided nowwhere, so any hint is appreciable.
------------------------------
Date: Tue, 4 Mar 2008 15:07:28 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Perl, Apache and Certificates
Message-Id: <95adf012-aa9b-411f-94d4-23d38ce42da9@e25g2000prg.googlegroups.com>
On Mar 4, 5:05 pm, am500...@gmail.com wrote:
> Hi !
>
> I am using Apache2 with self-signed certificates. I also made client
> certificates and everything is cool.
> Of course, i am also using mod_ssl.
> But somehow I cannot get DN of the certificate into perl CGI code. It
> ought to be in an SSL... environment variables, but its not. If I set
> SSLOptions in apache config to FakeAuth, I can see full certificate
> description in access file, but yet not in a perl script. Do i need to
> 'use' some special library ?
> No direct documentation provided nowwhere, so any hint is appreciable.
In http.conf you should have:
SSLVerifyClient require (or 2)
SSLOptions +StdEnvVars
In the CGI check
$ENV{'SSL_CLIENT_DN'}
------------------------------
Date: Tue, 4 Mar 2008 19:53:27 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: php vs perl for RDBMS backend work
Message-Id: <db22baf0-2277-41dc-a391-5f9242bc63c3@n77g2000hse.googlegroups.com>
On Mar 3, 11:55 am, dcrunch...@aim.com wrote:
> So I need some real reasons as to why php is superior to perl.
> I got one so far: It has a more natural support for OO, which I agree.
So? OO is simply another way of organizing code. In many cases, OO
just gets in the way, as when you are dealing with a simply procedural
script. I write a lot of scripts for databases, in many cases taking
data from one database, manipulating it in some way, and writing it to
another database. It's simpler to do this with a script written in an
imperative style than one written in an object oriented style.
Languages are simply tools. When you use a tool, you use one most
suitable for the task at hand. PHP might be a better tool for your job
than Perl, but it won't be a better tool because it has more natural
support for OO development.
CC
------------------------------
Date: Tue, 4 Mar 2008 18:35:13 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Rename File Using Strring Found in File?
Message-Id: <slrnfsrqm1.qpm.tadmc@tadmc30.sbcglobal.net>
He Who Greets With Fire <Entwadumayla@HyenaKiller.com> wrote:
> On Tue, 4 Mar 2008 16:15:20 +0000, Ben Morrow <ben@morrow.me.uk>
> wrote:
>>Quoth He Who Greets With Fire <Entwadumayla@HyenaKiller.com>:
>>>
>>> OK, thanks, but the script does not seem to rename the files.
^^^^^^^
^^^^^^^
Eh?
>>> I added some troubleshooting code, most of which I commented out. I
>>> also moved a copy of the personalinjury folder and all its files
>>> inside the C:\Perl directory so it can access it directly.
>>
>>Don't do that. You can set the working directory from within your Perl
>>script using the chdir function. In any case, the working directory may
>>not be what you expect under Win32.
>>
>
> the directory/folder location is not a problem.
Exactly so. That is why you should not do that.
Your "current working directory" and the directory that your perl
executable are in are not the same thing.
The directory where your perl binary lives has no connection
whatsoever to accessing files so moving files under there
will not solve file accessing problems.
Your cwd is what matters with regard to filesystem access.
>>> #!/bin/perl
>>
>>Perl is *never* installed as /bin/perl.
>
> but it already works in that regard--the script executes
The fact that your script executes does not prove that perl
is installed as /bin/perl.
(Windows programs use some other mechanizm for associating files).
You should either use a place where perl is usually installed, eg:
#!/usr/bin/perl
or simply
#!perl
if you want to use command line switches, or even
(nothing)
leave that line out completely.
>>> #sleep 2;
Why do you think that calling sleep() will help with debugging?
>>> print "here I am! \n";
>>
>>Diagnostics like this are better given with warn, which will .a. print
>>them to STDERR, where they ought to be and .b. tell you where you are in
>>the script.
>
> Well, I'm not actually a programmer,
You will need to become a bit of a programmer if you hope to
write a bit of a program.
> just someone trying to do some
> organization of my files.
If you need some programming done, and you want to do it yourself,
then you are going to have to learn some programming.
> So, that issue is not a concern right now.
so the issue of how to debug programs should be of ultimate concern
right now, since now is when you have a program that you need to debug!
Error and warning messages should go on STDERR, not STDOUT.
>>> foreach my $file ( glob 'personalinjury/*.htm' ) {
>>>
>>> # print "here I am A \n";
The text of the debugging message should tell you where it is in
the program rather than requiring you to search in the program
to find where it is. It also give you a chance to examine the
data that you are operating on:
warn "processing '$file' inside the foreach loop\n";
>>> open my $PI, '<', $file or die "could not open '$file' $!";
>>>
>>> # print "here I am! B \n";
warn "succeeded in opening $file\n";
>>> while ( <$PI> ) {
>>> # print "\n inside whileloop";
warn "processing '$_' inside the while loop\n";
>>> I AM getting to this point here.
>>>
>>> next unless /Citation: [\d-]+.*([\d.]+)/;
>>>
>>> but I never get to this point here--apparently the regex never sees a
>>> match for the "Citation:" etc string.
Then you should modify the regex so that is sees a match for
the "Citation:" etc string.
To do that, you need to know *exactly* what the data looks like,
and you probably need to read some of the standard documentation
that covers regexes.
>>> Here is a screen shot of the typical file, with a red arrow pointing
>>> to the string in this particular file that I want to match.
>>> I do not know why the regex does not see a match, because it looks
>>> like it matches it???
>>>
>>> See here:
>>> http://img225.imageshack.us/img225/91/citationue2.jpg
>>
>>*DON'T* do that.
>
> Don't do what?
Don't post a screenshot. Your program is processing text, not graphics.
Don't post a URL and expect people to go follow it to find out what
you are talking about.
>>Had you done the right thing, and copy-pasted a small
>>section of the relevant file into your message,
Do post a copy-pasted section of the data into your message.
>> you would have found
>>that the file doesn't in fact contain the string 'Citation: whatever' at
>>all. It's an HTML file, so there is markup in there as well, and the
>>string may well be spread across several lines. Get into the habit of
>>looking at files in a text editor before you try parsing them with Perl.
>
> That is a good point.
Well duh.
When crafting a regular expression, it is *essential* to know *exactly*
what the data you are trying to match looks like.
> Here are two excerpts from the source html for a typical file in that
> folder:
>
>
><td class="toolbar" align=right valign=top width="1%"
> nowrap>Citation: </td>
><td class="toolbar" valign=top width="99%"><b>21-340 Dorsaneo, Texas
> Litigation Guide § 340.02</b></td>
If the data you want is in an HTML table, then you should use
a module that will process an HTML table for you, such
as HTML::TableExtract.
> Are the angle brackets special characters in perl so that they have to
> be backslashed inside the regex?
Yes, angle brackets are special characters in Perl, they mean
"less than" and "greater than" and whatnot.
No, angle brackets are not special characters in a regular
expression, so they do not need to be backslashed.
The Perl Language and the Regular Expression Language are different
languages, so the funny characters mean different things depending
on which language you are in.
> I wonder if this regex would work?
The way to answer that is to write a teeny tiny program
and *see* for yourself it it works or not.
>>> my $newfile = $1;
>>> rename $file, "$newfile.htm" or die "could not mv '$file' $!";
>>> print "\n renamed a file";
>>> sleep 1;
>>> last;
>>> }#end while
>>
>>If you had used proper indentation, you would be able to see that
>>comments like this are completely useless.
>
> Not sure what you mean?
Me either.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 5 Mar 2008 02:45:34 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Rename File Using Strring Found in File?
Message-Id: <e3e1a5-a92.ln1@osiris.mauzo.dyndns.org>
[please trim your quotations]
Quoth He Who Greets With Fire <Entwadumayla@HyenaKiller.com>:
> On Tue, 04 Mar 2008 11:13:44 -0600, He Who Greets With Fire
> <Entwadumayla@HyenaKiller.com> wrote:
> >On Tue, 4 Mar 2008 16:15:20 +0000, Ben Morrow <ben@morrow.me.uk>
> >wrote:
> >
> >>Diagnostics like this are better given with warn, which will .a. print
> >>them to STDERR, where they ought to be and .b. tell you where you are in
> >>the script.
> >
> >Well, I'm not actually a programmer, just someone trying to do some
> >organization of my files. So, that issue is not a concern right now.
The fact you don't consider yourself a programmer is irrelevant. You are
writing a program, and it will make your life easier if you do it
properly.
> >>*DON'T* do that.
> >
> >Don't do what?
Take screenshots of HTML files, rather than posting a sample.
<snip>
> >Here is another snippet that looks much more promising. The TITLE of
> >the html page. This is not the instance of "citation....etc" that I
> >was looking for, but now that I see it, it looks like a good candidate
> >for use as a filename:
> >
> ><title>Get a Document - by Citation - 21-340 Dorsaneo, Texas
> >Litigation Guide § 340.02</title>
Is this spread across two lines in the HTML file? If so, then reading
the file line-by-line with while (<>) will never give you a string that
matches your regex. You would be better off reading the whole file with
File::Slurp.
> >Are the angle brackets special characters in perl so that they have to
> >be backslashed inside the regex?
No. See perldoc perlreref: it lists all the special characters.
<snip>
> >>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.
> well, I changed the program quite a bit so as to be able to target a
> match with the title string shown above. And I am able to find the
> title string and extract the needed numbers, and I have been able to
> place those numbers in a string variable.
>
> BUT the problem is that the program crashes whenever I try to rename
> the file using the string that I extracted.
I seriously doubt it 'crashes'. That would be a serious bug in perl.
More likely, the rename fails for some reason and the program exits with
an error.
> this rename line below is what causes it to crash, so i commented it
> out:
> #rename $file, "$newfile.htm" or die "could not mv '$file' $!";
>
> But I cannot read what the error message says because the dos window
> just closes. Where can I read what was in the window before it
> crashed?
Open a cmd window yourself (Start / Run / cmd), cd into the appropriate
directory and run the script yourself with 'perl script.pl'. Then the
window won't go away.
> And how can I rename the file? What went wrong with the
> renaming?
Noone can tell that from here until you can see what the error message
said.
Ben
------------------------------
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 1333
***************************************