[23688] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5895 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 5 03:05:49 2003

Date: Fri, 5 Dec 2003 00:05:09 -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           Fri, 5 Dec 2003     Volume: 10 Number: 5895

Today's topics:
    Re: a question about memory management <usenet@morrow.me.uk>
    Re: Another sort question. <jwillmore@remove.adelphia.net>
    Re: any idea how to optimize this regex? (Tad McClellan)
    Re: any idea how to optimize this regex? (Malcolm Dew-Jones)
    Re: any idea how to optimize this regex? <usenet@morrow.me.uk>
    Re: any idea how to optimize this regex? <matthew.garrish@sympatico.ca>
    Re: any idea how to optimize this regex? <jwillmore@remove.adelphia.net>
    Re: any idea how to optimize this regex? (Malcolm Dew-Jones)
    Re: any idea how to optimize this regex? <usenet@morrow.me.uk>
    Re: Can you tell me how to change from regular Perl to  <tore@aursand.no>
    Re: foreach counter <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: foreach counter <bmb@ginger.libs.uga.edu>
    Re: Generating Day of Week in Pure Perl <debbiep@csse.monash.edu.au>
    Re: Generating Day of Week in Pure Perl <krahnj@acm.org>
        gui in perl <eddGallary2@hotmail.com>
    Re: gui in perl <jwillmore@remove.adelphia.net>
        how can I retrieve a file sent from an HTML form? <someone@somewhere.nb.ca>
    Re: how can I retrieve a file sent from an HTML form? (Sam Holden)
    Re: How to open a file from the end and read the last 1 <tore@aursand.no>
    Re: How to open a file from the end and read the last 1 <uri@stemsystems.com>
    Re: How to open a file from the end and read the last 1 (David)
    Re: Idiom for array index that I'm foreach'ing over? <tore@aursand.no>
    Re: Idiom for array index that I'm foreach'ing over? <bmb@ginger.libs.uga.edu>
    Re: In search of elegant code: is variable is within a  <bmb@ginger.libs.uga.edu>
    Re: My apologizes (Was: Descending sort) <bmb@ginger.libs.uga.edu>
    Re: My apologizes (Was: Descending sort) <colossus_NOSPAM_@freemail.it>
    Re: Newsgroup Searching Program <gerardlanois@netscape.net>
    Re: question about installation of GD::Text on cygwin ( <mgjv@tradingpost.com.au>
    Re: Search and Replace date string <josef.moellers@fujitsu-siemens.com>
        sorting file names <mixo@beth.uniforum.org.za>
    Re: trouble with DBI/CGI <jwillmore@remove.adelphia.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 5 Dec 2003 00:47:19 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: a question about memory management
Message-Id: <bqokin$bmo$1@wisteria.csv.warwick.ac.uk>


Konstantinos Agouros <elwood@agouros.de> wrote:
> Then I looked at the display of first sleep at the memory using ps (the
> whole thing on Linux). With the display of the second sleep I did this 
> again and saw that the same amount of memory is used.
> $a is local using my, so I expected that at least at the print in the main
> program $a should have been forgotten and the memory freed.

Under most OSen memory grabbed from the OS cannot be given back: that
is, a process will never shrink. The memory which is 'freed' is
instead put into a free pool inside the process from which new
requests will be granted: so you can use up to the same amount again
without any more being requested from the OS. Generally speaking, the
only way to cut your memory usage back down is to find a convenient
point to save state and re-exec yourself.

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


------------------------------

Date: Fri, 05 Dec 2003 05:52:19 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Another sort question.
Message-Id: <20031205005218.6702ba07.jwillmore@remove.adelphia.net>

On 3 Dec 2003 22:38:13 GMT
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> Mal <mpatt644@yahoo.com> wrote in comp.lang.perl.misc:
<snip>
> Please first fix the program so that it runs cleanly under strict
> and warnings, so we have a solid base to build on.  I'm pretty sure
> what you want can be done by simple modifications of your code, so
> the effort won't be lost.  At the moment, it is hard to tell what
> part of your program's behavior is intended and what is buggy.

Might I also add ...
perldoc -f sprinf
and
Date::Manip

I say this because the issue with your times is the format.  If you
reformat the times into something standard, then you'll be able to
compare the times better :-)

I'll leave it up to you (the OP) to find out which you prefer :-)

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Brain, n.:  The apparatus with which we think that we think.   --
Ambrose Bierce, "The Devil's Dictionary" 


------------------------------

Date: Thu, 4 Dec 2003 17:12:27 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: any idea how to optimize this regex?
Message-Id: <slrnbsvfqr.6n5.tadmc@magna.augustmail.com>

