Perl Hashes

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


-6 points

I've been reading over the perl doc, but I can't quite get my head around hashes. I'm trying to find if a hash key exists, and if so, compare is't value. The thing that is confusing me is that my searches say that you find if a key exists by if (exists $files{$key}) , but that $files{$key} also gives the value? the code i'm working on is:

foreach my $item(@new_contents) { 

        next if !-f "$directory/$item";

        my $date_modified = (stat("$directory/$item"))[9];

        if (exists $files{$item}) {

            if ($files{$item} != $date_modified {

                $files{$item} = $date_modified;

                print "$item has been modified\n";
            }
        } else {
            $files{$item} = $date_modified;
            print "$item has been added\n";
        }
    }




Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.