> >   20:     warn "blah blah\n" if (glob("~$arg") !~ m{^ (/\w+)+ /$arg $}x);
> 
>        glob    In list context, returns a (possibly empty) list of filename
>                expansions on the value of EXPR such as the standard Unix shell
>                /bin/csh would do. In scalar context, glob iterates through
>                such filename expansions, returning undef when the list is
>                exhausted.
> 
> Funny, I never noticed that behaviour before.  AFAIK it's the only perl
> function that behaves that way. Definitely a gotcha!

Actually the <> operator behaves as an iterator in scalar
context, both for globbing and for file reads.  So, it is
consistent in that sense.

But the bug (IMHO) here is that the iterator does not get
reset even though the argument to glob() changes between
invocations.  It continues to operate on the old glob()
argument.

This bug is not confined to "~" globbing.

  || % ls -1
  || apple
  || apply
  || bogus
  || % 
  || % perl -le 'sub pr {my $x= "$_*"; print "$x: ", scalar glob($x);} \
  ||     &pr for @ARGV' a b
  || a*: apple
  || b*: apply
  || % 
  || % perl -v | grep built
  || This is perl, v5.6.0 built for sun4-solaris
  || % 

peace,          || Operation Shoe Fly: Send your shoes to Afghan children:
--{kr.pA}       || http://tinyurl.com/6jnpf
-- 
We must believe in luck.  For how else can we explain the success of those
    we don't like?  -- Jean Cocteau, author and painter (1889-1963)
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to