Question on File::Find

Discussion in 'Perl Misc' started by Diana, Aug 17, 2006.

  1. Diana

    Diana Guest

    Hi,
    I am struggling to use File::Find module,
    the issue is, I can use with defining find function with &wanted, but
    not with %options, here is what I am doing
    my %findoption=( bydepth=>"1" , no_chdir => "1" );
    push (@All,find(\%fort,"$Location"));
    thx
    -D
     
    Diana, Aug 17, 2006
    #1
    1. Advertising

  2. Diana

    Paul Lalli Guest

    Diana wrote:
    > Hi,
    > I am struggling to use File::Find module,
    > the issue is, I can use with defining find function with &wanted, but
    > not with %options, here is what I am doing
    > my %findoption=( bydepth=>"1" , no_chdir => "1" );
    > push (@All,find(\%fort,"$Location"));


    1) You didn't include the wanted option in your %findoption hash. If
    you pass a hash reference as the first option to find, one of the
    key-value pairs of that hash must be 'wanted' with the value of the
    subroutine you want to call.
    2) find() does not return a list of files it finds. I have no idea
    what you think your push statement is doing
    3) Do not needlessly double-quote variables (like you did to
    $Location). See `perldoc -q quoting`

    Paul Lalli
     
    Paul Lalli, Aug 17, 2006
    #2
    1. Advertising

  3. Diana

    Paul Lalli Guest

    Paul Lalli wrote:
    > Diana wrote:


    > > I am struggling to use File::Find module,
    > > the issue is, I can use with defining find function with &wanted, but
    > > not with %options, here is what I am doing
    > > my %findoption=( bydepth=>"1" , no_chdir => "1" );
    > > push (@All,find(\%fort,"$Location"));

    >
    > 1) You didn't include the wanted option in your %findoption hash. If
    > you pass a hash reference as the first option to find, one of the
    > key-value pairs of that hash must be 'wanted' with the value of the
    > subroutine you want to call.
    > 2) find() does not return a list of files it finds. I have no idea
    > what you think your push statement is doing
    > 3) Do not needlessly double-quote variables (like you did to
    > $Location). See `perldoc -q quoting`


    4) What the heck is %fort? You declared %findoption, but are passing a
    reference to %fort? If this is your real code, please enable `use
    strict;` and `use warnings;` in your code. If this is not your real
    code, please DON'T DO THAT!

    Paul Lalli
     
    Paul Lalli, Aug 17, 2006
    #3
  4. Diana

    Diana Guest

    Paul Lalli wrote:

    > Paul Lalli wrote:
    > > Diana wrote:

    >
    > > > I am struggling to use File::Find module,
    > > > the issue is, I can use with defining find function with &wanted,
    > > > but not with %options, here is what I am doing
    > > > my %findoption=( bydepth=>"1" , no_chdir => "1" );
    > > > push (@All,find(\%fort,"$Location"));

    > >
    > > 1) You didn't include the wanted option in your %findoption hash.
    > > If you pass a hash reference as the first option to find, one of the
    > > key-value pairs of that hash must be 'wanted' with the value of the
    > > subroutine you want to call.
    > > 2) find() does not return a list of files it finds. I have no idea
    > > what you think your push statement is doing
    > > 3) Do not needlessly double-quote variables (like you did to
    > > $Location). See `perldoc -q quoting`

    >
    > 4) What the heck is %fort? You declared %findoption, but are passing
    > a reference to %fort? If this is your real code, please enable `use
    > strict;` and `use warnings;` in your code. If this is not your real
    > code, please DON'T DO THAT!
    >
    > Paul Lalli


    sorry for the mistake, I presume I modified during posting, my mistake,
    it seems I am NOW able to use options like this


    my %fort=(wanted=>sub{push (@AllDir,$File::Find::name)},bydepth=>"1" ,
    no_chdir => "1" ); ;
    find(\%fort,$Location);

    --
     
    Diana, Aug 17, 2006
    #4
  5. Diana

    Ben Morrow Guest

    Quoth "Diana" <>:
    >

    [File::Find]
    > it seems I am NOW able to use options like this
    >
    > my %fort=(wanted=>sub{push (@AllDir,$File::Find::name)},bydepth=>"1" ,
    > no_chdir => "1" ); ;
    > find(\%fort,$Location);


    There's no need to quote "1", either. Note that you can build the
    hashref inline:

    find ({
    wanted => sub {
    push (@AllDir, $File::Find::name);
    },
    bydepth => 1,
    no_chdir => 1,
    }, $Location);

    Personally I wouldn't use any of those parens, but you may find them
    helpful.

    Ben

    --
    Raise your hand if you're invulnerable.
    []
     
    Ben Morrow, Aug 17, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Hansen
    Replies:
    6
    Views:
    428
    Peter.....
    Sep 29, 2004
  2. Wybo Dekker
    Replies:
    1
    Views:
    389
    Yukihiro Matsumoto
    Nov 15, 2005
  3. nani
    Replies:
    2
    Views:
    174
    comp.llang.perl.moderated
    Mar 14, 2008
  4. vdvorkin
    Replies:
    0
    Views:
    433
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    846
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page