title: Why can't I open a file when I use glob on a directory with a space in the name?
body: <p>I recently started working with Perl as a requirement for an education class. Part of our homework is to open a text file, read some lines, and then close the file.</p>
  
  <p>I created a folder on the desktop and put the required text files in it. I wrote the following code to open each file, read a line, and close it:</p>
  
  <pre><code>my $dir = 'C:\Users\Jay Zabaluski\Desktop\Shakespeare';
  
  opendir (DIR, $dir) or die "cannot opendir $dir";
  
  foreach my $fp (glob("$dir/*.txt")) {
  
    printf "%s\n", $fp;
  
    open my $fh, "&lt;", $fp or die "can't read open '$fp': $OS_ERROR";
    my $firstLine = &lt;$fh&gt;;
    print "$firstLine\n";
  
    close $fh or die "can't read close '$fp': $OS_ERROR";
  }
  </code></pre>
  
  <p>When I run this script on Padre, the Perl IDE, I get this error:</p>
  
  <pre class="lang-none prettyprint-override"><code>C:./UsersJay
  can't read open 'C:./UsersJay': at example.pl line 5
  Press any key to continue.....
  </code></pre>
  
  <p>I don't understand why I'm getting this error unless I'm somehow mistakenly using <code>\</code> instead of <code>/</code>, but when I right-click on a file in Windows Explorer, the path always shows up with backslashes, e.g. <code>C:\something\something</code>.</p>
  
  <p>I tried changing the file path to use forward slashes as suggested by OnlineCop in the comments, but got a similar error:</p>
  
  <pre class="lang-none prettyprint-override"><code>C:/Users/Jay
  can't read open 'C:/Users/Jay': at example.pl line 5
  Press any key to continue.....
  </code></pre>