[17484] in Perl-Users-Digest
Perl-Users Digest, Issue: 4904 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 16 18:06:07 2000
Date: Thu, 16 Nov 2000 15:05:24 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <974415924-v9-i4904@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 16 Nov 2000 Volume: 9 Number: 4904
Today's topics:
Re: A silly. Substitution - s/// (Anno Siegel)
ANNOUNCE: DBD::Sybase 0.91 <mpeppler@peppler.org>
ANNOUNCE: sybperl 2.13 <mpeppler@peppler.org>
ANNOUNCE: tagged-0.20 released <t.geffert@gmx.de>
Can anyone help with this <sean@motorsports.co.uk>
Re: Can anyone help with this (John J. Trammell)
Capital Letters Won't Sort - HeLp! fhinchey@my-deja.com
Re: Capital Letters Won't Sort - HeLp! eggrock@my-deja.com
Re: Capital Letters Won't Sort - HeLp! <tony_curtis32@yahoo.com>
Re: Capital Letters Won't Sort - HeLp! fhinchey@my-deja.com
Re: Capital Letters Won't Sort - HeLp! fhinchey@my-deja.com
cgi display graph suggestions needed? krystd@my-deja.com
Re: Converting Troff to Jpeg <jeffahill@_ANTISPAM_.lucent.com>
Re: Converting Troff to Jpeg (Martien Verbruggen)
Re: Counting bracket matching <jeffp@crusoe.net>
Re: Counting bracket matching <bart.lateur@skynet.be>
CRC Check <me@privacy.net>
Re: CRC Check (Gwyn Judd)
Re: Date (Ameen Dausha)
Re: Date (Ameen Dausha)
Re: Date (Ameen Dausha)
Re: Date (Ameen Dausha)
Re: Date (Ameen Dausha)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 16 Nov 2000 19:10:37 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: A silly. Substitution - s///
Message-Id: <8v1bfd$gce$1@lublin.zrz.tu-berlin.de>
Bart Lateur <bart.lateur@skynet.be> wrote in comp.lang.perl.misc:
>Anno Siegel wrote:
>
>>>If you want to reduce it to just one instance: tr/// with the /s option
>>>(for "single") is designed for that.
>>
>>Pity. I thought "s" was for "squeeze", and found that more colorful.
>
>Why not. The /s is part of the language, the word itself is not. perlop
>talks about "squash", which is even more colorful.
Certainly. However, knowing that the originator(s) of /s thought of
"single" (as I'm inclined to believe after this exchange) will produce
a tendency to "get it right". Sometimes ignorance *is* bliss.
Anno
------------------------------
Date: Wed, 15 Nov 2000 07:18:39 -0800
From: Michael Peppler <mpeppler@peppler.org>
Subject: ANNOUNCE: DBD::Sybase 0.91
Message-Id: <3A12A94F.9A458725@peppler.org>
The uploaded file
DBD-Sybase-0.91.tar.gz
has entered CPAN as
file: $CPAN/authors/id/M/ME/MEWP/DBD-Sybase-0.91.tar.gz
size: 58730 bytes
md5: a95ab43918044d2e50694a4f564615c5
This is a minor bug fix release. But as Sybase has released an early
beta of ASE 12.5 for linux I was motivated to check that the code
actually handles the new features of that server, specifically the
longer column lengths (char/varchar can be up to 16000 bytes in
certain circumstances.)
>From the CHANGES file:
Release 0.91
Removed artificial 1024 byte limit on char/varchar datatypes in
result sets.
Bug Fixes:
213: BLOBs are returned in HEX, not binary.
--
Michael Peppler - Data Migrations Inc. - mpeppler@peppler.org
http://www.mbay.net/~mpeppler - mpeppler@mbay.net - AIM MPpplr
International Sybase User Group - http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com
------------------------------
Date: Wed, 15 Nov 2000 07:19:07 -0800
From: Michael Peppler <mpeppler@peppler.org>
Subject: ANNOUNCE: sybperl 2.13
Message-Id: <3A12A96B.92CA9332@peppler.org>
The uploaded file
sybperl-2.13.tar.gz
has entered CPAN as
file: $CPAN/authors/id/M/ME/MEWP/sybperl-2.13.tar.gz
size: 166084 bytes
md5: 492bac909dd34c40b786a8efdefac8a5
Sybase has just made an early beta of ASE 12.5 available for linux.
Just the push I needed to clean up some loose ends and release sybperl
2.13. This version fixes various bugs, and enables Sybase::CTlib (but
not Sybase::DBlib) to handle the longer data columns (char/varchar can
now go beyond 255 chars!)
>From the CHANGES file:
2.13 Yet more bug fixes
Correct EMBED_SYBASE handling (bug in config.pl script).
Fix building for Sybase 12.0 (uses SYBASE_OCS environment
variable.)
Added dbretlen(), dbretname(), dbrettype() to DBlib.
Minor changes to support wide data in Sybase 12.5.
340: Sybase::BCP fails unless REORDER is defined.
342: DateTime calc method microseconds aren't.
--
Michael Peppler - Data Migrations Inc. - mpeppler@peppler.org
http://www.mbay.net/~mpeppler - mpeppler@mbay.net - AIM MPpplr
International Sybase User Group - http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com
------------------------------
Date: 16 Nov 2000 21:33:27 +0100
From: Thomas Geffert <t.geffert@gmx.de>
Subject: ANNOUNCE: tagged-0.20 released
Message-Id: <t18mataji6vkb1@corp.supernews.com>
tagged-0.20.tar-gz - Release Notes
tagged-0.20 contains:
* updated MP3::Tag modules.
These modules can be used to read/change/write ID3v1/ID3v1.1/ID3v2.3 tags
of MP3 audio files. This new version supports now also the use of MP3::Tag
with perl on windows. The last version didn't write the tags correctly
when used with windows.
Also more ID3v2 frames are supported now, and an additional manpage
MP3::Tag::ID3v2-Data contains information about which frames are how
supported.
The test program now does some additional tests to check if MP3::Tag works
(to be called with 'make test').
* added tk-tag.pl
tk-tag.pl is a graphical interface to MP3::Tag and allows you to view
the tags of any MP3 audio files. This first version supports only to
change the filename and the ID3v1/ID3v1.1 tags.
Support for changing ID3v2.3 tags is coming soon, because this is already
supported by MP3::Tag.
* tagit.pl
A command line utility to change ID3v1 tags and to set the filename of
a MP3 file automatically, according to the information found in the
ID3v1/ID3v1.1 tag.
tagged-0.20.tar.gz can be found at
http://tagged.sourceforge.net or
http://www.cpan.org/authors/id/T/TH/THOGEE/tagged-0.20.tar.gz or
http://search.cpan.org/search?dist=tagged
The author can be reached at <thg@users.sourceforge.net>
At http://sourceforge.net/projects/tagged you can also find forums to
discuss this package as well as a announce-mailing-list.
------------------------------
Date: Thu, 16 Nov 2000 22:22:23 +0000
From: Sean W <sean@motorsports.co.uk>
Subject: Can anyone help with this
Message-Id: <sean-E9EE17.22222316112000@usenet.plus.net>
I have no knowledge whatsoever of either programming or perl but I am of
average inteligence with a need for a number of scripts that perform
certain tasks for a new website I am working on. I don't if it is
acceptable but am I able to ask question here as long as I am trying my
hardest to self teach but getting stuck.
If so here are questions 1 and 2
Iam using 3 existing scripts each of which does a function of what I am
looking for but none of which does all three.
if(!$ENV{'QUERY_STRING'} | !$call_page) {
why does the above use the ! before the $ENV and $call_page.
Second when do you use { and }
Before people say buy a book, I have two both of which must assume you
have a phd before you start. People aren't good at explaining in plain
English why something happens.
Regards
Sean
PS if anyone programs well for $30 an hour instead of $130 email me
perhaps you can save me all this hassle sean@motorsports.co.uk
------------------------------
Date: 16 Nov 2000 22:38:47 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Can anyone help with this
Message-Id: <slrn917u42.nbr.trammell@nitz.hep.umn.edu>
On Thu, 16 Nov 2000 22:22:23 +0000, Sean W <sean@motorsports.co.uk> wrote:
[snip]
> if(!$ENV{'QUERY_STRING'} | !$call_page) {
>
> why does the above use the ! before the $ENV and $call_page.
Hard to say, without knowing what the script is trying to
do. You're aware that the '!' stands for logical 'not',
right? The pipe ("|") is a bitwise OR, and should probably
be a logical or ("||").
> Second when do you use { and }
In Perl the {} characters mean different things depending
on context. In code like "if (test) {...}" (like the code
you included above), the {...} is a code block, and is
used to group lines of code.
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: Thu, 16 Nov 2000 21:16:59 GMT
From: fhinchey@my-deja.com
Subject: Capital Letters Won't Sort - HeLp!
Message-Id: <8v1is2$1ui$1@nnrp1.deja.com>
I'm having problems alphabetically sorting an array using...
@sorted = sort @list;
It's working great for words beginning with lower case letters,
however, for words beginning with capital letters, it's putting them
all at the top of the list. This isn't what i want! Does anyone know
what this happens and how I can stop this maddness??? Thx.
P.S. I don't want to change the words in caps to lower case, I just
want all my duckies in a row!
-Frank
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 16 Nov 2000 21:28:05 GMT
From: eggrock@my-deja.com
Subject: Re: Capital Letters Won't Sort - HeLp!
Message-Id: <8v1jgq$2gi$1@nnrp1.deja.com>
In article <8v1is2$1ui$1@nnrp1.deja.com>,
fhinchey@my-deja.com wrote:
> I'm having problems alphabetically sorting an array using...
> @sorted = sort @list;
>
> It's working great for words beginning with lower case letters,
> however, for words beginning with capital letters, it's putting them
> all at the top of the list. This isn't what i want! Does anyone know
> what this happens and how I can stop this maddness??? Thx.
>
> P.S. I don't want to change the words in caps to lower case, I just
> want all my duckies in a row!
>
> -Frank
Perl sorts in ASCII order by default. ASCII "Z" is lower (numerically)
than ASCII "a".
To fix... ? Never ran into the problem yet. Someone more knowledgeable
will know how to 'fix' it in an elegant fashion.
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 16 Nov 2000 15:48:56 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Capital Letters Won't Sort - HeLp!
Message-Id: <87d7fva8qf.fsf@limey.hpcc.uh.edu>
>> On Thu, 16 Nov 2000 21:16:59 GMT,
>> fhinchey@my-deja.com said:
> I'm having problems alphabetically sorting an array
> using... @sorted = sort @list;
> It's working great for words beginning with lower case
> letters, however, for words beginning with capital
> letters, it's putting them all at the top of the
> list. This isn't what i want! Does anyone know what this
> happens and how I can stop this maddness??? Thx.
That's how ASCII is ordered, upper case is below lower
case. It sounds as if you want a case-insensitive sort,
in which case see
perldoc -q sort
perlfaq4
How do I sort an array by (anything)?
Basically here you want to lc() [ or uc() ] both keys when
you compare them.
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Thu, 16 Nov 2000 22:05:56 GMT
From: fhinchey@my-deja.com
Subject: Re: Capital Letters Won't Sort - HeLp!
Message-Id: <8v1lnt$4ke$1@nnrp1.deja.com>
Not to be masterbatory, but I ALMOST found the answer to my question...
@sorted = sort{$a<=>$b}(@list);
I thought this would do it, but it still doesn't work correctly, it
works for the first ten then get all nutty again. Plus, only the first
letter of the capitalized words sorts correctly, the second letter is
still not correctly alphabetized. Maybe I'm just too anal for Perl?
In article <8v1jgq$2gi$1@nnrp1.deja.com>,
eggrock@my-deja.com wrote:
> In article <8v1is2$1ui$1@nnrp1.deja.com>,
> fhinchey@my-deja.com wrote:
> > I'm having problems alphabetically sorting an array using...
> > @sorted = sort @list;
> >
> > It's working great for words beginning with lower case letters,
> > however, for words beginning with capital letters, it's putting them
> > all at the top of the list. This isn't what i want! Does anyone know
> > what this happens and how I can stop this maddness??? Thx.
> >
> > P.S. I don't want to change the words in caps to lower case, I just
> > want all my duckies in a row!
> >
> > -Frank
>
> Perl sorts in ASCII order by default. ASCII "Z" is lower (numerically)
> than ASCII "a".
>
> To fix... ? Never ran into the problem yet. Someone more knowledgeable
> will know how to 'fix' it in an elegant fashion.
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 16 Nov 2000 22:19:21 GMT
From: fhinchey@my-deja.com
Subject: Re: Capital Letters Won't Sort - HeLp!
Message-Id: <8v1mh0$58c$1@nnrp1.deja.com>
Aha! I should always look to perldoc first. I'm learning. Here's the
code in case it might save someone's else a little sanity:
@sorted = sort{uc($a) cmp uc($b)}@list;
thanks everyone!
In article <87d7fva8qf.fsf@limey.hpcc.uh.edu>,
Tony Curtis <tony_curtis32@yahoo.com> wrote:
> >> On Thu, 16 Nov 2000 21:16:59 GMT,
> >> fhinchey@my-deja.com said:
>
> > I'm having problems alphabetically sorting an array
> > using... @sorted = sort @list;
>
> > It's working great for words beginning with lower case
> > letters, however, for words beginning with capital
> > letters, it's putting them all at the top of the
> > list. This isn't what i want! Does anyone know what this
> > happens and how I can stop this maddness??? Thx.
>
> That's how ASCII is ordered, upper case is below lower
> case. It sounds as if you want a case-insensitive sort,
> in which case see
>
> perldoc -q sort
>
> perlfaq4
>
> How do I sort an array by (anything)?
>
> Basically here you want to lc() [ or uc() ] both keys when
> you compare them.
>
> hth
> t
> --
> Eih bennek, eih blavek.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 16 Nov 2000 20:15:15 GMT
From: krystd@my-deja.com
Subject: cgi display graph suggestions needed?
Message-Id: <8v1f8c$uio$1@nnrp1.deja.com>
I am trying to write a cgi script that will display a database
performance chart in a browser screen. The only way I have found to
do this is by calling another script to display the chart once the user
selects the month and year. Is there any way to just dislay the chart
without having to call the second script and having to ouput the first
to a file. When I try this(other things) I just get a empty box with a
little [x] image.
Newbie using cgi. Any suggestions would be apreciated.
Attached are the two scripts.
#!c:\perl\bin\perl.exe
#-----------------------------------------------------------------------
--
# program : db_chart
# author : krysd
# date : 11/14/2000
# purpose : Browser report for viewing performance charts
#-----------------------------------------------------------------------
--
use CGI qw/:standard -no_debug/;
use Sybase::CTLIB; #sybperl open client for db connection
#-----------------------------------------------------------------------
--
# Do the form Form on Browser
#-----------------------------------------------------------------------
--
print header('image/gif'),
start_html('Sybase PF Viewer'),
h4('Sybase I/O Chart...Select Month/Year...Press button'),
start_form(),
"Month",
popup_menu(-name => 'month',
-values =>
['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'
]),
"Year",
popup_menu(-name => 'year',
-values => ['2000','2001','2002']),
submit('View I/O Chart');
#-----------------------------------------------------------------------
--
# grab selections and process the button press
#-----------------------------------------------------------------------
--
if ( defined param()) {
#-----------------------------------------------------------------------
-
# get pw and make connections
#-----------------------------------------------------------------------
-
my $sapw = pw();
chop($sapw); # removed cr/lf
#-----------------------------------------------------------------------
-
# do chart
#-----------------------------------------------------------------------
-
$month = param(month);
$yr = param(year);
#--------------------------------------------------------------------
# Get month number and length
#--------------------------------------------------------------------
$sys_date = localtime();
@day = split(" ",$sys_date);
$leap = ($day[4] ) / 4; #determine if leap year
if ( $leap eq 0 ){
%monlen = qw(jan 31 feb 29 mar 31 apr 30 may 31 jun 30 jul 31
aug 31 sep 30 oct 31 nov 30 dec 31);
}
else {
%monlen = qw(jan 31 feb 28 mar 31 apr 30 may 31 jun 30 jul 31
aug 31 sep 30 oct 31 nov 30 dec 31);
}
%months = qw(jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8 sep 9
oct 10 nov 11 dec 12);
$mon_num = $months{$month};
#--------------------------------------------------------------------
# Get connection to database on server were historical server is saving
the info.
#--------------------------------------------------------------------
$d = new Sybase::CTlib "sa",$sapw,"dsy_gmd1";
$d->ct_sql("use p_mon");
#--------------------------------------------------------------------
# get logical io data from database for each day in a month
# data comes from sybase's historical server monitored daily data
#--------------------------------------------------------------------
$days = $monlen{$month};
if ($month !~ "\l$day[1]") { #process month other than current
foreach $num (1..$days){
@io = $d->ct_sql("select sum(LogicalPageReads_ValSmp) from
dbo.engines where Timestamp between '$mon_num\/$num\/$yr 06:00' and
'$mon_num\/$num\/$yr 23:30'");
foreach my $ref (@io){
push (@dly_io,$$ref[0]);
}
} #end foreach for complete month
} #above handles months other than current below current
else { #partial current month below
foreach $num (1..$days){
if ( $num <= $day[2] - 1) {
@io =$d-> ct_sql("select sum(LogicalPageReads_ValSmp) from
dbo.engines where Timestamp between '$mon_num\/$num\/$yr 06:00' and
'$mon_num\/$num\/$yr 23:30'");
foreach my $ref (@io){
push (@dly_io,$$ref[0]);
}
} # Do current days of month till today
else { #fill rest of days with zero
push (@dly_io,0);
}
} # end foreach
} # end month check if
#---------------------------------------------------------------------
# do chart using charting module that generates png files
#---------------------------------------------------------------------
use Chart::Bars;
$g = Chart::Bars->new (600,400);
# x axis
$g->add_dataset (1..$days);
# y axis
$g->add_dataset (@dly_io);
$g->set ('title' => "Gems I/O for \u$month$yr");
$g->set ('colors' => {'y_label' => [0,0,255], y_label2 => [0,255,0],
'y_grid_lines' => [127,127,0], 'dataset0' => [127,0,0],
'dataset1' => [0,127,0], 'dataset2' => [0,0,127]});
$g->set ('y_label' => 'logical I/O');
$g->set ('max_val' => '2000000000');
$g->set ('min_val' => '0');
$g->set ('x_label' => 'Days');
$g->set ('y_grid_lines' => 'true');
$g->set ('legend' => 'none');
$g->png ("io.png");
#-------------------------------------------
# print out chart by calling another script to do the chart display
#-------------------------------------------
print img( {-src => "io.pl",
border => 2,
height => 400,
width => 600
});
} #end if param
#-----------------------------------------------------------------------
----
# get pw subroutine
#-----------------------------------------------------------------------
----
sub pw
{
#-----------------------------------------------------------------------
----
# chop($sapw) # removed cr
#-----------------------------------------------------------------------
----
open(RD, "cat /korn/sa.key |");
while (<RD>){
#--------------------------------
# search for password and return
#--------------------------------
#
if ( $_ =~ "SA_PASSWD") {
my @part = split("=",$_);
return $part[1];
}
}
} # end of sub pw
#######################################################################
# second script
#######################################################################
#!c:/perl/bin/perl.exe
#-----------------------------------------------------------------------
--
# program : io.pl
# author : krysd
# date : 11/16/2000
# purpose : script to display io chart in the db_chart.pl script
# :
# :
# modified:
#-----------------------------------------------------------------------
--
use CGI qw/:standard /;
binmode STDOUT;
print redirect('c:\program files\apache group\apache\cgi-bin\io.png');
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 16 Nov 2000 15:59:35 -0600
From: Jeff H <jeffahill@_ANTISPAM_.lucent.com>
Subject: Re: Converting Troff to Jpeg
Message-Id: <3A1458C7.86B08F44@_ANTISPAM_.lucent.com>
I appreciate your help on this, and my appologies to the group for the off
subject post.
Jeff
------------------------------
Date: Thu, 16 Nov 2000 23:04:51 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Converting Troff to Jpeg
Message-Id: <slrn918pvn.425.mgjv@verbruggen.comdyn.com.au>
On Thu, 16 Nov 2000 15:59:35 -0600,
Jeff H <jeffahill@_ANTISPAM_.lucent.com> wrote:
> I appreciate your help on this, and my appologies to the group for the off
> subject post.
You weren't really that offtopic, although the question probably would
have been more at place in clp.modules. The answers were though :)
Martien
--
Martien Verbruggen |
Interactive Media Division | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd. | enough features yet.
NSW, Australia |
------------------------------
Date: Thu, 16 Nov 2000 16:46:29 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Counting bracket matching
Message-Id: <Pine.GSO.4.21.0011161645320.265-100000@crusoe.crusoe.net>
[posted & mailed]
On Nov 16, Alun Moon said:
>I'm writing a simple program where I need to print out everything
>between the next opening bracket ( a `[' or a '}') and its closing
>counterpart. There are other [] {} pairs within.
Granted, this doesn't stop one from doing "))...((", but it makes sure
the numbers are the same:
if ($str =~ tr/(// == $str =~ tr/)//) {
# they're the same
}
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Thu, 16 Nov 2000 21:59:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Counting bracket matching
Message-Id: <51m81to80cdb260hhfvrifobnogt1a70q0@4ax.com>
Alun Moon wrote:
>I'm writing a simple program where I need to print out everything
>between the next opening bracket ( a `[' or a '}') and its closing
>counterpart. There are other [] {} pairs within.
My Spider sense is tingling. Text::Balanced! Yes, that's the ticket. See
<http://search.cpan.org/>
--
Bart.
------------------------------
Date: Thu, 16 Nov 2000 19:10:39 GMT
From: "EM" <me@privacy.net>
Subject: CRC Check
Message-Id: <PiWQ5.3795$Nw6.11905@news.iol.ie>
Is there a way to perform a CRC check on a file with perl?
Thanks in advance
Eric
------------------------------
Date: Thu, 16 Nov 2000 20:01:00 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: CRC Check
Message-Id: <slrn918f7p.4ut.tjla@thislove.dyndns.org>
I was shocked! How could EM <me@privacy.net>
say such a terrible thing:
>Is there a way to perform a CRC check on a file with perl?
Yes.
okay, okay just for you I went and looked on CPAN and there are a couple
of modules with the text "CRC" in their name.
http://search.cpan.org
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
I'd rather just believe that it's done by little elves running around.
------------------------------
Date: Thu, 16 Nov 2000 22:37:31 GMT
From: ameen @ dausha . net (Ameen Dausha)
Subject: Re: Date
Message-Id: <3a146173.176014862@news>
There is an 'oops' I will need to post regarding the failure of the
code I presented. I used the wrong module. Below is the script I ran
to benchmark Date::Manip:
use Date::Manip;
$start = &UnixDate("today", "%c");
for ($i = 0; $i <= 100000; $i++){
$today = &UnixDate("today", "%m/%d%/%y");
}
$finish = &UnixDate("today", "%c");
$d=&DateCalc($start,$finish,\$err);
print "Today=>$today\n";
print "Start=>$start\nFinish=>$finish\n";
print "Dirff=>$d\n";
Here is the return information:
Today=>11/16/00
Start=>Thu Nov 16 07:26:33 2000
Finish=>Thu Nov 16 07:41:30 2000
Dirff=>+0:0:0:0:0:14:57
So, the time to execute 100,000 cycles is
897 seconds, or .00897 of a second per cycle.
It also used up 25 percent of the CPU, but don't ask me to talk
processor or
memory of the server, because our network admins don't like to share.
Now, running the other proposed script--debugging it for the right
output:
use Date::Manip;
$start = &UnixDate("today", "%c");
for ($i = 0; $i <= 100000; $i++){
@now = (localtime)[3 .. 5];
$date = sprintf('%02d/%02d/%02d', ++$now[1], $now[0], $now[2] %
100);
}
$finish = &UnixDate("today", "%c");
$d=&DateCalc($start,$finish,\$err);
print "Today=>$today\n";
print "Start=>$start\nFinish=>$finish\n";
print "Dirff=>$d\n";
Resulted in:
Today=>11/16/00
Start=>Thu Nov 16 08:06:20 2000
Finish=>Thu Nov 16 08:06:40 2000
Dirff=>+0:0:0:0:0:0:20
CPU usage was 17 percent.
The script mentioned by the other fellow does run at roughly 2 percent
that of Date::Manip, or 44.85 times faster. :-) So, if speed is the
question, my solution sucks.
[snip]
Ben Wilson (a.k.a. Ameen, Last of the Dausha)
____________________________
-"Ever heard of Aristotle . . . Plato . . . Socrates?!"
-"Yes."
-"Morons!"
------------------------------
Date: Thu, 16 Nov 2000 22:41:28 GMT
From: ameen @ dausha . net (Ameen Dausha)
Subject: Re: Date
Message-Id: <3a1461ae.176073366@news>
On 16 Nov 2000 06:36:05 -0700, tchrist@perl.com (Tom Christiansen)
spat:
[snip]
>>I remember reading somewhere ("Perl Cookbook," perhaps?) that POSIX
>>was bad and so have never used it.
>
>I should very much like to see the quote there. This is hearsay.
>Don't spread rumors.
Tom, read an earlier post I wrote in reply to myself. By saying
"perhaps?" I am indicating I'm not sure and that I would validate my
source. My book is at work since the bulk of my work is there. I have
since looked and couldn't find it . . . so when I get home (which I am
now) I would have retracted.
I don't like spreading rumors.
>>But, since you use it because it is
>>faster than Date::Manip, please provide the benchmark.
>
>Oh, do not be silly. The Date::Manip behemoth is not a standard module.
>POSIX is. And localtime doesn't even require any modules.
Again, read my earlier post. I did a benchmark and found just how bad
it is . . . 44+ times slower. Although, reading your stuff I sit
amazed at the ease of it. :-)
>% perl -e 'system("ps v$$"); eval "use POSIX qw(strftime)"; system("ps v$$");'
> PID STAT TIME SL RE PAGEIN VSZ RSS LIM TSIZ %CPU %MEM COMMAND
>18814 S+ 0:00.02 0 0 0 736 780 116464 628 0.0 0.6 perl -e s
> PID STAT TIME SL RE PAGEIN VSZ RSS LIM TSIZ %CPU %MEM COMMAND
>18814 S+ 0:00.09 0 0 0 1084 1360 116464 628 0.0 1.0 perl -e s
>
>% perl -e 'system("ps v$$"); eval "use Date::Manip"; system("ps v$$");'
> PID STAT TIME SL RE PAGEIN VSZ RSS LIM TSIZ %CPU %MEM COMMAND
>25546 S+ 0:00.02 0 0 0 736 780 116464 628 0.0 0.6 perl -e s
> PID STAT TIME SL RE PAGEIN VSZ RSS LIM TSIZ %CPU %MEM COMMAND
>25546 S+ 0:00.78 0 0 0 3588 3860 116464 628 0.0 3.0 perl -e s
>
>That is incredibly horrible. You just paid a bonus 2.5M more for that
>module. And this is a svelt BSD system. Imagine it on Slwolaris!
Fortunate for me I have Slowlaris at work. ;-)
>The Camel has these examples (truncated):
>
> use POSIX qw(strftime);
> $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
> strftime(I<fmt>, I<sec>, I<min>, I<hour>, I<mday>, I<mon>, I<year>,
> $str = POSIX::strftime("%A, %B %d, %Y", 0, 0, 0, 12,
> $datestr = strftime("%Y-%m-%d", localtime);
> $datestr = strftime("%A %D", localtime);
>
>The Ram has these examples (truncated):
>
> use POSIX qw(strftime);
> print strftime "%Y-%m-%d\n", localtime;
> use POSIX qw(strftime);
> $STRING = strftime($FORMAT, $SECONDS, $MINUTES, $HOUR,
> use POSIX qw(strftime);
> print "strftime gives: ", strftime("%A %D", localtime($time)), "\n";
> use POSIX qw(strftime);
> print strftime("<P>Last script update: %c (%Z)\n", localtime($raw_time));
>
>
>But really, localtime() is the right answer.
>
>--tom
Ben Wilson (a.k.a. Ameen, Last of the Dausha)
____________________________
-"Ever heard of Aristotle . . . Plato . . . Socrates?!"
-"Yes."
-"Morons!"
------------------------------
Date: Thu, 16 Nov 2000 22:45:56 GMT
From: ameen @ dausha . net (Ameen Dausha)
Subject: Re: Date
Message-Id: <3a1462cd.176361146@news>
On Thu, 16 Nov 2000 10:49:17 -0000, "Dave Cross" <dave@dave.org.uk>
spat:
[snip]
>> I looked at these documents:
>> http://search.cpan.org/doc/SBECK/DateManip-5.39/README
>> http://www.engelschall.com/ar/perldoc/pages/module/Date::Manip.html
>>
>> Nothing containing this. As I lack the module in this environment, I
>> will have to check at work tomorrow.
>
>It's in <http://search.cpan.org/doc/SBECK/DateManip-5.39/Manip.pod> in a
>section clearly entitled "SHOULD I USE DATE::MANIP".
Yep, read it. Humble tea is good in the evening.
>> >Let's see how really difficult it is with localtime:
>> >
>> >my @now = (localtime)[3 .. 5];
>> >my $date = sprintf('%02d/%02d%0d2', ++$now[2], $now[1], $now[3] % 100);
>> >
>> >Doesn't look that tricky to me.
>>
>> Dave, I don't mean to be a pain, but, I tried your solution--by
>> cutting and pasting into a test script. Here is the script I used:
>
>[snip discussion of embarassing bugs in my code]
Sorry, didn't mean to embarass.
>Yes, there were three bugs in my script. I omitted the second '/' from the
>output, I 'munged' the sprintf output template and for some reason I was
>assuming that the @now array was indexed from 1! (Memo to self: don't post
>untested code to clpm before first cup of coffee - in fact, don't post
>untested code to clpm at all)
>
>The script should be:
>
>my @now = (localtime)[3 .. 5];
>my $date = sprintf('%02d/%02d/%02d', ++$now[1], $now[0], $now[2] % 100);
>print "Date=>$date<=\n";
>
>> >I've benchmarked similar solutions, comparing localtime with Date::Manip
>and
>> >have found the localtime solution to be up to 30 times faster.
>>
>> I received a private email with a similar assertion, but I would like
>> to see benchmark data. Since my personal web host provider lacks
>> Date::Manip I will have to do this at work. I will run the command I
>> mentioned earlier in this thread 1 million times and tally the time. I
>> will also do the same with your script and tally that time. I am
>> curious to see the duration of both since I'm not sure of the timing.
>
>Here's my script comparing localtime, POSIX::strftime and
>Date::Manip::DateCalc.
>(Note that I haven't included the module load time in the comparison)
>
>#!/usr/local/bin/perl -w
>
>use strict;
>use Benchmark;
>use Date::Manip;
>use POSIX 'strftime';
>
>sub builtin {
> my @now = (localtime)[3 .. 5];
> return sprintf("%02d/%02d/%02d", ++$now[1], $now[0], $now[2] % 100);
>}
>
>sub posix {
> return strftime('%m/%d/%y', localtime);
>}
>
>sub date_man {
> return &DateCalc('today', '%m/%d/%y');
>}
>
>timethese(5000, { builtin => \&builtin,
> posix => \&posix,
> date_man => \&date_man });
>
>And here are the results from a typical run:
>
>Benchmark: timing 5000 iterations of builtin, date_man, posix...
> builtin: 4 wallclock secs ( 3.12 usr + 0.03 sys = 3.15 CPU)
> date_man: 301 wallclock secs (266.78 usr 0.11 sys + 0.01 cusr 0.05 csys
>= 0.00 CPU)
> posix: 5 wallclock secs ( 4.43 usr + 0.05 sys = 4.48 CPU)
>
>Pretty conclusive stuff, I hope you'll agree. I thought it was 30 times
>faster, but on this test it seems to be 75 times faster!
I tried a very sloppy method and got 45 times. Alas, I just now got
home to post.
>> But, if you're only going to do this once, why worry about jiffies?
>> After all, how many times are you going to want to know what the
>> month/day/year stamp for "today" is.
>
>Potentially quite a lot if you're writing timestamps into a log file or
>something like that.
Yes, timestamps. Very true. I suppose I imagine that he would have
gone for the date once. I only recently started dabbling with
Date::Manip because it makes things a bit easier to maintain . . . in
a shop where Perl maintenance is sometimes difficult.
>hth,
>Dave...
Ben Wilson (a.k.a. Ameen, Last of the Dausha)
____________________________
-"Ever heard of Aristotle . . . Plato . . . Socrates?!"
-"Yes."
-"Morons!"
------------------------------
Date: Thu, 16 Nov 2000 22:47:29 GMT
From: ameen @ dausha . net (Ameen Dausha)
Subject: Re: Date
Message-Id: <3a1463bf.176602258@news>
On Thu, 16 Nov 2000 14:08:29 GMT, Bart Lateur <bart.lateur@skynet.be>
spat:
>ameen @ dausha . net (Ameen Dausha) wrote:
>
>>Yes, buy with localtime don't you need to incriment the month and day?
>>Don't you need to handle the fact that this is Perl Year 100? Granted,
>>that can be handled by adding a few lines of code, but:
>
>A few lines of code?
>
> @now = localtime;
> $today = sprintf "%02d/%02d/%02d", 1+$now[4], $now[3], $now[5]%100;
>
>I fail to see the "few lines" here.
Well, if you put a space between the first and second line you get
three lines . . . and that makes 'a few.' Thanks for the clarification
guys.
>--
> Bart.
Ben Wilson (a.k.a. Ameen, Last of the Dausha)
____________________________
-"Ever heard of Aristotle . . . Plato . . . Socrates?!"
-"Yes."
-"Morons!"
------------------------------
Date: Thu, 16 Nov 2000 22:50:06 GMT
From: ameen @ dausha . net (Ameen Dausha)
Subject: Re: Date
Message-Id: <3a146457.176754931@news>
On Thu, 16 Nov 2000 10:49:17 -0000, "Dave Cross" <dave@dave.org.uk>
spat:
[snip]
>Yes, there were three bugs in my script. I omitted the second '/' from the
>output, I 'munged' the sprintf output template and for some reason I was
>assuming that the @now array was indexed from 1! (Memo to self: don't post
>untested code to clpm before first cup of coffee - in fact, don't post
>untested code to clpm at all)
[snip]
Hmm, should have seen where you were so I would have taken the coffee
factor into account. I also posted bad code, so there's egg to share.
Ben Wilson (a.k.a. Ameen, Last of the Dausha)
____________________________
-"Ever heard of Aristotle . . . Plato . . . Socrates?!"
-"Yes."
-"Morons!"
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 4904
**************************************