Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Mac Space in Path

by fishmonger (Chaplain)
on May 22, 2013 at 22:18 UTC ( [id://1034823]=note: print w/replies, xml ) Need Help??


in reply to Mac Space in Path

I think we need a little more info/context.

How are you executing the script?

Are you passing the file path as a command line arg, or is it in a file that is passed as an arg or piped to the script?

Did you try dumping out $metadata_file (via Data::Dumper) prior to the open call to see if it held the value you expected?

There's no need to quote $metadata_file in the open call as demonstrated in the following example

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $filepath = 'C:\Program Files\Internet Explorer\ie9props.propdesc'; open my $fh, '<', $filepath or die "can't open '$filepath' $!"; my $file_contents = join '', <$fh>; print $file_contents;
outputs:
&#8745;&#9559;&#9488;<?xml version="1.0" encoding="utf-8"?> <!-- The properties in this file cover the following: Microsoft.IE.* --> <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="h +ttp://schemas.microsoft.com/windows/2006/propertydescription" schemaV +ersion="1.0"> <propertyDescriptionList publisher="Microsoft" product="Internet E +xplorer"> <propertyDescription name="Microsoft.IE.FeedItemLocalId" forma +tID="{E32596B0-1163-4E02-867A-12132DB4BA06}" propID="2"> <searchInfo inInvertedIndex="false" isColumn="true" maxSiz +e="256"/> <typeInfo type="String" isViewable="false"/> </propertyDescription> <propertyDescription name="Microsoft.IE.SelectionCount" format +ID="{1CE0D6BC-536C-4600-B0DD-7E0C66B350D5}" propID="2"> <searchInfo inInvertedIndex="false" isColumn="true"/> <typeInfo type="UInt32" isViewable="false"/> </propertyDescription> <propertyDescription name="Microsoft.IE.TargetUrl" formatID="{ +1CE0D6BC-536C-4600-B0DD-7E0C66B350D5}" propID="3"> <searchInfo inInvertedIndex="true" isColumn="true" maxSize +="4168"/> <typeInfo type="String" isViewable="false" isQueryable="tr +ue"/> </propertyDescription> <propertyDescription name="Microsoft.IE.TargetUrlHostName" for +matID="{1CE0D6BC-536C-4600-B0DD-7E0C66B350D5}" propID="4"> <searchInfo inInvertedIndex="true" isColumn="true" maxSize +="512"/> <typeInfo type="String" isViewable="false" isQueryable="tr +ue"/> </propertyDescription> <propertyDescription name="Microsoft.IE.TargetUrlPath" formatI +D="{1CE0D6BC-536C-4600-B0DD-7E0C66B350D5}" propID="5"> <searchInfo inInvertedIndex="true" isColumn="true" maxSize +="4168"/> <typeInfo type="String" isViewable="false" isQueryable="tr +ue"/> </propertyDescription> <propertyDescription name="Microsoft.IE.Title" formatID="{1CE0 +D6BC-536C-4600-B0DD-7E0C66B350D5}" propID="6"> <searchInfo inInvertedIndex="true" isColumn="true" maxSize +="4168"/> <typeInfo type="String" isViewable="false" isQueryable="tr +ue"/> </propertyDescription> <propertyDescription name="Microsoft.IE.VisitCount" formatID=" +{1CE0D6BC-536C-4600-B0DD-7E0C66B350D5}" propID="7"> <searchInfo inInvertedIndex="false" isColumn="true"/> <typeInfo type="UInt32" isViewable="false"/> </propertyDescription> </propertyDescriptionList> </schema>

Replies are listed 'Best First'.
Re^2: Mac Space in Path
by bettis (Initiate) on May 23, 2013 at 03:27 UTC

    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.

      Solution:

      $metadata_file =~ s/\\//;

      Apparently, Mac OSX Perl doesn't want the space band escaped. It likes a bare space in the path.

      Again, thank you for your help.

        No Perl wants the space band escaped, and I'm not sure where you got the idea that there's escaping that needs to be done.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1034823]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found