jdhedden has asked for the wisdom of the Perl Monks concerning the following question:

IO::All is GREAT!!! However, I may have found a bug, or it may be just a problem on my part. I read the docs, and am using version 0.15.

This simple example assumes you're in a directory with only files (no sub-dirs). The following works fine:

my @files = <*>; io($files[0]) > io('/tmp/'. $files[0]);
However, the following:
my @files = io('.')->all_files; io($files[0]) > io('/tmp/'. $files[0]);
complains as follows:

Undefined behavior for overloaded IO::All operation: 'unknown > unknown' at /usr/lib/perl5/site_perl/5.8.2/IO/All.pm line 840.

What's wrong?

Replies are listed 'Best First'.
Re: IO::All problem/bug?
by dragonchild (Archbishop) on Mar 19, 2004 at 20:02 UTC
    Double-check to make sure that the second version isn't returning back IO::All objects. :-)

    ------
    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      You are correct. @files does contain a list of IO::All objects. The docs do say that IO::All objects 'scalar' to their names. That's why when I printed out @files, I got a list of names. This is the fix to my original problem:
      my @files = io('.')->all_files; $files[0] > io('/tmp/' . $files[0]->name);

        Or simpler

        my @files = io('.')->all_files; $files[0] > io( "/tmp/$files[0]" );

        By forcibly stringifying your original solution should work as well:

        my @files = io('.')->all_files; io( "$files[0]" ) > io( "/tmp/$files[0]" );

        But I don't want to be the maintenance programmer then..

        But, are you using @files at all otherwise? Sounds like you just want the first — in which case I'd use

        my $file = io( '.' )->next; $file > io( "/tmp/$file" );

        Also, are you sure you need the file named after the original? If not, it's better to let IO::All pick a temporary name for you.

        my $tmp = io; io( '.' )->next > $tmp;

        Makeshifts last the longest.