Are you sure you want a hash? The whole point of a hash is to create an
array with custom indexes instead of consecutive numbers.
In any case, I think what you are looking for is readdir(). This will
return an array with the files in a directory. The following code will
populate the @files array with the contents of the mydir directory.
opendir(DIR,"mydir");
@files = readdir(DIR);
-----Original Message-----
From: Jonathan E. Paton
To: [EMAIL PROTECTED]
Sent: 3/11/02 6:15 AM
Subject: Re: easy way to make a hash of filenames?
> so I have a dir with files:
>
> /dir/foo.jpg
> bar.jpg
>
> and I want a
>
> %hashtable = (
> 1 => 'foo',
> 2 => 'bar'
> )
>
> how can this be done ?
Try map:
%hashtable = map { $ctr++, $_ } @files;
Or even:
%hashtable = map { $ctr++, $_ } <*>;
Of course, I've probably got the syntax wrong - since I
don't use map that often. You can, of course, write many
programs in terms of sub/map like:
sub add {
return map {
#do processing
} @_;
}
which can really annoy your coworkers.
Jonathan Paton
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------------------
This email may contain confidential and privileged
material for the sole use of the intended recipient.
If you are not the intended recipient, please contact
the sender and delete all copies.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]