Use of double negation (!!)


This question already has an answer here:


It converts non-boolean types to boolean (dualvar(0,"") or 1).

It is a shortcut way of doing this, instead of trying to cast it explicitly (which may take more characters). The ! operator negates the truthness of its argument. Hence, two of them are used.

Many object types are "truthy", and others are "falsey".

  • The only false values are 0, undef, "", "0" and some overloaded objects.
  • Examples of true values are 1, "asdf", and all other values.

That is a lot of funk for a sort block!

It's essentially a two-level sort :

  1. ascii-betical
  2. deleted files first, then undeleted

So one could rewrite it as (untested):

@documents = sort {  exists $deleted_documents_names{$a} # same effect as '!!'
                     exists $deleted_documents_names{$b}
                     uc( $a ) cmp uc( $b )

Need Your Help

Show tooltip on textbox entry

c# .net textbox tooltip

I have a textbox that requires data to be entered in a certain way. I have implemented some cell validating techniques to check the data after it has been entered, but I'd like to provide the user ...

How to Define a MySql datasource bean via XML in Spring

spring javabeans datasource definition

I've looked over the documentation to define a bean. I'm just unclear on what class file to use for a Mysql database. Can anyone fill in the bean definition below?