Steve Grazzini <[EMAIL PROTECTED]> writes:

> Ah, okay.  But you'll need to make that into a real loop.
>
>      use File::Spec::Functions;
>      ...
>
>      foreach (readdir(DIR)) {
>          my $target = catfile($mnsd, $_);
>          if (-l $target) {
>            unlink $target or warn "unlink: $target: $!";
>          }
>      }
>
> The "uninitialized value" was $_.

Tim Johnson <[EMAIL PROTECTED]> writes:

> It doesn't look like you are setting the $_ variable anywhere.  Maybe if you
> put this line in after the opendir and before the first bracket:
>
> foreach(readdir(DIR))
>
> and closed the bracket

Always a good sign to get two answers the same...

Just one further point here.  I see my formulation doesn't set $_ but
not really sure why. Comparing mine to the example from perldoc:

Mine:
   opendir(DIR, $mnsd) or die "can’t opendir DIR: $!";
   { my $target = $mnsd . "/" . $_;
   unlink $target if (-l $target)} readdir(DIR);

perldoc -f readdir 
[...]
  opendir(DIR, $some_dir) ││ die "can’t opendir $some_dir: $!";
         @dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR);
         closedir DIR;

Which I was kind of trying to emulate.  What makes the
difference? 

Before seeing the helpful posts I wound up with something that works
but not as well as foreach (It also has a few changes and more things
thrown in):

   opendir(MY_DIR,"$modf") or die "Can't opendir MY_DIR: $!";
    chdir $modf;

     @lose_em = grep { /\d+$/ && -l $_ || $_ eq "pipeout_00" } readdir(MY_DIR);
  if (@lose_em) {
    unlink @lose_em or die "Can't unlink @lose_em: $!";
   }

This works but is hackish and needed the boolean truth test because it
gets some undefined values somehow maybe '' values in there some how.

foreach is better.... thanks




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to