[29270] in Perl-Users-Digest
Perl-Users Digest, Issue: 514 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 14 14:14:23 2007
Date: Thu, 14 Jun 2007 11:14:14 -0700 (PDT)
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, 14 Jun 2007 Volume: 11 Number: 514
Today's topics:
Re: Perl Bug??? <bik.mido@tiscalinet.it>
Re: Perl Bug??? <bik.mido@tiscalinet.it>
Re: Perl Bug??? <mritty@gmail.com>
Perl script to identify corrupt mbox messages? <tuxedo@mailinator.net>
Re: Perl script to identify corrupt mbox messages? <glennj@ncf.ca>
Re: Perl script to identify corrupt mbox messages? <tuxedo@mailinator.net>
Perl system call fails under windows 2003 server rahulkats@gmail.com
Re: perl vs C for CGI <bik.mido@tiscalinet.it>
Re: Regex OR Operator <rvtol+news@isolution.nl>
Runtime disparity - Same program in Perl and Ruby <kaldrenon@gmail.com>
SWF thumbnail module <nutyo@nutyo.com>
Re: Useless use of array element in void context <rvtol+news@isolution.nl>
Re: Win32: How to quit perl script during log off autom <rprp@gmx.net>
Writing row at a time in Excel using OLE <ashishrai@gmail.com>
Re: Writing row at a time in Excel using OLE <anton.vandersteen@chello.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 14 Jun 2007 19:22:47 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl Bug???
Message-Id: <o8u273pn2adgf1b8nhjnn0oh7t1q8p2r5i@4ax.com>
On Wed, 13 Jun 2007 19:55:44 -0000, usenet@DavidFilmer.com wrote:
>> Pooh. I'm sure then are dozens of bugs in perl. Perl evolves. New bugs
>> get added every year.
>
>I don't think Paul was claiming that Perl has no bugs. I think he was
>pointing out that it is unlikely that a noob would actually uncover a
>genuine bug with nothing more than a small, simple test program (and
>that immediately suspecting a language fault instead of user-error is
>implausible).
Suspecting a bug *is* generally plausible: except that it's generally
expected to reside in wetware.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 14 Jun 2007 19:28:24 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl Bug???
Message-Id: <jlu273h3sotivle2m9h8gd2a97s5t64v3t@4ax.com>
On Wed, 13 Jun 2007 16:21:03 -0400, "Mike Thorland"
<Mike.Thorland@sas.com> wrote:
>I never realized that in Perl loop variables allow you to directly change
>the contents of an array. I always thought they were merely a copy.
You assumed wrong:
gin:~ [19:24:50]$ perl -le '@a=qw/foo bar/;$_ x= 2,print for @a'
foofoo
barbar
>"Paul Lalli" <mritty@gmail.com> wrote in message
You also quoted wrong, BTW.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 14 Jun 2007 10:33:03 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Perl Bug???
Message-Id: <1181842383.887716.36780@e9g2000prf.googlegroups.com>
On Jun 14, 1:28 pm, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On Wed, 13 Jun 2007 16:21:03 -0400, "Mike Thorland"
>
> <Mike.Thorl...@sas.com> wrote:
> >I never realized that in Perl loop variables allow you to directly change
> >the contents of an array. I always thought they were merely a copy.
>
> You assumed wrong:
>
> gin:~ [19:24:50]$ perl -le '@a=qw/foo bar/;$_ x= 2,print for @a'
> foofoo
> barbar
While you're correct that the OP's assumption was wrong, this example
does not demonstrate that. Here, you're only printing $_ within the
loop. If the OP had been correct and $_ was in fact a copy of the
values of @a, the output would be the same. The example you meant to
type was:
perl -le'@a=qw/foo bar/; $_ x= 2 for @a; print for @a;'
Paul Lalli
------------------------------
Date: Thu, 14 Jun 2007 16:06:00 +0200
From: Tuxedo <tuxedo@mailinator.net>
Subject: Perl script to identify corrupt mbox messages?
Message-Id: <f4ri08$jg2$02$1@news.t-online.com>
I'm trying to repair a gigantic mbox file that appears to have been
corrupted in that it displays only 17 of the most recent and total 3087
messages contained in the actual file.
The mail application used is Mozilla on Windows. The exact same error
occurs in all Mozilla applications I tested the file with, i.e. the full
Mozilla suite, the most recent Seamonkey and the stand-alone Thunderbird.
The identical error also happens when testing the mbox in Mozilla
Thunderbird on a Linux system.
I've tried to fix the error by manually removing the message just before
the first message shown in the index, but this does not seem to be the
(only) position of the culprit. The same mbox works entirely when viewed in
for example MUTT or the standard KDE mail client, Kmail. In other words,
the error may partly be attributed to how Mozilla parses it's own mbox and
partly to any incorrectly formatted messages. Perhaps there are several
incorrectly formatted messages, in the form of junk mail, which have been
intentionally or not crafted to currupt standard mbox files within Mozilla.
Does anyone have or know of a perl script that traverses through an mbox
file and that can identify incorrectly formatted mail messages within?
Tuxedo
--
"Imagine if every Thursday your shoes exploded if you tied them the
usual way. This happens to us all the time with computers, and nobody
thinks of complaining."
-- Jeff Raskin, interviewed in Doctor Dobb's Journal
------------------------------
Date: 14 Jun 2007 15:38:33 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Perl script to identify corrupt mbox messages?
Message-Id: <slrnf72o7q.93t.glennj@smeagol.ncf.ca>
At 2007-06-14 10:06AM, "Tuxedo" wrote:
> I'm trying to repair a gigantic mbox file that appears to have been
> corrupted in that it displays only 17 of the most recent and total 3087
> messages contained in the actual file.
>
> The mail application used is Mozilla on Windows. The exact same error
> occurs in all Mozilla applications I tested the file with, i.e. the full
> Mozilla suite, the most recent Seamonkey and the stand-alone Thunderbird.
>
> The identical error also happens when testing the mbox in Mozilla
> Thunderbird on a Linux system.
>
> I've tried to fix the error by manually removing the message just before
> the first message shown in the index, but this does not seem to be the
> (only) position of the culprit. The same mbox works entirely when viewed in
> for example MUTT or the standard KDE mail client, Kmail. In other words,
> the error may partly be attributed to how Mozilla parses it's own mbox and
> partly to any incorrectly formatted messages. Perhaps there are several
> incorrectly formatted messages, in the form of junk mail, which have been
> intentionally or not crafted to currupt standard mbox files within Mozilla.
>
> Does anyone have or know of a perl script that traverses through an mbox
> file and that can identify incorrectly formatted mail messages within?
Make sure that supposedly empty lines are in fact empty (no stray spaces
or carriage returns). Check for the proper existence of /^From / lines
following a blank line (except for the first line of the mbox) which are
the indicator for a message in an mbox file.
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Thu, 14 Jun 2007 19:17:20 +0200
From: Tuxedo <tuxedo@mailinator.net>
Subject: Re: Perl script to identify corrupt mbox messages?
Message-Id: <f4rt70$87s$03$2@news.t-online.com>
Glenn Jackman wrote:
[...]
> Make sure that supposedly empty lines are in fact empty (no stray spaces
> or carriage returns). Check for the proper existence of /^From / lines
> following a blank line (except for the first line of the mbox) which are
> the indicator for a message in an mbox file.
>
Many thanks for those pointers!
------------------------------
Date: Thu, 14 Jun 2007 11:08:42 -0700
From: rahulkats@gmail.com
Subject: Perl system call fails under windows 2003 server
Message-Id: <1181844522.160422.6980@i38g2000prf.googlegroups.com>
Hi,
I'm having trouble with perl system call. The system call calls
ntbackup.exe , the windows inbuilt utiility but the system errors out
by saying cannot find ntbackup.exe even after giving the full path.
I'm using windows 2003 server with Perl 5.8
Any suggestions?
Thanks
------------------------------
Date: Thu, 14 Jun 2007 19:11:29 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: perl vs C for CGI
Message-Id: <4kt273t2nu87nla4ltfnnk4v2r2uk3srde@4ax.com>
On Wed, 13 Jun 2007 14:35:50 +0200, "Peter J. Holzer"
<hjp-usenet2@hjp.at> wrote:
>If you don't convert the *script* (as opposed to print statements within
>the script), apache probably can't even start the script because the
>linux kernel will try to invoke "/usr/bin/perl\r" which doesn't exist.
BTW: I've always wondered... how 'bout HERE docs? Are they portable
across platforms or is the line ending deemed to be that of the
script. Is the question clear enough, BTW?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 14 Jun 2007 10:24:28 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Regex OR Operator
Message-Id: <f4r540.1h4.1@news.isolution.nl>
Greg Bacon schreef:
> This sort of pattern will look much nicer in Perl 6. Fingers crossed.
In Perl 5.10 too.
:)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 14 Jun 2007 16:29:18 -0000
From: Kaldrenon <kaldrenon@gmail.com>
Subject: Runtime disparity - Same program in Perl and Ruby
Message-Id: <1181838558.894595.146220@g37g2000prf.googlegroups.com>
Hi all (this is going to comp.lang.ruby and comp.lang.perl.misc),
The other day I wrote a basic program in Perl, and the following day I
rewrote it in Ruby. I'm curious about the differences in runtime of
the two versions, though.
Let me start by describing the program (I'll append full code for both
to the end): it reads in a list of alphanumeric codes from file
(format is [\w\d\S]+_\d{3}, but they're separated by a comma in the
file), then creates a hash with those codes as keys and empty arrays
as values. After the hash is built, the program traverses through a
given directory and its subdirectories (using File::Find in Perl and
Find.find in Ruby) and checks each file against the hash of codes
(with a few regexps and conditions to prevent lots of unnecessary
looping), adding it to the array for a code if the code is found in
the filename. Finally, it writes the contents of the hash to a .csv
file in the format CODE,PATH for each match.
Now, if it were the case that Ruby or Perl were simply -slower- than
the other, I wouldn't be bothering you folks. But here's where it gets
a little unusual: the number of elements in the code list has a
noticeable impact on the run time of the Ruby version, but far less on
the Perl version. I ran each one a few times with code lists of
various sizes, and they both print start/stop timestamps at the end,
so I collected the data:
Entries | Seconds
Ruby
4 | 153
64 | 133
256 | 222
512 | 327
1024 | 562
1500 | 683
Perl
4 | 291
64 | 258
256 | 253
512 | 248
1024 | 353
1500 | 363
Ruby runs faster for low numbers of entries, as you can see, but once
you get up to 1500, Ruby's time has more than tripled while Perl's
time has gone up about a fifth.
I've looked over the code for both versions several times, and I don't
see any significant differences. The only important feature the Ruby
version lacks is the sort() before writing the file.
I'd really appreciate any insight into why Ruby's runtime grows so
readily and Perl's does not.
Code of both versions follows.
Thanks,
Andrew Fallows
use File::Find;
use strict;
use warnings;
my $code;
my $type;
my %filecodes = ();
my $start_time = "Started: " . localtime();
$| = 1; #Enables flush on print.
$\ = "\n"; #Automatic newlines on print
open(ITEM_LIST, "(path)") or die "Error";
# This loop builds a hash whose keys are the codes/types from file
# and whose values are references to empty arrays
while(my $item = <ITEM_LIST>)
{
$item =~ s/,/_/;
$item =~ s/\n//g;
print $item;
my @files = ();
$filecodes{$item} = \@files;
}
print "Hash built";
# Uses File::Find to iterate over the entire subdirectory
find(\&file_seek, "(path)");
# The searching portion: gets each location from File::Find, then
compares it
# to all the targets. If there is a match, prints a message and adds
that file
# to the related array.
sub file_seek
{
my $file = $_;
# Kicks out if the file in question is not of the necessary format
if(!(-f $file) || !($file =~ /^[\d\w\S]+_\d{3}/)){ return; }
foreach my $target (keys(%filecodes))
{
# If the file name contains the code sought
if($file =~ /$target/)
{
print "found $file in $File::Find::dir";
# Jumps out if the list for this code already contains this file.
for (0..@{$filecodes{$target}})
{
if(defined(${$filecodes{$target}}[$_])
&& $File::Find::name eq ${$filecodes{$target}}[$_]) {return; }
}
push(@{$filecodes{$target}}, $File::Find::name);
}
}
}
# After the whole directory has been searched, prints each key and all
# values found for it.
open(RESULTS, "> (path)") or die "Error 2";
foreach my$target ( sort(keys( %filecodes )))
{
my @results = @{$filecodes{$target}};
if(@results == 0) { push(@results, "NO FILES FOUND") }
print $target;
foreach (@results)
{
print RESULTS "$target,$_";
print "\t$_";
}
}
close RESULTS;
print $start_time;
print "Ended: " . localtime();
Ruby:
class FileSearcher
$\ = "\n"
in_file = File.open( "(path)","r")
start_time = Time.now
filecodes = Hash.new
# This loop reads all the item codes in from file and then
# adds them to a hash, each linked to its own empty array
while item = in_file.gets
item = item.gsub(',','_')
item = item.gsub("\n","")
files = Array.new
files.push("empty");
filecodes[item]= files
end
in_file.close
# The searching portion: looks at each file/location, then compares
it
# to all the targets. If there is a match, prints a message and
adds
# that file to the related array.
require "Find"
require 'ftools'
Find.find("(path)") do |file|
if !(FileTest.file?(file)) || !(File.basename(file) =~ /^[\d\w\S]+_
\d{3}/)
next
else
filecodes.each_key do |target|
if(file =~ /#{target}/)
puts "found " + target + " at " + file
$stdout.flush
fail = 0
for i in 0..filecodes[target].size-1 do
if(filecodes[target][i] != "empty" &&
File.basename(file) == File.basename(filecodes[target]
[i]))
fail = 1
break
end
end
if fail == 0
if filecodes[target][0] == "empty"
filecodes[target][0] = file
else
filecodes[target].push(file)
end
end
end
end
end
end
# After the whole directory has been searched, prints each key and
all
# values found for it to a file called Ruby_results.csv.
target_file = File.open("(path)","w")
filecodes.each_key do |target|
results = filecodes[target]
if results[0] == "empty"
results[0] = "NO FILES FOUND"
end
puts target
for i in 0..(results.size-1)
target_file.puts target + "," + results[i]
end
end
target_file.close
end_time = Time.now
puts "Started: " + start_time.to_s
puts "Ended: " + end_time.to_s
end
------------------------------
Date: Thu, 14 Jun 2007 04:00:27 -0500
From: "NUTYO" <nutyo@nutyo.com>
Subject: SWF thumbnail module
Message-Id: <1181811627_2485@sp12lax.superfeed.net>
Hello Everyone,
Is there a module which extracts the first(or given) frame of a .swf file as a picture format such as jpg or gif or png etc..?
So I can resize this picture frames inorder to make them thumbnails.
Thank you...
------------------------------
Date: Thu, 14 Jun 2007 10:27:08 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Useless use of array element in void context
Message-Id: <f4s6io.1c0.1@news.isolution.nl>
Paul Lalli schreef:
> Dr.Ruud:
>> Marek:
>>> This is looking really genius! But this gives me a syntax
>>> error! I probably misunderstood something?
>>
>> What did you try,
>
> Er. Presumably the line of quote directly above the text
> that you just quoted...
Not if you believe his use of "[T]his".
:)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 14 Jun 2007 14:45:49 +0200
From: Reinhard Pagitsch <rprp@gmx.net>
Subject: Re: Win32: How to quit perl script during log off automatically ?
Message-Id: <4671387e$0$90268$14726298@news.sunsite.dk>
Peter Sobisch wrote:
> Lambik <lambik@kieffer.nl> schrieb:
>>> on Unix its a simplest thing, perl do it for me or I can set $SIG{HUP} :-)
>>> but, how can I do this in Windows ?
>>>
>>> Every time I try to shutdown or log off, pop-up is comming up with
>>> "application doesn't response" and expecting to kill by clicking a
>>> button -> very dirty thing :-/
>>>
>>> So, I tried to catch WM_QUERYENDSESSION (using Win32::GUI::Hook), but no
>>
>> You should reveive a WM_CLOSE according to Bill.
>
>
> not really, I'm affraid windows doesn't sent neither WM_CLOSE nor
> WM_QUIT because of the same reason of not sending WM_QUERYENDSESSION.
>
> There must be something more in the Win32-universe :-)
Have you also read the MSDN documentation about SetConsoleCtrlHandler?
The last paragraph say:
The system generates CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and
CTRL_SHUTDOWN_EVENT signals when the user closes the console, logs off,
or shuts down the system so that the process has an opportunity to clean
up before termination. Console functions, or any C run-time functions
that call console functions, may not work reliably during processing of
any of the three signals mentioned previously. The reason is that some
or all of the internal console cleanup routines may have been called
before executing the process signal handler.
Can you send me the code you are using, maybe I can find it out why the
Win32::API::Callback Module crashes.
regards,
Reinhard
--
PM Mails an rpirpag <at> gmx dot at
------------------------------
Date: Thu, 14 Jun 2007 10:49:51 -0700
From: Ash <ashishrai@gmail.com>
Subject: Writing row at a time in Excel using OLE
Message-Id: <1181843391.577838.285570@j4g2000prf.googlegroups.com>
Hi!
I need to write a row at a time or a whole sheet at a time, anything
faster than one cell at a time in Excel sheet using Win32::OLE. Can
anyone help me?
Spreadsheet::WriteExcel module have functions for writing row at a
time but I need to modify existing Excel file and the module does not
allow that.
Thank you in advance!
------------------------------
Date: Thu, 14 Jun 2007 11:05:55 -0700
From: "anton.vandersteen@chello.nl" <anton.vandersteen@chello.nl>
Subject: Re: Writing row at a time in Excel using OLE
Message-Id: <1181844355.036271.313770@z28g2000prd.googlegroups.com>
On Jun 14, 7:49 pm, Ash <ashish...@gmail.com> wrote:
> Hi!
>
> I need to write a row at a time or a whole sheet at a time, anything
> faster than one cell at a time in Excel sheet using Win32::OLE. Can
> anyone help me?
>
> Spreadsheet::WriteExcel module have functions for writing row at a
> time but I need to modify existing Excel file and the module does not
> allow that.
>
> Thank you in advance!
Hey,
You must look for the package Spreadsheet::WriteExcel
With this package you can create an Excel document realy fast.
With the Perl listing below I create an Excel file first and then I
write data in it based on an sql statement.
In this example I did use an connection to an Access database.
Have fun.
#!perl/bin/perl
use Spreadsheet::WriteExcel;
use DBI;
# Create a new Excel workbook called perl.xls
my $excel_file = $ent2 -> get();
my $workbook = Spreadsheet::WriteExcel->new($excel_file);
my $worksheet = $workbook->addworksheet();
$sqlstatement9= $txt1->get('0.0','end');
#open connection to Access database
$dbh9 = DBI->connect('dbi:ODBC:driver=microsoft access driver
(*.mdb);dbq=C:\dump9\MS_Access.mdb');
#prepare and execute SQL statement
$sth9 = $dbh9->prepare($sqlstatement9);
$sth9->execute ||
die "Could not execute SQL statement ... maybe invalid?";
my $i=0;
#output database results
while (@row=$sth9->fetchrow_array())
{
$worksheet->write($i, 0, @row[0]);
$worksheet->write($i, 1, @row[1]);
$worksheet->write($i, 2, @row[2]);
$worksheet->write($i, 3, @row[3]);
$worksheet->write($i, 4, @row[4]);
$worksheet->write($i, 5, @row[5]);
$worksheet->write($i, 6, @row[6]);
$worksheet->write($i, 7, @row[7]);
$worksheet->write($i, 8, @row[8]);
$worksheet->write($i, 9, @row[9]);
$worksheet->write($i, 10, @row[10]);
$worksheet->write($i, 11, @row[11]);
$worksheet->write($i, 12, @row[12]);
$worksheet->write($i, 13, @row[13]);
$worksheet->write($i, 14, @row[14]);
$worksheet->write($i, 15, @row[15]);
$worksheet->write($i, 16, @row[16]);
$worksheet->write($i, 17, @row[17]);
$worksheet->write($i, 18, @row[18]);
$worksheet->write($i, 19, @row[19]);
$worksheet->write($i, 20, @row[20]);
$worksheet->write($i, 21, @row[21]);
$worksheet->write($i, 22, @row[22]);
$worksheet->write($i, 23, @row[23]);
$worksheet->write($i, 24, @row[24]);
$worksheet->write($i, 25, @row[25]);
$worksheet->write($i, 26, @row[26]);
$worksheet->write($i, 27, @row[27]);
$worksheet->write($i, 28, @row[28]);
$worksheet->write($i, 29, @row[29]);
$worksheet->write($i, 30, @row[30]);
$i=$i+1;
};
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 514
**************************************