drejcicaREMOVE@volja.net <drejcicaREMOVE@volja.net> wrote:
> Hello. I've discovered that this regex is a bottleneck:
> 
> /(?:<!\-.*?>.*?){5}/sig
                       ^
                       ^

That "i" doesn't do anything. So why is it there?


> It tries to locate as many html comments 


What will it do when it comes across a comment like this:

   <!--  if A > B then  --> 

??


> in chunks of five which can
> make for quite some possibilities in longer files. Is there a way to
> optimize this or do you consider it to be simply poor practice? 


Attempting to use regexes to parse HTML is the poor practice.

Use a module that understands HTML data for processing HTML data.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 4 Dec 2003 16:23:58 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: any idea how to optimize this regex?
Message-Id: <3fcfd01e@news.victoria.tc.ca>

drejcicaREMOVE@volja.net wrote:
: Hello. I've discovered that this regex is a bottleneck:

: /(?:<!\-.*?>.*?){5}/sig

: It tries to locate as many html comments in chunks of five which can
: make for quite some possibilities in longer files. Is there a way to
: optimize this or do you consider it to be simply poor practice? 


First, there are html parses that may help do what ever you want to do,
but ignoring that for the moment...


First off, a comment does not end with >, it ends with --> (and starts
with <!-- so why not test for that correctly also)?

  <!--.*?-->

If you know the comments can't have > in them, then a character class 
would be quicker than .*?

  <!--[^>]*>

Next, I wonder why would you need to find comments in blocks of 5?

Even if you really wish to look for blocks of 5 comments at a time, the /g
says to do this globally, so it looks thru the entire file for all
possible combinations of 5 blocks (I didn't say that correctly) and I
suspect that is the biggest bottle neck.

I suspect you don't really want /g at all.

Also, the .*? is a potential bug, because it does not _prevent_ the re
from matching two (or more) comments at the place you intend to match a
single comment, it simply says "match no more than is necessary to get a 
match", so the regex engine could be trying combinations of multiple 
comments in an attempt to get a {5} /g match to work.

I'm not sure if the above _is_ a bug, but I can't say it isn't.  The 
character class I mentioned is not prone to this issue as it simply can't 
match past the > , but that assumes (as I mentioned) that the comments 
never use > .

Finally, /i is to ignore case, but nothing you look for uses case, so why
specify it (though I doubt that makes a difference here).




------------------------------

Date: Fri, 5 Dec 2003 00:58:23 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: any idea how to optimize this regex?
Message-Id: <bqol7f$bmo$2@wisteria.csv.warwick.ac.uk>


yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote:
> First off, a comment does not end with >, it ends with --> (and starts
> with <!-- so why not test for that correctly also)?
> 
>   <!--.*?-->
> 
> If you know the comments can't have > in them, then a character class 
> would be quicker than .*?
> 
>   <!--[^>]*>
> 
<snip>
>
> Also, the .*? is a potential bug, because it does not _prevent_ the re
> from matching two (or more) comments at the place you intend to match a
> single comment, it simply says "match no more than is necessary to get a 
> match", so the regex engine could be trying combinations of multiple 
> comments in an attempt to get a {5} /g match to work.

I'm somewhat thinking aloud here, but would

/ (?: <!-- (?: [^-] (?!->) )* --> ){5} /x

perform the correct match here? The generalisation of [^>]: ie. 'match
anything up to this multi-character string' is something one quite
often wants.

Ben

-- 
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks]         ben@morrow.me.uk


------------------------------

Date: Thu, 4 Dec 2003 20:20:55 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: any idea how to optimize this regex?
Message-Id: <g4Rzb.13997$zf2.1535226@news20.bellglobal.com>


"Malcolm Dew-Jones" <yf110@vtn1.victoria.tc.ca> wrote in message
news:3fcfd01e@news.victoria.tc.ca...
>
> First off, a comment does not end with >, it ends with --> (and starts
> with <!-- so why not test for that correctly also)?
>
>   <!--.*?-->
>

Html comments allow whitespace between the -- and > when you close a
comment, so you'd have to write that as:

<!--.*?--\s*>

Matt




------------------------------

Date: Fri, 05 Dec 2003 05:39:51 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: any idea how to optimize this regex?
Message-Id: <20031205003950.7043a734.jwillmore@remove.adelphia.net>

On Thu, 04 Dec 2003 22:53:02 GMT
drejcicaREMOVE@volja.net wrote:

> Hello. I've discovered that this regex is a bottleneck:
> 
> /(?:<!\-.*?>.*?){5}/sig
> 
> It tries to locate as many html comments in chunks of five which can
> make for quite some possibilities in longer files. Is there a way to
> optimize this or do you consider it to be simply poor practice? 

Poor practice :-)

Use one of the *many* HTML parsing modules that are available.
http://search.cpan.org/

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Never hit a man with glasses.  Hit him with a baseball bat. 



