Hello, I know this might be something basic that I am unable to see.

On Linux with perl v5.24.0, I want to check if any files exist whose names start with a specific string. So first I tested it on command line and it seemed working fine there:

/perl -le 'print -e glob "/abc/def/ghi/test*"'
It prints 1 if any file exist with name starting with "test" under /abc/def/ghi directory and blank if such file doesn't exist.

But when I use same in program like:

if (-e glob '/abc/def/ghi/test*') # line 4 { `sudo rm /abc/def/ghi/test*`; # Remove files if they already exist }
I get warning (I think it's warning) when I run the program as: Use of uninitialized value in -e at ./script_name.pl line 4.

Which variable is uninitialized here? Is it $_?
I tried replacing single quotes with double quotes, using -f instead of -e but still get same warning.
Am I missing something here? Is it possible to remove the warning by correcting/changing something?

Thank you for your time!

EDIT: Changed subject line to solved!


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.