[23687] in Perl-Users-Digest
Perl-Users Digest, Issue: 5894 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 4 18:05:41 2003
Date: Thu, 4 Dec 2003 15: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 Thu, 4 Dec 2003 Volume: 10 Number: 5894
Today's topics:
Re: A problem while testing MPEG-LibMPEG3-0.01 <usenet@morrow.me.uk>
a question about memory management <elwood@agouros.de>
any idea how to optimize this regex? drejcicaREMOVE@volja.net
Re: Can you tell me how to change from regular Perl to <usenet@morrow.me.uk>
Re: foreach counter (Tad McClellan)
Re: Idiom for array index that I'm foreach'ing over? <usenet@morrow.me.uk>
Re: Idiom for array index that I'm foreach'ing over? <shoppa@trailing-edge.com>
Re: Idiom for array index that I'm foreach'ing over? <uri@stemsystems.com>
Re: Idiom for array index that I'm foreach'ing over? <shoppa@trailing-edge.com>
Re: Idiom for array index that I'm foreach'ing over? (Anno Siegel)
Re: Idiom for array index that I'm foreach'ing over? (Anno Siegel)
Re: Idiom for array index that I'm foreach'ing over? <uri@stemsystems.com>
Re: In search of elegant code: is variable is within a (Sara)
Re: Is perl 5.8 slower than 5.005_03? <usenet@morrow.me.uk>
Re: Is perl 5.8 slower than 5.005_03? <nospam-abuse@ilyaz.org>
Search and Replace date string <mislam@spamless.uiuc.edu>
Re: Search and Replace date string <mislam@spamless.uiuc.edu>
Re: Search and Replace date string <asu1@c-o-r-n-e-l-l.edu>
Re: Search and Replace date string <asu1@c-o-r-n-e-l-l.edu>
Re: Search and Replace date string <mislam@spamless.uiuc.edu>
Re: trouble with DBI/CGI (Sara)
Re: trouble with DBI/CGI (Malcolm Dew-Jones)
Win32API::NET Problem (ThERiZla)
Re: Your code doesn't work <bik.mido@tiscalinet.it>
Re: Your code doesn't work <me@privacy.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 4 Dec 2003 19:08:12 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: A problem while testing MPEG-LibMPEG3-0.01
Message-Id: <bqo0ms$sn2$6@wisteria.csv.warwick.ac.uk>
xern@cpan.org (xern) wrote:
> The error message is as follows.
>
> Can't load 'blib/arch/auto/MPEG/LibMPEG3/LibMPEG3.so' for module
> MPEG::LibMPEG3:
> blib/arch/auto/MPEG/LibMPEG3/LibMPEG3.so: undefined symbol:
> mpeg3_seek_percentage at
> /usr/local/lib/perl5/5.8.1/i686-linux/DynaLoader.pm line 229. at
> test.pl line 18
>
> I've got libmpeg3.a successfully installed, and have written a C
> program to test libmpeg3, which was good. I'm curious about why this
> error would happen. The author's email seems broken, so I cannot reach
> him for the answer. Hope someone can give me the solution.
Are the versions compatible? What do you get from
nm /path/to/libmpeg3.a | grep mpeg3_seek_percentage
?
Ben
--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-: ben@morrow.me.uk
------------------------------
Date: Thu, 04 Dec 2003 21:20:15 GMT
From: Konstantinos Agouros <elwood@agouros.de>
Subject: a question about memory management
Message-Id: <1070572815.513239@rumba>
Hi,
I wrote the following little program:
sub testfunktion
{
my $a=" ";
$a.=$a;
$a.=$a;
... do this 27 more time to really eat some memory
print "First sleep\n";
sleep(4);
my $length = length($a);
$a="";
print "2nd sleep\n";
sleep(4);
return($length);
}
print "Laenge=".testfunktion()."\n";
sleep(5);
print "Laenge=".testfunktion()."\n";
print "Finished\n";
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.
During the second run I noticed no memory increase. My question: Would perl
free the memory at all if the program was running for a longer time?
The reason for me trying this is another program, where delete() stuff from
a hash after it is processed and this is a longer running server process
which grows big (memorywise) after some time to I am trying to find the
places were I can free memory, in order for this to work I need to
understand the memory management in perl scripts.
Thanks for any hint.
Konstantin
--
Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
Otkerstr. 28, 81547 Muenchen, Germany. Tel +49 89 69370185
----------------------------------------------------------------------------
"Captain, this ship will not survive the forming of the cosmos." B'Elana Torres
------------------------------
Date: Thu, 04 Dec 2003 22:53:02 GMT
From: drejcicaREMOVE@volja.net
Subject: any idea how to optimize this regex?
Message-Id: <slrnbsvepf.4c6.drejcicaREMOVE@sonet.utopija.linux>
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?
Thanks,
andrej
--
echo ${girl_name} > /etc/dumpdates
------------------------------
Date: Thu, 4 Dec 2003 19:36:42 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Can you tell me how to change from regular Perl to Mod_perl
Message-Id: <bqo2ca$sn2$9@wisteria.csv.warwick.ac.uk>
"Picker Leon" <Temp@NoSuchDomain.Info> wrote:
> > 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.
Then you have no imagination. I have never used mod_perl; just for the
hell of it I started at http://perl.apache.org/ and followed about
five obvious links; this got me to
http://perl.apache.org/docs/1.0/guide/porting.html#The_Script_Is_Too_
Dirty__But_It_Does_The_Job_And_I_Cannot_Afford_To_Rewrite_It_
(excuse the line-wrapping) which I believe tells you what you want to
know.
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* ben@morrow.me.uk *
------------------------------
Date: Thu, 4 Dec 2003 16:24:01 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: foreach counter
Message-Id: <slrnbsvd01.6ia.tadmc@magna.augustmail.com>
Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> wrote:
> foreach (@array) {
> $_ .= "\n";
> }
>
> will ''unchomp'' the values in @array.
But not really.
For unchomp() you'd need a different loop body:
$_ .= $/;
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 4 Dec 2003 19:27:00 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <bqo1q4$sn2$8@wisteria.csv.warwick.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> my $i = 0;
> while ( $i < @array ) {
> # do something with $array[ $i];
> last if bored();
> $i ++; # hi Abigail
I haven't been here long enough to get the 'hi Abigail', but surely
that should be in a continue block so you can 'next'?
Also, I would be more inclined to code this as
my $i = 0;
for (@array) {
# do something with $i and $_;
} continue { $i++ }
or, as you say, completely restructure the code so I didn't need to
know what $i was at all :).
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: 4 Dec 2003 11:23:27 -0800
From: Tim Shoppa <shoppa@trailing-edge.com>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <bqo1jf0f2p@drn.newsguy.com>
In article <bqnsfo$ogu$1@mamenchi.zrz.TU-Berlin.DE>, Anno Siegel says...
>Perl can manipulate arrays as a whole, and doing that makes better
>use of its high-level features. Once you get accustomed to this style,
>you'll find that you rarely want to loop over an index. You loop over
>array elements directly, and in fact map and grep do much of the looping.
>
>If you actually need random access to elements, more often than not
>the right data structure is a hash and not an array (even if the indices
>happen to be numbers). With hashes, indexed access, and hence loops
>over hash keys, are more frequent than with arrays, though "each" and
>"values" offer alternatives.
I agree, hashes are great, hashes are wonderful, I love hashes, but
sometimes the data really is an ordered list.
I should add that the reason that I want to know the index of the
current element is to access the same element number in another
array. (Things like a list of x coordinates in a time series and
y coordinates in a time series and the time value of each x-y
coordinates). Given this one-to-one mapping between multiple arrays, it's
probably best to make one object (possibly hash-based object-oriented
stuff) which contains x,y, and time for each point. But it seems
silly to me to go through the whole object paradigm for a simple
ten-line program, and at the same time it seems a little awkward
that the hypothetical $# doesn't exist. There are lots of ways to
make workable programs, it's just that none of them have the
simplicity and elegance that I expect out of good modern Perl
that I'm writing :-)
If the program was bigger, I'd go the full object-oriented route
with modules etc., but it seems silly to do this for such a tiny
quick little thing.
Tim.
------------------------------
Date: Thu, 04 Dec 2003 20:00:13 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <x7u14gz73n.fsf@mail.sysarch.com>
>>>>> "TS" == Tim Shoppa <shoppa@trailing-edge.com> writes:
TS> I should add that the reason that I want to know the index of the
TS> current element is to access the same element number in another
TS> array. (Things like a list of x coordinates in a time series and
TS> y coordinates in a time series and the time value of each x-y
TS> coordinates). Given this one-to-one mapping between multiple
TS> arrays, it's probably best to make one object (possibly hash-based
TS> object-oriented stuff) which contains x,y, and time for each
TS> point. But it seems silly to me to go through the whole object
TS> paradigm for a simple ten-line program, and at the same time it
TS> seems a little awkward that the hypothetical $# doesn't exist.
TS> There are lots of ways to make workable programs, it's just that
TS> none of them have the simplicity and elegance that I expect out of
TS> good modern Perl that I'm writing :-)
who says you need objects for that? you need proper perl data
structures. you really have to stop thinking in fortran!! :)
perl data structures use references which are not the same as
objects. to do a 1-1 mapping of two arrays is simple without
indexes. depending on where the data cam from you can just create a
array of arrays ( [ x, y ] coordinates ) or even add the time value as
the third array element. or you could do a simple hash like:
{ x => 1.2,
y => 3.4,
time => 12335,
}
and have an array or hash of those (not sure what the hash key would
be).
TS> If the program was bigger, I'd go the full object-oriented route
TS> with modules etc., but it seems silly to do this for such a tiny
TS> quick little thing.
perl works fine with or without objects. get your mind out of that
fortran gutter where all you have are individual arrays that can only be
linked by their indexes. that is such a poor design and paradigm.
read more about perl data structures in perllol and perldsc.
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 12:21:44 -0800
From: Tim Shoppa <shoppa@trailing-edge.com>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <bqo50o0r6l@drn.newsguy.com>
In article <x7u14gz73n.fsf@mail.sysarch.com>, Uri Guttman says...
>perl data structures use references which are not the same as
>objects. to do a 1-1 mapping of two arrays is simple without
>indexes. depending on where the data cam from you can just create a
>array of arrays ( [ x, y ] coordinates ) or even add the time value as
>the third array element. or you could do a simple hash like:
>
> { x => 1.2,
> y => 3.4,
> time => 12335,
> }
>
>and have an array or hash of those (not sure what the hash key would
>be).
All those are workable but IMHO a bit ugly compared to creating a
"point" object that has x,y, and time methods. Your last suggestion
comes close but I don't like all those curly brackets (again, my
personal taste).
I did discover Class::MethodMaker which is somewhat elegant for
this sort of stuff.
> TS> If the program was bigger, I'd go the full object-oriented route
> TS> with modules etc., but it seems silly to do this for such a tiny
> TS> quick little thing.
>
>perl works fine with or without objects. get your mind out of that
>fortran gutter where all you have are individual arrays that can only be
>linked by their indexes. that is such a poor design and paradigm.
But it's where my mind goes for any quick-and-dirty program.
For big programs I'm quite used to the object-oriented approach...
but then I find that many CPAN modules still insist on, for example,
arrays ordered the "wrong" way (e.g. GD::Graph), so I'm forced
to take my elegant objects and break them down to a bunch of arrays
("the Fortran gutter").
I think more use of Class::MethodMaker will satisfy my desire for
elegance even when quick-and-dirty. And maybe I ought to just not
use CPAN modules from the Fortran Gutter.
Tim.
------------------------------
Date: 4 Dec 2003 20:52:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <bqo6qc$ol$1@mamenchi.zrz.TU-Berlin.DE>
Ben Morrow <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
>
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > my $i = 0;
> > while ( $i < @array ) {
> > # do something with $array[ $i];
> > last if bored();
> > $i ++; # hi Abigail
>
> I haven't been here long enough to get the 'hi Abigail', but surely
Oh, that's all about a blank, the one in front of "++". Abigail endorses
that style, but not everyone follows :)
> that should be in a continue block so you can 'next'?
>
> Also, I would be more inclined to code this as
>
> my $i = 0;
> for (@array) {
> # do something with $i and $_;
> } continue { $i++ }
Sure, that's more robust. I was being sketchy.
> or, as you say, completely restructure the code so I didn't need to
> know what $i was at all :).
As we have learned (news-propagation allowing), the purpose is access
to two (or more) parallel arrays. Perl isn't particularly good at that,
though no worse than comparable languages, it just isn't needed all
that much.
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.
Anno
------------------------------
Date: 4 Dec 2003 21:22:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <bqo8j9$21h$1@mamenchi.zrz.TU-Berlin.DE>
Tim Shoppa <shoppa@trailing-edge.com> wrote in comp.lang.perl.misc:
> In article <bqnsfo$ogu$1@mamenchi.zrz.TU-Berlin.DE>, Anno Siegel says...
> >Perl can manipulate arrays as a whole, and doing that makes better
> >use of its high-level features. Once you get accustomed to this style,
> >you'll find that you rarely want to loop over an index. You loop over
> >array elements directly, and in fact map and grep do much of the looping.
> >
> >If you actually need random access to elements, more often than not
> >the right data structure is a hash and not an array (even if the indices
> >happen to be numbers). With hashes, indexed access, and hence loops
> >over hash keys, are more frequent than with arrays, though "each" and
> >"values" offer alternatives.
>
> I agree, hashes are great, hashes are wonderful, I love hashes, but
> sometimes the data really is an ordered list.
>
> I should add that the reason that I want to know the index of the
> current element is to access the same element number in another
> array. (Things like a list of x coordinates in a time series and
> y coordinates in a time series and the time value of each x-y
> coordinates). Given this one-to-one mapping between multiple arrays, it's
> probably best to make one object (possibly hash-based object-oriented
> stuff) which contains x,y, and time for each point. But it seems
> silly to me to go through the whole object paradigm for a simple
> ten-line program, and at the same time it seems a little awkward
> that the hypothetical $# doesn't exist. There are lots of ways to
> make workable programs, it's just that none of them have the
> simplicity and elegance that I expect out of good modern Perl
> that I'm writing :-)
You don't need objects just because you want an advanced data structure
in Perl. Usually it is possible to build a list of data points (triplets,
in your case) right from the input.
If, for some reason, the data is given in individual arrays, there are
many ways to pre-process them into a list of triplets. I have given an
example in another article not far from here in this thread.
The main loop would look like (untested):
for ( @data_points ) { # @data_points built elsewhere
my ( $x, $y, $t) = @{ $_}; # $_ is an array(ref) of three elements
# do things with $x, $y, $t
}
Hey, it doesn't even use a hash!
> If the program was bigger, I'd go the full object-oriented route
> with modules etc., but it seems silly to do this for such a tiny
> quick little thing.
Well, that's one of the beauties of Perl that you can often use just
enough of it to fit your needs. In this case, an array-ref neatly
encapsulates your data. This is just an alternative to Uri's hashes-used-
as-records.
Anno
------------------------------
Date: Thu, 04 Dec 2003 21:27:44 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <x7iskwz31r.fsf@mail.sysarch.com>
>>>>> "TS" == Tim Shoppa <shoppa@trailing-edge.com> writes:
>> { x => 1.2,
>> y => 3.4,
>> time => 12335,
>> }
>>
>> and have an array or hash of those (not sure what the hash key would
>> be).
TS> All those are workable but IMHO a bit ugly compared to creating a
TS> "point" object that has x,y, and time methods. Your last suggestion
TS> comes close but I don't like all those curly brackets (again, my
TS> personal taste).
but you don't speak perl so you taste is not relevent. even with objects
you need to understand perl refs.
TS> I did discover Class::MethodMaker which is somewhat elegant for
TS> this sort of stuff.
overkill. you just said you didn't want to go OO for this. make up your
mind. and you still need to learn refs.
TS> If the program was bigger, I'd go the full object-oriented route
TS> with modules etc., but it seems silly to do this for such a tiny
TS> quick little thing.
that makes no sense at all.
>> perl works fine with or without objects. get your mind out of that
>> fortran gutter where all you have are individual arrays that can only be
>> linked by their indexes. that is such a poor design and paradigm.
TS> But it's where my mind goes for any quick-and-dirty program.
if you want to get better at perl, then you should stop thinking in
fortran.
TS> For big programs I'm quite used to the object-oriented approach...
TS> but then I find that many CPAN modules still insist on, for example,
TS> arrays ordered the "wrong" way (e.g. GD::Graph), so I'm forced
TS> to take my elegant objects and break them down to a bunch of arrays
TS> ("the Fortran gutter").
huh?
TS> I think more use of Class::MethodMaker will satisfy my desire for
TS> elegance even when quick-and-dirty. And maybe I ought to just not
TS> use CPAN modules from the Fortran Gutter.
huh?
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 12:13:31 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <776e0325.0312041213.2c26b8f0@posting.google.com>
IneverReadAnythingSentToMe@hotmail.com (David Filmer) wrote in message news:<e4c916dd.0312031439.69419e1e@posting.google.com>...
> Suppose I want to check if $foo is between 1 and 10. What I would like
> to do is something elegant like:
>
> if (1 < $foo < 10) {blah blah...
>
> But Perl doesn't like that. Am I forced to resort to
>
> if (1 < $foo && $foo < 10) {blah blah...
>
> or is there a more elegant way to write it?
...between 1 and 10, meaning 2..9?. That's what (1 < $foo && $foo <
10) would yield if it worked so I guess that's what you want. Anyhow
this might work:
$foo =~ /^0*[2-9]\.?.*$/
or if you know if $foo is always an integer,
$foo =~ /^0*[2-9]$/
or if you know there are no leading zeros:
$foo =~ /^[2-9]$/
------------------------------
Date: Thu, 4 Dec 2003 19:19:40 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Is perl 5.8 slower than 5.005_03?
Message-Id: <bqo1cc$sn2$7@wisteria.csv.warwick.ac.uk>
jreed@ptc.com (Jon Reed) wrote:
> We rebuilt one of three webserver machines with solaris 5.8 and added
> perl 5.8 using
> ./Configure -des -Dusethreads -Dcc='gcc -B/usr/ccs/bin/'
Was the perl you got from sunfreeware also built with gcc? What about
the old perl? Does it make a difference if you use Sun's compiler? You
may also want to check the compiler optimizations used: perl -V tells
you what was used in each case.
What happens if you try 5.6 instead (on the vague hypothesis that the
new Unicode stuff might be making a difference)? 5.6 is *enormously*
improved on 5.005_03, so it's well worth upgrading at least that far.
Ben
--
We do not stop playing because we grow old;
we grow old because we stop playing.
ben@morrow.me.uk
------------------------------
Date: Thu, 4 Dec 2003 21:44:37 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Is perl 5.8 slower than 5.005_03?
Message-Id: <bqo9s5$c8r$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Jon Reed
<jreed@ptc.com>], who wrote in article <21cca72e.0312040550.128bd53d@posting.google.com>:
> Is perl 5.8 slower than perl 5.005_03 ?
> eliminate the webserver, so executing a simple perl script 1000 times
> direct from the command line took about 30 seconds with perl 5.8.
> Then I copied the perl 5.005_03 binary over from a very similar
> machine (that has not been rebuilt yet) and it takes 16 seconds for
> the same test!!
My benchmarks of 5.005_53 vs 5.8.1 are (Athlon 850, OS/2, no threads):
Load time with -e1: 60ms vs 80ms
Load time of old File::Find: 190ms vs 240ms
So the slowdown is 25% on load of the interpreter, and 33% on compile
of required modules.
However, the "new" File::Find loads 2x slower than the old one (it is
significantly more complicated code now).
I did not detect any striking slowdown of *running* time (but I did
not try to...).
BTW, to answer other question in this thread: after my first rewrite
of Perl's malloc(), it was 2.5x quickier than Solaris one (of the
time), and would use 40% lower memory. For several Perl applications
I tested, this gave (widely varying) speedups centered about 10-15%.
Hope this helps,
Ilya
------------------------------
Date: Thu, 04 Dec 2003 14:50:08 -0600
From: Sharif Islam <mislam@spamless.uiuc.edu>
Subject: Search and Replace date string
Message-Id: <bqo6ue$r29$1@news.ks.uiuc.edu>
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.
This is what I have so far:
if ($date =~ m!^/\d\d\d\d-/;?!) {
my ($startm,$starty,$endy) = ($date =~ m!(/)(\d\d\d\d)-(/)!);
print "$starty-Present";
}
elsif ($date =~m!^\d+/\d\d\d\d-/!) {
my ($startm,$starty,$endy) =($date =~ m!(^\d+)/(\d\d\d\d)-(/)!);
print "$startm/$starty-Present";
}
else {print $date ; }
I am not sure how to take care of the strings with ';' in it, as in (e).
The problem is there are few strings that has more than two dates
separated by ';' and they are not necessarily the same type.
--
)
((
|""|-.
| :|/'
-`--'-
------------------------------
Date: Thu, 04 Dec 2003 14:53:16 -0600
From: Sharif Islam <mislam@spamless.uiuc.edu>
Subject: Re: Search and Replace date string
Message-Id: <bqo749$r29$2@news.ks.uiuc.edu>
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 meant (d) to leave alone, not (e).
--
)
((
|""|-.
| :|/'
-`--'-
------------------------------
Date: 4 Dec 2003 21:35:19 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Search and Replace date string
Message-Id: <Xns9447A8C06D158asu1cornelledu@132.236.56.8>
Sharif Islam <mislam@spamless.uiuc.edu> wrote in
news:bqo749$r29$2@news.ks.uiuc.edu:
> 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.
>> (d) leave alone.
What is the difference between (a) and (c)?
#! perl
use strict;
use warnings;
while(<DATA>) {
chomp;
for ($_) {
m!(\d\d)/(\d\d\d\d)-/! and print "$1/$2-Present" and last;
m!/(\d\d\d\d)-/! and print "$1-Present" and last;
m!(\d\d)/(\d\d\d\d)-/;(\d\d)/(\d\d\d\d)! and print "$1/$2 - $3/$4"
and last;
print;
}
print "\n";
}
__DATA__
09/1998-/
/1998-/
02/1997-/
03/2001-07/2003
02/1997-/;02/1998-/
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: 4 Dec 2003 21:44:48 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Search and Replace date string
Message-Id: <Xns9447AA5BD9C06asu1cornelledu@132.236.56.8>
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in
news:Xns9447A8C06D158asu1cornelledu@132.236.56.8:
> m!(\d\d)/(\d\d\d\d)-/! and print "$1/$2-Present" and last;
> m!/(\d\d\d\d)-/! and print "$1-Present" and last;
> m!(\d\d)/(\d\d\d\d)-/;(\d\d)/(\d\d\d\d)! and print "$1/$2 - $3/$4"
> and last;
> print;
Well ... Sorry, not only is the code bad, but it does not do what you
want. Hope the following helps:
#! perl
use strict;
use warnings;
while(<DATA>) {
chomp;
for ($_) {
m!^(\d\d)/(\d\d\d\d)-/$! and print("$1/$2-Present") and last;
m!^/(\d\d\d\d)-/$! and print("$1-Present") and last;
m!^(\d\d)/(\d\d\d\d)-/;(\d\d)/(\d\d\d\d)-/$! and print("$1/$2-$3/$4")
and last;
print;
}
print "\n";
}
__DATA__
09/1998-/
/1998-/
02/1997-/
03/2001-07/2003
02/1997-/;02/1998-/
C:\misc>ddd.pl
09/1998-Present
1998-Present
02/1997-Present
03/2001-07/2003
02/1997-02/1998
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Thu, 04 Dec 2003 16:52:23 -0600
From: Sharif Islam <mislam@spamless.uiuc.edu>
Subject: Re: Search and Replace date string
Message-Id: <bqoe3m$tj6$1@news.ks.uiuc.edu>
A. Sinan Unur wrote:
> "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in
> news:Xns9447A8C06D158asu1cornelledu@132.236.56.8:
>> m!(\d\d)/(\d\d\d\d)-/! and print "$1/$2-Present" and last;
>> m!/(\d\d\d\d)-/! and print "$1-Present" and last;
>> m!(\d\d)/(\d\d\d\d)-/;(\d\d)/(\d\d\d\d)! and print "$1/$2 - $3/$4"
>>and last;
>> print;
>
>
> Well ... Sorry, not only is the code bad, but it does not do what you
> want. Hope the following helps:
>
> #! perl
>
> use strict;
> use warnings;
>
> while(<DATA>) {
> chomp;
> for ($_) {
> m!^(\d\d)/(\d\d\d\d)-/$! and print("$1/$2-Present") and last;
> m!^/(\d\d\d\d)-/$! and print("$1-Present") and last;
> m!^(\d\d)/(\d\d\d\d)-/;(\d\d)/(\d\d\d\d)-/$! and print("$1/$2-$3/$4")
> and last;
> print;
> }
> print "\n";
> }
>
> __DATA__
> 09/1998-/
> /1998-/
> 02/1997-/
> 03/2001-07/2003
> 02/1997-/;02/1998-/
>
> C:\misc>ddd.pl
> 09/1998-Present
> 1998-Present
> 02/1997-Present
> 03/2001-07/2003
> 02/1997-02/1998
Thanks for your reply. Sorry, I should've been little more clearer about
the data in my initial posting. I have strings like this also:
'09/1867-/;07/2003-/;08/2003-10/2001'
So I am thinking about just splitting out the string if it has a ';',
then apply the changes on them separately. I like the idea of using
$1,$2 for the output, little cleaner. Here's my updated code. I will
have to do some changes on it, though. Comments, suggestion welcomed.
____CODE___
#!/usr/bin/perl
use strict;
use warnings;
@ARGV == 1 or die "Die you gravy sucking pig. Give a date!\n";
my $date = shift;
# if you see a ';' do this
if ($date =~ m\;\) {
my @spltdate = split /;/, $date;
my $line;
foreach $line(@spltdate) {
fixdate($line) ; }
}
else {
fixdate($date);
}
#subroutine
sub fixdate {
my $date = shift;
if ($date =~ m!^/\d\d\d\d-/!) {
my ($startm,$starty,$endy) = ($date =~ m!(/)(\d\d\d\d)-(/)!);
print "$starty-Present\n";
}
elsif ($date =~m!^\d+/\d\d\d\d-/!) {
my ($startm,$starty,$endy) =($date =~ m!(^\d+)/(\d\d\d\d)-(/)!);
print "$startm/$starty-Present\n";
}
else {print "$date\n" ; }
}
#end sub
__END CODE____
__OUTPUT__
# perl datechange.pl '09/2003-11/2004'
09/2003-11/2004
# perl datechange.pl '09/2003-11/2004;08/2003-/'
09/2003-11/2004
08/2003-Present
# perl datechange.pl '09/2003-11/2004;/2003-/'
09/2003-11/2004
2003-Present
[Ya, i need to fix the output so it looks like
09/2003-11/2004;2003-Present ]
# perl datechange.pl '09/2003-11/2004;12/2003-11/2004'
09/2003-11/2004
12/2003-11/2004
# perl datechange.pl '09/2003-11/2004'
09/2003-11/2004
# perl datechange.pl '/1999-/'
1999-Present
--
)
((
|""|-.
| :|/'
-`--'-
------------------------------
Date: 4 Dec 2003 12:27:28 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: trouble with DBI/CGI
Message-Id: <776e0325.0312041227.30d3ca68@posting.google.com>
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').
>
> 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 ...
> Disco is to music what Etch-A-Sketch is to art.
.
.
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".
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..
Use the CGI log, like Barney its your friend :)
G
------------------------------
Date: 4 Dec 2003 12:38:39 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: trouble with DBI/CGI
Message-Id: <3fcf9b4f@news.victoria.tc.ca>
Sara (genericax@hotmail.com) wrote:
: ... I'd rather ensure
: my SQL statements are correct by construction rather than error-check
: everytime I issue one, wasting code and resources.
I would disagree. Every call should be error checked unless you don't
care about an error at that point (which is ok in some situations).
No sql query is every "correct by construction" except at the moment you
test it. Many databases change over time, and old queries become
incorrect, and any number of other things can occur.
Of course I haven't read this thread, I just noticed the above, which
sounds wrong to me, so maybe i'm out to lunch.
------------------------------
Date: 4 Dec 2003 11:49:38 -0800
From: cool_ian10@hotmail.com (ThERiZla)
Subject: Win32API::NET Problem
Message-Id: <42f55bd6.0312041149.40e94f7@posting.google.com>
Hi,
I search the examples about the modules Win32API:Net or
Win32::NetAdmin.
I want add a new user, change a password or delete an user and I don't
know
what is the best method to process with this.
I can delete an user but I'm not able add user or change password.
If someone have a web site page with examples or can give me some
examples or detailled explications.
Thanks
------------------------------
Date: Thu, 04 Dec 2003 22:50:36 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Your code doesn't work
Message-Id: <qslssv4jpk92ela4h15rqgrpngr3ltlbt0@4ax.com>
On Wed, 03 Dec 2003 13:46:32 +0100, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
>A suitable starter might be
>
> perldoc -f sort
On Wed, 03 Dec 2003 14:21:47 +0100, Colossus
<colossus_NOSPAM_@freemail.it> wrote:
>> A suitable starter might be
>
>What you call suitable is a very difficult
>explanation on how to sort an array of more fields.
As I wrote in my other post, please quote correctly. I had to check
Gunnar Hjalmarsson's own post above to see what you consider a "very
difficult explanation"... and only now I realize that I gave you the
very same advice (but the 'perldoc -q' one is probably more
effective)!
However your claim is plainly false: the perldoc entry you were
pointed to definitely is *not* "an explanation on how to sort an array
of more fields", either difficult or not. It's the full documentation
of the sort() function, and certainly it is clear enough as to give
you an idea on how to sort an array "of more fields".
But then please explain what is difficult about 'perldoc -f sort' and
hopefully someone may help you with the difficulties you're
experiencing.
Ciao,
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
Date: Fri, 5 Dec 2003 11:26:31 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: Your code doesn't work
Message-Id: <bqoccf$24b73v$1@ID-172104.news.uni-berlin.de>
"Colossus" <colossus_NOSPAM_@freemail.it> wrote in message
news:bqn52o$24kaf3$1@ID-154800.news.uni-berlin.de...
> poorly worded ? I gave a perfect example of the expected output, infact Mr
> Tore Aursand understood perfectly, so my message was clear.
Tore only "understood" after you were repeatedly asked to clarify the output
and in the end you even admitted you were wrong (see below). I think you
owe everyone on this newsgroup an apology.
> Tore Aursand wrote:
> > The fields are tab separated. I want it this way:
> > A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110
> > A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39
> > A14829.PE1 DRAPLIPAI.PE1 HBG004257 1.96625 386
> > A14829.PE1 AF042219.PE1 HBG004257 2.03983 110
> > A14829.PE1 SSAPOLAI.PE1 HBG004257 1.88791 39
>
> As I hope you can see, the data _IS NOT_ sorted in a descending order.
You are right.
--
Bye,
Colossus
------------------------------
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 5894
***************************************