Thank you so much for your responses. I implemented and tested different permutations of the suggestions listed here. I also added a line to print the path $metadata_file, so I could keep track of what the script was opening if it was able to open the file and not die:

print "\n\nPlease drop the metadata file [vendor instructions/isbn13.x +ml]:\n\n\t\t>>>"; chomp (my $metadata_file = <>); print $metadata_file; #$metadata_file =~ s/\s$//; open (FILE, "<", "$metadata_file") or die "Could not open '$metadata_f +ile': $!\n"; $metadata = join '', <FILE>;

First, I commented out the line that deletes the trailing space from the user input. I noticed that the chomp() was not working the same after OSX 10.4, so I had to implement the line (We're a small Mac typehouse and all of our machines have slightly different implementations of perl. The trailing space works on some machines and not on others, but no trailing space works on all.):

$metadata_file =~ s/\s$//;

When I comment it out, you'll see that the trailing space is still there and the space between "vendor" and "instructions" has been escaped:

Please drop the metadata file [vendor instructions/isbn13.xml]: >>>/Users/jefe/Desktop/vendor\ instructions/9781118172773.xml Could not open '/Users/jefe/Desktop/vendor\ instructions/9781118172773 +.xml ': No such file or directory

The script opens the file and reads it in perfectly if I simply delete the space in the path:

Please drop the metadata file [vendor instructions/isbn13.xml]: >>>/Users/jefe/Desktop/vendorinstructions/9781118172773.xml /Users/jefe/Desktop/vendorinstructions/9781118172773.xml

I also tried not using quotes around $metadata_file in the open command and it successfully commented out the space:

Please drop the metadata file [vendor instructions/isbn13.xml]: >>>/Users/jefe/Desktop/vendor\ instructions/9781118172773.xml Could not open '/Users/jefe/Desktop/vendor\ instructions/9781118172773 +.xml': No such file or directory

To answer your question, fishmonger, the metadata_file is simply being inserted at the top of every document the script produces, so I open it, join it, format it and insert it when I need to in the script.

This particular piece of code is my test to get it to work, then I can rewrite the other parts of the script that read and write files with space bands. Previously, I simply admonished all our comps to not use space bands in their paths. Unfortunately, the client's CMS inserts space bands at every level, so I need to figure this out. It seems so simple, but it's not working.

Again, thank you for your help.


In reply to Re^2: Mac Space in Path by bettis
in thread Mac Space in Path by Anonymous Monk

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.