Re: code references - how to

[email protected] (Dermot)
Newsgroups perl.beginners
Message-ID <[email protected]>
2008/6/11 Rob Dixon <[email protected]>:
> Dermot wrote:
>> Hi All,

..snip

>> So how do you create a code reference in this context, should I create
>> a code reference or use something else and what should I be test the
>> hash values for?
>> Thanx in advance.
>> Dp.
>>
>>
>>
>> #!/usr/bin/perl
>>
>> use strict;
>> use warnings;
>> use File::Find;
>>
>> my $root = shift;
>> my @records;
>>
>> find(\&wanted, $root);
>>
>> for (@records) {
>>  print $_->{name},"\t";
>>  foreach my $l (qw/a b c j/) {
>>         if ($_->{$l}) {
>>                 print "YES\t";
>>         }
>>         else {
>>                 print "No\t";
>>         }
>>  }
>>  print "\n";
>> }
>>
>>
>> sub wanted {
>>
>>  my ($num,$let) = ($_ =~ /(\d+)([\w{1}])\.txt/);
>>  print $_, "  $num Let=$let\n" if ($let !~ /i|j|k/) ;
>>
>>  my @sizes = qw(a b c d e f h i j k);
>>
>>  my %file = (
>>         name    => "f001/$num",
>>         a       => sub { return -e "$File::Find::dir/${num}a.txt"},
>>         b       => sub { return -e "$File::Find::dir/${num}b.txt"},
>>         c       => sub { return does_exist("$File::Find::dir/${num}c.txt") },
>>         j       => \&does_exist("$File::Find::dir/${num}c.txt"),
>>         );
>>  push(@records, \%file);
>>
>> }
>>
>> sub does_exist {
>>  my $file = shift;
>>  return sub { return -e $file };
>> }
>
> Please describe your design, without reference to Perl code.

Sorry Rob don't know what you by that.

Thanx (once again) John and Jenda for pointing that I wasn't
de-referencing. I did suspect that there was something wrong with the
test.
Dp.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.