Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Utterly BIZARRE behavior of IO::All vs glob

Reply
Thread Tools

Utterly BIZARRE behavior of IO::All vs glob

 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      06-14-2005
This is the most bizarre thing I have ever encountered. I was able
(with some difficulty) to figure out what was going on, but I still
don't know why.

Consider this simple example script which looks for files and adds them
to a zip archive:

#!/usr/bin/perl -w
use IO::All;
use Archive::Zip;
use Digest::MD5 qw/md5_hex/;
use strict;

my $zip = Archive::Zip -> new();
my $dir = '/my/path';
my $item = 'ETN599827';

foreach my $file(sort glob ("$dir/$item*")) {
print "PROCESSING: '$file' - @{[md5_hex $file]}\n";
$zip -> addFile($file , io($file)->filename )
|| warn "Could not add $file\n";
}

THAT WORKS FINE. There is a debugging statement which prints the
filename and the filename's md5sum, which outputs thus:

PROCESSING: '/my/path/ETN599827.txt' - 0d8572577b458ded778efd0d88c6cf05

But I prefer the flexibility IO::All, and lately I've been using that
module exclusively for my IO needs.

So what happens when I replace the glob with an IO::All statement
(one-line change):

foreach my $file (io($dir)-> filter(sub {$_->name =~
/$item.*/})->all_files) {
print "PROCESSING: '$file' - @{[md5_hex $file]}\n";
$zip -> addFile($file , io($file)->filename )
|| warn "Could not add $file\n";
}

Perl outputs thus:

&Digest::MD5::md5_hex function called with reference argument at
test.pl line 29.
PROCESSING: '/my/path/ETN599827.txt' - 0d8572577b458ded778efd0d88c6cf05
stat() on unopened filehandle GEN535 at
..../site_perl/5.8.4/Archive/Zip.pm line 2503.
Could not add /my/path/ETN599827.txt

The Digest::MD5 and Archive::Zip messages are courtesy of "-w" - they
don't print if warnings are not enabled.

The IO::All function SEEMS to be returning a plain, ordinary scalar
value whose MD5SUM is IDENTICAL to the result from the glob. This
debugging statement is returning the identical result:
print "PROCESSING: '$file' - @{[md5_hex $file]}\n";
But Perl seems to think it's some type of reference when it comes
from IO::All.

This is Perl 5.8.4 built on AIX 5.1 using IO::All 0.33

I'm very interested to learn more about what is happening. Does
anyone have any ideas or suggestions? Thanks!

 
Reply With Quote
 
 
 
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      06-14-2005
Also sprach http://www.velocityreviews.com/forums/(E-Mail Removed):

> But I prefer the flexibility IO::All, and lately I've been using that
> module exclusively for my IO needs.
>
> So what happens when I replace the glob with an IO::All statement
> (one-line change):
>
> foreach my $file (io($dir)-> filter(sub {$_->name =~
> /$item.*/})->all_files) {
> print "PROCESSING: '$file' - @{[md5_hex $file]}\n";
> $zip -> addFile($file , io($file)->filename )
> || warn "Could not add $file\n";
> }
>
> Perl outputs thus:
>
> &Digest::MD5::md5_hex function called with reference argument at
> test.pl line 29.
> PROCESSING: '/my/path/ETN599827.txt' - 0d8572577b458ded778efd0d88c6cf05
> stat() on unopened filehandle GEN535 at
> .../site_perl/5.8.4/Archive/Zip.pm line 2503.
> Could not add /my/path/ETN599827.txt
>
> The Digest::MD5 and Archive::Zip messages are courtesy of "-w" - they
> don't print if warnings are not enabled.
>
> The IO::All function SEEMS to be returning a plain, ordinary scalar
> value whose MD5SUM is IDENTICAL to the result from the glob. This
> debugging statement is returning the identical result:
> print "PROCESSING: '$file' - @{[md5_hex $file]}\n";
> But Perl seems to think it's some type of reference when it comes
> from IO::All.


My suspicion is that IO::All returns objects with overloaded
stringification. Digest::MD5::md5_hex checks whether its argument is an
object and, in case its not an instance of Digest::MD5, barfs.

I am not really surprised that modules such as IO::All which
incorporates every conceivable seemingly smart trickery would sooner or
later exhibit strange interaction with other modules. That's the price
you have to pay if you prefer laziness over robustness.

Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854 220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($ m+=<=200);
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SOLVED - Utterly BIZARRE behavior of IO::All vs glob usenet@DavidFilmer.com Perl Misc 0 12-08-2005 06:37 AM
glob.glob unicode bug or feature Elbert Lev Python 5 08-02-2004 12:09 AM
Question about glob.glob <--newbie Sean Berry Python 3 05-04-2004 05:34 PM
RE: Bug in glob.glob for files w/o extentions in Windows Tim Peters Python 1 12-01-2003 09:22 AM
Bug in glob.glob for files w/o extentions in Windows Georgy Pruss Python 15 12-01-2003 04:04 AM



Advertisments