------------------------------

Date: 4 Dec 2003 22:56:00 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: any idea how to optimize this regex?
Message-Id: <3fd02c00@news.victoria.tc.ca>

Matt Garrish (matthew.garrish@sympatico.ca) wrote:

: "Malcolm Dew-Jones" <yf110@vtn1.victoria.tc.ca> wrote in message
: news:3fcfd01e@news.victoria.tc.ca...
: >
: > First off, a comment does not end with >, it ends with --> (and starts
: > with <!-- so why not test for that correctly also)?
: >
: >   <!--.*?-->
: >

: Html comments allow whitespace between the -- and > when you close a
: comment, so you'd have to write that as:

: <!--.*?--\s*>

Ah yes, and exactly why one should use the html parsing modules if
at all possible,

(I was looking at my xml book.  Xml comments have a more rigid comment
format, if I understand it correctly.)


------------------------------

Date: Fri, 5 Dec 2003 02:19:56 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: any idea how to optimize this regex?
Message-Id: <bqoq0c$gms$1@wisteria.csv.warwick.ac.uk>


"Matt Garrish" <matthew.garrish@sympatico.ca> wrote:
> 
> "Malcolm Dew-Jones" <yf110@vtn1.victoria.tc.ca> wrote in message
> news:3fcfd01e@news.victoria.tc.ca...
> >
> > First off, a comment does not end with >, it ends with --> (and starts
> > with <!-- so why not test for that correctly also)?
> >
> >   <!--.*?-->
> >
> 
> Html comments allow whitespace between the -- and > when you close a
> comment, so you'd have to write that as:
> 
> <!--.*?--\s*>

HTML (SGML) comments also allow whitespace after the '!', and anything
matching /--\s*--/ to appear within the body of the comment. What
browsers will accept is another matter... ;)

Ben

-- 
"If a book is worth reading when you are six,                * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis


------------------------------

Date: Fri, 05 Dec 2003 04:08:27 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Can you tell me how to change from regular Perl to Mod_perl
Message-Id: <pan.2003.12.05.02.11.19.33123@aursand.no>

On Thu, 04 Dec 2003 18:51:54 +0000, Picker Leon wrote:
>>> Do I just simple add a
>>> use mod_perl;
>>> then all my old perl program can work with mod_perl?

>> No.  Please read the documentation on http://perl.apache.org/ before
>> you continue asking.  There's even a document describing how to migrate
>> from CGI to mod_perl on that site.

> I still could not find it. There are 1.0 2.0 docutmens and tutorio but
> nothing as you said.

Yes it is.  Is it _really_ that hard to find it?  Go to the following
address and be sure to read most of the documentation provided there:

  http://perl.apache.org/docs/1.0/guide/index.html

When I was talking about migrating from CGI to mod_perl, I was referring
to the following document:

  http://perl.apache.org/docs/1.0/guide/porting.html

Description: "This chapter is relevant to both writing a new CGI script or
perl handler from scratch and migrating an application from plain CGI to
mod_perl."


-- 
Tore Aursand <tore@aursand.no>
"Time only seems to matter when it's running out." -- Peter Strup


------------------------------

Date: Thu, 4 Dec 2003 17:02:36 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: foreach counter
Message-Id: <cfloqb.8ee.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On 2003-12-04, Tad McClellan <tadmc@augustmail.com> wrote:
> Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> wrote:
>
>> foreach (@array) {
>> 	$_ .= "\n";
>> }
>> 
>> will ''unchomp'' the values in @array.
>
> For unchomp() you'd need a different loop body:
>
>    $_ .= $/;
>
>:-)

unchomp() and ''unchomp''() are two different subs.  ;-)

- --keith

- -- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/z9kXhVcNCxZ5ID8RAnSxAJ9EzDsga3m9GkpuJrYQvw1hCKxj7wCdGBeb
SJ4O1NC5QJpICOWfB874J1k=
=9tw6
-----END PGP SIGNATURE-----


------------------------------

Date: Thu, 4 Dec 2003 23:56:05 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: foreach counter
Message-Id: <Pine.A41.4.58.0312042343480.16464@ginger.libs.uga.edu>

On Thu, 4 Dec 2003, Tassos wrote:

> Is there a special var (like $_) which contains the number of the current loop?
> so instead of :
> foreach $i (1..$#array) {
>          $array[$i] = "0";
> 	print $i;
> }
>
> we can do :
>
> foreach (@array) {
> 	$_ = "0";
> 	print $x;	# where x should be equal to $i in the above example
> }

Hmmm, I had intended to be clever, but I'm afraid I'm just baffled,
because ...

