in reply to Re: Best way to match items in an array
in thread Best way to match items in an array

That certainly is a unique way to do this, that I had not considered. However, what I expect that I will have many many different suffixes and it would be difficult to create a handle for each one.

$ echo '$0 & $0 &' > foo; chmod a+x foo; foo;

Replies are listed 'Best First'.
Re: Re: Re: Best way to match items in an array
by pg (Canon) on Dec 07, 2002 at 06:24 UTC
    It is not required to have unique handler for each suffix. As the suffixes are just 'values' of the hash, not 'keys', so you can share handlers among suffixes. Also, you can make those handlers accept more parameters, for complex situation.
      Actually, I was thinking that I would have to code something like:

      my %handlers = ("zip" => \&zip, "zaaap" => undef, "txt" => \&txt, "ini +" => \&misc, "foo" => \&misc, ....);
      That is, if I have 50 different file types, do I need 50 different "end" => \&handler entries?

      In addition, my suffixes may not be known until the script is run...

      $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;