[EMAIL PROTECTED] wrote:
Hello,

Hello,

did someone know why the code1 version works and the
condensed code2 don't??  $TempShapes_folder is something
like 'C:.../TempShapes/


code1:

opendir(DIR, "$TempShapes_folder") || die "folder not found: $!";
@File_list_TempShapes = grep(/\.png$/, readdir(DIR));
closedir(DIR);
opendir(DIR, "$TempShapes_folder") || die "folder not found: $!";
@File_list_TempShapes2 = grep(/\.PNG$/, readdir(DIR));
closedir(DIR);
push(@File_list_TempShapes, @File_list_TempShapes2);
opendir(DIR, "$TempShapes_folder") || die "folder not found: $!";
@File_list_TempShapes3 = grep(/\.jpg$/, readdir(DIR));
closedir(DIR);
push(@File_list_TempShapes, @File_list_TempShapes3);
opendir(DIR, "$TempShapes_folder") || die "folder not found: $!";
@File_list_TempShapes4 = grep(/\.JPG$/, readdir(DIR));
closedir(DIR);
push(@File_list_TempShapes, @File_list_TempShapes4);


code2:

opendir(DIR, "$TempShapes_folder") || die "folder not found: $!";
@File_list_TempShapes  = grep(/\.png$/, readdir(DIR));
@File_list_TempShapes2 = grep(/\.PNG$/, readdir(DIR));
@File_list_TempShapes3 = grep(/\.jpg$/, readdir(DIR));
@File_list_TempShapes4 = grep(/\.JPG$/, readdir(DIR));
closedir(DIR);
push(@File_list_TempShapes, @File_list_TempShapes2,
@File_list_TempShapes3, @File_list_TempShapes4);

perldoc -f readdir
    readdir DIRHANDLE
            Returns the next directory entry for a directory opened by
            "opendir".  If used in list context, returns all the rest of the
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            entries in the directory.  If there are no more entries, returns
            ^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            an undefined value in scalar context or a null list in list
                                                    ^^^^^^^^^^^^^^^^^^^
            context.
            ^^^^^^^^

The first readdir returns all the entries. The second, third and fourth readdir return a null list.

You probably want something like this:


opendir DIR, $TempShapes_folder or die "folder not found: $!";
my @File_list_TempShapes = grep /\.(?i:png|jpg)\z/, readdir DIR;
closedir DIR;




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to