>> cat -n qt
     1  #!/usr/local/bin/perl
     2  use strict;
     3  use warnings;
     4
     5  my @array = qw ( a b c );
     6
     7  {{
     8  my $i=0;
     9  sub rewind{$i=0}
    10  sub it(\@){$i>$#{$_[0]}?():($i,$_[0][$i++])}
    11  }}
    12
    13  while( my( $i, $it ) = it( @array ) ) {
    14          print "i: $i, it: $it\n";
    15  }

>> ./qt
i: 1, it: a
i: 2, it: b
i: 3, it: c


I expected $i to print as '0' first.  In fact ...

>> cat -n qt
     1  #!/usr/local/bin/perl
     2  use strict;
     3  use warnings;
     4
     5  my @array = qw ( a b c );
     6
     7  {{
     8  my $i=0;
     9  sub rewind{$i=0}
    10  sub it(\@){$i>$#{$_[0]}?():($i-1,$_[0][$i++])}
    11  }}
    12
    13  while( my( $i, $it ) = it( @array ) ) {
    14          print "i: $i, it: $it\n";
    15  }

>> ./qt
i: -1, it: a
i: 0, it: b
i: 1, it: c


Too much scotch?

Brad


------------------------------

Date: Fri, 05 Dec 2003 01:55:56 GMT
From: Deborah Pickett <debbiep@csse.monash.edu.au>
Subject: Re: Generating Day of Week in Pure Perl
Message-Id: <MARzb.980$hX1.31438@news.optus.net.au>

rev wrote:

> I have a date formatted like so MM/DD/YYYY (e.g. 12/01/2003) and I need
> to get the day of the week from this (Monday).  But, this is occurring
> on my hosting vendor so whatever does it needs to be pure Perl.

This works for any Gregorian Calendar day.  Apologies for the formatting; my
news client likes to wrap text and I can't be bothered turning off the
feature for one lousy post.  I'll leave it as an exercise for you to
extract the day, month and year from the string to pass to this function. 
If you know that the date is a valid one, you can omit the function body
from the first comment until "don't try this at home".

# weekday
# input: three scalar parameters: year, month (1-origin), day (1-origin).
# output: scalar from 0 to 6 representing Sunday to Saturday respectively.
#         returns undef if month or day is out of bounds or any input is
#         not integral.
sub weekday ($$$)
{
  my ($y,$m,$d) = @_;

  # Year must be made positive for modulus to work correctly.
  $y += 400 * (1 + abs int $y/400) if $y <= 0;

  # Return undef if anything is out of bounds.
  return undef if
    $y != int $y        or
    $m != int $m        or
    $d != int $d        or
    $m < 1 || $m > 12   or
    $d < 1 ||
       $d > [[31,28,31,30,31,30,31,31,30,31,30,31]
[31,29,31,30,31,30,31,31,30,31,30,31]] ->
      [ ((! ($y % 400) || ($y % 100)) && (! ($y % 4))) || 0 ][ $m-1 ];

  # The calculation. Don't try this at home, kids.
  (
    [[6,2,2,5,0,3,5,1,4,6,2,4],[6,2,3,6,1,4,6,2,5,0,3,5]] ->
      [ ((! ($y % 400) || ($y % 100)) && (! ($y % 4))) || 0 ][ $m-1 ]
    + $d
    + $y
    + int(($y-1)/4)
    - int(($y-1)/100)
    + int(($y-1)/400)
  ) % 7;
}

-- 
Debbie Pickett
http://www.csse.monash.edu.au/~debbiep
debbiep@csse.monash.edu.au


------------------------------

Date: Fri, 05 Dec 2003 06:52:01 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Generating Day of Week in Pure Perl
Message-Id: <3FD02AED.28AA1F2C@acm.org>

Deborah Pickett wrote:
> 
> [snip]
> 
> --
> Debbie Pickett
> http://www.csse.monash.edu.au/~debbiep
> debbiep@csse.monash.edu.au

A student of the demented Dr. Conway perhaps?  ;-)

BTW - in reference to your web page at: http://www.csse.monash.edu.au/courseware/cse2395/exercise/topic09.html

> 3. Perl provides two Unix commands for creating processes: fork
> clones the current process, so that two identical copies of the
> process are running (the only difference is in the value the fork
> function returns); exec completely replaces the current process
> with the specified program. Suggest how to implement the system
> function using fork and exec.

AFAIK fork is the only way to _create_ a process.  exec doesn't _create_ a process, it
replaces the currently running program with a different one but it is still the same process.

From _Advanced Programming in the UNIX(R) Environment_ by W. Richard Stevens, page 188

8.3   fork Function

      The <i>only</i> way a new process is created by the Unix kernel is when an existing process
      calls the fork function.



John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Fri, 05 Dec 2003 08:48:39 +1100
From: Edo <eddGallary2@hotmail.com>
Subject: gui in perl
Message-Id: <3FCFABB7.70507@hotmail.com>

Hello

I need to know if perl is ok for an interactive gui programming,

e.g. tasks I need to do are:
use a form on the desktop to run a perl script by mouse click, let perl
script variables use values from text boxes, create a chart with mouse
location indicated when moved on the x and y axis. add scroll function
to a chart, automate chart scale, display data from files on a spread 
sheet ...etc.

or should I look into java as well and if so, would both languages work
in connection with each other?
any light is appriciated

thanks



------------------------------

Date: Fri, 05 Dec 2003 07:02:48 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: gui in perl
Message-Id: <20031205020248.4cb13e0c.jwillmore@remove.adelphia.net>

On Fri, 05 Dec 2003 08:48:39 +1100
Edo <eddGallary2@hotmail.com> wrote:

> I need to know if perl is ok for an interactive gui programming,
<snip>

I've used Tk scripts without issue and find they are easier to deal
with than Java GUI's - but my opinion is biased :-)

There are many Tk module that you can incorporate into your script
that will speed development.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Fortune's Real-Life Courtroom Quote #52:  Q:  What is your name? 
A:  Ernestine McDowell. Q:  And what is your marital status? A:  
Fair. 


------------------------------

Date: Fri, 05 Dec 2003 04:20:10 GMT
From: "Guy" <someone@somewhere.nb.ca>
Subject: how can I retrieve a file sent from an HTML form?
Message-Id: <_HTzb.4937$IF6.237058@ursa-nb00s0.nbnet.nb.ca>

If the following HTML form is submitted to my perl script...

<input name='var3' value='test'>

 ...my Perl script can read that variable using the following code (assuming
I'm using the right library)

$var=param('var3');



But if the following HTML form is submitted to my Perl script...

<input name=fil type=file>

 ...how do I retrieve the contents of the file?



Thanks again,
Guy




------------------------------

Date: 5 Dec 2003 04:31:15 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: how can I retrieve a file sent from an HTML form?
Message-Id: <slrnbt02gj.58k.sholden@flexal.cs.usyd.edu.au>

On Fri, 05 Dec 2003 04:20:10 GMT, Guy <someone@somewhere.nb.ca> wrote:
> If the following HTML form is submitted to my perl script...
> 
><input name='var3' value='test'>
> 
> ...my Perl script can read that variable using the following code (assuming
> I'm using the right library)
> 
> $var=param('var3');
> 
> 
> 
> But if the following HTML form is submitted to my Perl script...
> 
><input name=fil type=file>
> 
> ...how do I retrieve the contents of the file?

The way the documentation of the library you are using tells you to.


-- 
Sam Holden


------------------------------

Date: Fri, 05 Dec 2003 04:08:27 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: How to open a file from the end and read the last 100 lines
Message-Id: <pan.2003.12.05.02.14.47.328769@aursand.no>

On Thu, 04 Dec 2003 18:05:50 +0000, Uri Guttman wrote:
>> I am writing some Perl script to check some patterns errors in an
>> alert log (Oracle alert log).  The file can't get quite large.
>> Therefore I would like write a Perl script that runs every day via at
>> and opens the file from the end to read the last 100 lines. How can I
>> do this?

> use File::ReadBackawards ;

*bzzzt*  Should be 'File::ReadBackwards'.


-- 
Tore Aursand <tore@aursand.no>
"Fighting terrorism is like being a goalkeeper. You can make a hundred
 brilliant saves but the only shot that people remember is the one that
 gets past you." -- Paul Wilkinson


------------------------------

Date: Fri, 05 Dec 2003 04:03:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How to open a file from the end and read the last 100 lines
Message-Id: <x7wu9bykqj.fsf@mail.sysarch.com>

>>>>> "TA" == Tore Aursand <tore@aursand.no> writes:

  TA> On Thu, 04 Dec 2003 18:05:50 +0000, Uri Guttman wrote:
  >>> I am writing some Perl script to check some patterns errors in an
  >>> alert log (Oracle alert log).  The file can't get quite large.
  >>> Therefore I would like write a Perl script that runs every day via at
  >>> and opens the file from the end to read the last 100 lines. How can I
  >>> do this?

  >> use File::ReadBackawards ;

  TA> *bzzzt*  Should be 'File::ReadBackwards'.

bah!

it is a module that tells you who won awards in reverse order! :)

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: 4 Dec 2003 23:13:26 -0800
From: diberri@yahoo.com (David)
Subject: Re: How to open a file from the end and read the last 100 lines
Message-Id: <31b26f4.0312042313.4ea6a9@posting.google.com>

rui.vilao@rocketmail.com (Rui Vilao) wrote:

> I am writing some Perl script to check some patterns errors in an
> alert log (Oracle alert log).  The file can't get quite large.
> Therefore I would like write a Perl script that runs every day via at
> and opens the file from the end to read the last 100 lines. How can I
> do this?
> Any help/suggestion is highly appreciated. 

I believe File::Tail is well-suited to this task.

- David


------------------------------

Date: Fri, 05 Dec 2003 03:00:15 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <pan.2003.12.04.16.16.56.509801@aursand.no>

On Thu, 04 Dec 2003 07:42:42 -0800, Tim Shoppa wrote:
> Is there some magical variable like $. for array loops?

No.  You say that you've been programming Fortran, and you're saying - at
the same time - that you're too lazy to write the following code?

  my $i = 0;
  foreach ( @array ) {
      $_ . ' at position ' . $i . "\n";
      $i++;
  }

Crazy. :-)


-- 
Tore Aursand <tore@aursand.no>
"Out of missiles.  Out of bullets.  Down to harsh language." -- Unknown


------------------------------

Date: Thu, 4 Dec 2003 23:10:18 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <Pine.A41.4.58.0312042302440.16464@ginger.libs.uga.edu>

On Thu, 4 Dec 2003, Anno Siegel wrote:
> If you can't avoid parallel lists, I see something like
>
>     for ( map [ $_, shift @yy], @xx ) {
>         my ( $x, $y) = @$_;
>         print "x: $x, y: $y\n";
>         # here we go
>     }
>
> which is slightly obscure and partially destructive.  Maybe an indexed
> approach is okay for a ten-liner.

Here's one non-destructive version:

my %h;
@h{@xx}=@yy;
for ( map [ $_, $h{$_}], @xx ) {
    my ( $x, $y) = @$_;
    print "x: $x, y: $y\n";
}

Here's another.  :-)

{{
my $i=0;
sub rewind{$i=0}
sub eAch(\@\@){$i>$#{$_[0]}&&$i>$#{$_[1]}?():($_[0][$i],$_[1][$i ++])}
}}

while( my( $x, $y ) = eAch( @xx, @yy ) ) {
    print "x: $x, y: $y\n";
}


Regards,

Brad


------------------------------

Date: Thu, 4 Dec 2003 21:46:42 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <Pine.A41.4.58.0312042145030.16464@ginger.libs.uga.edu>

On Wed, 3 Dec 2003, Malcolm Dew-Jones wrote:

> David Filmer (IneverReadAnythingSentToMe@hotmail.com) wrote:
> :    if (1 < $foo && $foo < 10) {blah blah...
> : or is there a more elegant way to write it?
>
> sub is { my $number = shift; bless \$number , 'Hairy' }
>
> sub Hairy::between
> {   my ($nref,$lo,$hi) = @_;
>     return ($lo < $$nref and $$nref < $hi);
> }
>
> my $foo = 5;
>
> if ( is($foo)->between(1,10) )
> {
>     print "Yes!";
> }

I am not worthy.

Brad


------------------------------

Date: Thu, 4 Dec 2003 21:49:34 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: My apologizes (Was: Descending sort)
Message-Id: <Pine.A41.4.58.0312042147180.16464@ginger.libs.uga.edu>

On Thu, 4 Dec 2003, Helgi Briem wrote:

> On Thu, 04 Dec 2003 12:46:10 +0100, Colossus
> <colossus_NOSPAM_@freemail.it> wrote:
>
> >I realized that my example was not clear.
> >I apologize toward all who replied me. The problem
> >was mine. An alphabetical order was needed on first column.
> >Please accept my deepest apologizes.
> >
> >I have appreciated the answers given by all of you,
> >in particular the one of Anno who solved my problem.
>
> It's pretty late for that after having insulted almost
> everyone who might have a shot at solving your
> problem.  Most of them have already killfiled you
> and will never see anything you post, ever again.
>
> Such is life.

Godzilla was a colossus as I recall.

Perhaps I'm wrong.

Regards,

Brad


------------------------------

Date: Fri, 05 Dec 2003 07:58:42 +0100
From: Colossus <colossus_NOSPAM_@freemail.it>
Subject: Re: My apologizes (Was: Descending sort)
Message-Id: <bqpa84$25175g$1@ID-154800.news.uni-berlin.de>

Ben Morrow wrote:

>by the rules of social interaction generally accepted in clpmisc. In case >
> you are unfamiliar with these, they include 'If you ask a stupid/unclear
> question you must expect harsh words in response; you must not take
> these to heart.'.

Be harshing is not polite, as the netiquette says. Please read it.

> They also include 'Moralising is in general only acceptable from
> regulars who have proved they have something of worth to contribute to
> the group.'. (I realise I may be putting myself on the line here, but
> I'll risk that... :)

YOUR rules are unsocial and creates problem. This thread is the
demonstration of thinking like you. Respect and politeness are the base of
good society. Again ,PLEASE, read the netiquette.

> Useful, helpful and knowledgable people join relatively infrequently and
> leave even less so.

Ok, another opinion.

> These hypothetical 'others' are unlikely to be in a position to give
> you as much useful help as Anno and the other regulars.

Again another one.
-- 
Bye,
Colossus



------------------------------

Date: Fri, 05 Dec 2003 04:43:01 GMT
From: Gerard Lanois <gerardlanois@netscape.net>
Subject: Re: Newsgroup Searching Program
Message-Id: <usmjzswmh.fsf@netscape.net>

Ben Morrow <usenet@morrow.me.uk> writes:

> Gerard Lanois <gerardlanois@netscape.net> wrote:
> > my $absolute_datetime = time2str(
> >                                  "%Y-%m-%d %X", 
> >                                  str2time($date),
> >                                  "GMT"));
> > 
> > strtime is in the module Date::Parse, and time2str is in the
> > module Date::Format.
> > 
> > This absolute date format can be sorted lexicographically.
> 
> Isn't it easier just to sort the epoch times from str2time directly?

Yes.

I neglected to mention I store my headers in a MySQL database, and
that is the format MySQL expects.

-Gerard


------------------------------

Date: 05 Dec 2003 04:18:59 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: question about installation of GD::Text on cygwin (could be a Makefile q)
Message-Id: <slrnbt01pm.2sd.mgjv@verbruggen.comdyn.com.au>

On 4 Dec 2003 08:21:32 -0800,
	Upstart <stimonyhall@netscape.net> wrote:
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnbsq4d3.5j7.mgjv@verbruggen.comdyn.com.au>...
>  
>> Just for the heck of it, could you do something like:
>> 
>> $ cd /tmp
>> $ h2xs -ACXn Foo
>> Writing Foo/Foo.pm
>> Writing Foo/Makefile.PL
>> Writing Foo/README
>> Writing Foo/test.pl
>> Writing Foo/MANIFEST
>> $ cd Foo
>> [edit Makefile.PL and put "use GD;" near the top]
>> $ perl Makefile.PL
> 
> This breaks!
> 
> $ h2xs -ACXn Foo
[snip]
> $ cat Makefile.PL 
> use 5.008002;
> use ExtUtils::MakeMaker;
> use GD;  # jim add
> # See lib/ExtUtils/MakeMaker.pm for details of how to influence
> # the contents of the Makefile that is written.
> WriteMakefile(
>     NAME              => 'Foo',
>     VERSION_FROM      => 'lib/Foo.pm', # finds $VERSION
>     PREREQ_PM         => {}, # e.g., Module::Name => 1.1
>     ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
>       (ABSTRACT_FROM  => 'lib/Foo.pm', # retrieve abstract from module
>        AUTHOR         => 'Foo <foo@familiehaase.de>') : ()),
> );
> 
> $ perl Makefile.PL 
> Checking if your kit is complete...
> Looks good
> 

Hmmm. Looks like there's something that's odd with the way GD works in
this environment.

> $
> 
> Silent failure to create a Makefile.
> 
>> If that breaks, then the problem is somewhere in the interaction
>> between GD and MakeMaker, and that's probably worth a bug report to
>> either P5P of Lincoln Stein.
> 
> What would be the most effective way to proceed? It is a bummer the
> way this thing is not throwing some kind of error message. Is there a
> debug switch somewhere?

I'll have a look to see whether I can reproduce it in my environment.
I haven't actually got 5.8.2 installed yet, but I should. If the same
happens here (non-cygwin) I'll submit a bug report. If not, I'll get
back here, and someone with cygwin shuld probably try to figure ut
what the story is.

> Is there anybody out there who has my combination of a platform (win
> 2000, perl 5.8.2, cygwin) that has got this to work recently?

Martien
-- 
                        | 
Martien Verbruggen      | If at first you don't succeed, destroy all
Trading Post Australia  | evidence that you tried.
                        | 


------------------------------

Date: Fri, 05 Dec 2003 08:55:36 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Search and Replace date string
Message-Id: <3FD039F8.6B745F39@fujitsu-siemens.com>

Sharif Islam wrote:
> =

> I have some date strings like this:
> a)09/1998-/
> b)/1998-/
> c)02/1997-/
> d)03/2001-07/2003
> e)02/1997-/;02/1998-/
> =

