On 04/03/2011 16:48, Téssio Fechine wrote:
> 
>> De: Shawn H Corey<shawnhco...@gmail.com> wrote:
>
>>      my ( $file, $dir, $sufix ) = fileparse( $item, %sufixTable );
>>
>> I don't think fileparse takes a hash as the final
>> arguments.  It would be converted to an array and both
>> the keys and the values used.
>>
>> Also, from `perldoc File::basename`:
>>
>> If @suffixes are given each element is a pattern (either a
>> string or a "qr//") matched against the end of the
>> $filename.  The matching portion is removed and becomes
>> the $suffix.
>>
>> That mean all the periods in the hash will match any
>> character.
>>
>> Try:
>>
>> my @sufixTable = ( '\\.div', '\\.tex', '\\.o', '\\.c',
>> '\\.a', );
>
> Can't I use the hash in list context with something like 
> itsNotRegex(%sufixTable)? I use this hash in a program that find
> related suffix to know if a file has a source ('.o' => '.c').. and
> keeping the list of suffixes in another is variable is a kind of
> rework.

I suggest you write this

   my ($file, $dir, $suffix) = fileparse($item, map quotemeta, %sufixTable);

which will correctly escape the dots in the regex.

HTH,

Rob

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to