in reply to [SOLVED]: Using glob in file test gives "Use of uninitialized value in -e" warning.

glob returns a list of file names. Combine it with grep:

/etc>ls pa* passwd passwd- passwd~ /etc>perl -E 'say for grep { -e $_ } glob "pa*"' passwd passwd- passwd~ /etc>

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
  • Comment on Re: Using glob in file test gives "Use of uninitialized value in -e" warning.
  • Download Code

Replies are listed 'Best First'.
Re^2: Using glob in file test gives "Use of uninitialized value in -e" warning.
by choroba (Cardinal) on Dec 07, 2017 at 13:20 UTC
    What glob returns depends on the context. In scalar context (which -e imposes) it iterates over the matching files, and returns undef when there are no more files. If nothing matches the glob, it returns undef directly.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      What glob returns depends on the context.

      I must admit I never even thought of using glob in a non-list context, so I learned something new today. Great!

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)