> I would like to change (a) type strings to mm/yyyy-Present.
>                   (b) type strings to yyyy-Present (get rid of first '/=
')
>     and so on.
>                   (e) leave alone.

I'd try a structural approach:

1 split line on ;
2 split results of 1 on -
3 check whether 2nd field of 2 is empty, if so, replace by Present
4 join using -
5 join using ;

HTH,

Josef
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


------------------------------

Date: Fri, 05 Dec 2003 09:54:20 +0200
From: mixo <mixo@beth.uniforum.org.za>
Subject: sorting file names
Message-Id: <bqpdjd$86k$1@ctb-nnrp2.saix.net>

I have file name that have a prefix "t-", which
is followed by a number (integer), like
   t-1
   t-2
   t-3
   t-10
   t-21
   and so on.

How can I sort this in numeric order? This avoid a situation
where I get:
     t-1
     t-10
     t-2
     t-21
     t-3
     and so on.

So I far have the following which suffers from the above symptom:
++++++++++++
#!/usr/bin/perl -w
opendir THISDIR, "." or die "serious dainbramage: $!";
@allfiles = readdir THISDIR;
@allfiles = sort @allfiles;
#@allfiles = reverse @allfiles;
 

closedir THISDIR;
print "@allfiles\n";
++++++++++++



------------------------------

Date: Fri, 05 Dec 2003 05:27:48 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: trouble with DBI/CGI
Message-Id: <20031205002747.2e8b8d14.jwillmore@remove.adelphia.net>

On 4 Dec 2003 12:27:28 -0800
genericax@hotmail.com (Sara) wrote:
> James Willmore <jwillmore@remove.adelphia.net> wrote in message
> news:<20031130175409.7c3f2cc7.jwillmore@remove.adelphia.net>...
> > On 30 Nov 2003 07:06:53 -0800
> > genericax@hotmail.com (Sara) wrote:
> > > altalingua@hotmail.com (David Morel) wrote in message
> > > news:<60c4a7b1.0311292116.670c439f@posting.google.com>...
> >  <snip>
> > > I've found with DBI, many errors DON'T get to the browser, but
> > > the SQL fails. In those cases, the log file always captures
> > > them. This is particularly true for incorrect SQL statements.
> > 
> > Because of improper use of the module :-)  You *need* to code so
> > that errors from DBI calls *are* reported.  For example:
> > 
> > my $dbh = DBI->connect('dbi:ODBC:mydb', 'user', 'pass')
> >     or die "Connection failed: ", $DBI::errstr,"\n";
> > 
> > The error *will* show in the web server's error log (at least
> > Apache will do such trival things - not sure about IIS).  And, it
> > *will* show in the browser, just like other errors, if you use
> > CGI::Carp(importing 'fatalsToBrowser').

Just take note of the example - no SQL is involved - we want to see if
we can *connect* to the datasource.  You would like to know that
first, right?

<snip> 
> Not so fast Mogambo aka Mister Jim. Unless you want to check the
> error status of every single query, which is wasteful in more ways
> than one, its much simpler to log the errors and botta-bing "there's
> your problem".

Define "wasteful".  If this were COBOL, I could understand.  It *is*
wasteful in COBOL to do things like check to see if a file exists or
was opened, etc., etc. - because JCL will do the task with less code
and resources.  But ... this is Perl :-)  So, you'll have to explain
to me *why* it's wastful to check for errors.

In fact, you're doing double duty with using a log to log errors to. 
How do you maintain the log (or logs - because if you apply this
principle to *each* script that uses DBI, you'll have more than *one*
log I presume)?  How about rotation of the log(s)?  Hum ... I guess
you didn't think of that one, eh?  Now you'll have to write a script
to take care of this newly added log(s) - or the log(s) will overrun
the filesystem over time.

And - What's wrong with the *server's* log?  *All* errors will get
logged to the server's log - *if* you code properly.

> 
> Even with "Errors Raised", failed SQL statements don't result in a
> fatal error,  Therefore "FatalsToBrowser" does nothing in those
> cases unless you explicitly die or croak as you did above. I'd
> rather ensure my SQL statements are correct by construction rather
> than error-check everytime I issue one, wasting code and resources.
> Talk about code bloat! ack.. I mean really..

True - not all errors with a *query* will result in an *fatal* error. 
However, if you want to *know* something went wrong, you need to
*code* for that.

The error checking is *not* just to see if the SQL syntax is correct -
it's to see if the query *worked* - there is a difference.

> 
> Use the CGI log, like Barney its your friend :)

No - I'll use the server log like most who code CGI scripts :-)

Check out this link which will show *how* to debug buggy CGI
(long link follows)

http://cvs.sourceforge.net/viewcvs.py/*checkout*/brian-d-foy/CGI_MetaFAQ/troubleshooting_CGI.html?rev=HEAD&content-type=text/html

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
The light at the end of the tunnel is the headlight of an
approaching train. 


------------------------------

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.  

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 5895
***************************************


home help back first fref pref prev next nref lref last post