* Ian Ferguson <theferg2003@rogers.com> [2004-05-31T12:50:54]
> I guess that this is a good time to ask whether or not Perl requires me to
> quote paths containing spaces or if it is smart enough to resolve things on
> its own. For example, if I had assigned $dir =
> "/Users/my_username/Desktop/with spaces/" and then I was to rmdir( $dir )
> would this cause a problem or should I quote the variable rmdir( "$dir" )?
Step 1: consulet perldoc (perldoc -f rmdir, etc)
Step 2: Try It And See
Step 3: Ask Humans ;)

Signature
rjbs
> That seemed to fix it, but the escaped version still is not recognized.
It's not supposed to be recognized. Escapes are necessary in a shell,
because it uses white space as a delimiter, so white space that isn't
to be treated as such needs to be escaped.
> I guess that this is a good time to ask whether or not Perl requires
> me to
> quote paths containing spaces
No, it doesn't. Is this a good time to ask what led you to believe it
might, or should? ;-)
> or if it is smart enough to resolve things on its own.
There's nothing to resolve. The file name is (for example) "file name
space.txt". When you use that in a shell without escaping the spaces,
the shell splits it up into three separate arguments: ("file", "name",
"space.txt"). To prevent it from doing that - i.e. to tell the shell
that the spaces are part of a single argument, not delimiters between
multiple arguments - you escape the spaces.
In Perl, strings are most often delimited by single- and double-quotes,
not spaces. So spaces don't normally need to be escaped. But see
'perldoc perlop' - especially the "Quote and Quote-like Operators"
section. The point of having a variety of quote operators is to allow
you to choose a delimiter that doesn't appear in the input and thus
doesn't need to be escaped.
> For example, if I had assigned $dir =
> "/Users/my_username/Desktop/with spaces/" and then I was to rmdir(
> $dir )
> would this cause a problem or should I quote the variable rmdir(
> "$dir" )?
It's unnecessary, and some members of the Cranky Perl Police will
chastise you for it. (See <http://tinyurl.com/2l6wm>). It *is* slightly
inefficient - a temporary string is created, and then $dir is
interpolated into the temp string - but the CPP makes entirely too big
an issue of it.
sherm--
Ian Ferguson - 31 May 2004 22:13 GMT
"Quoth Sherm Pendley" <sherm@dot-app.org> on 5/31/04 3:01 PM:
>> That seemed to fix it, but the escaped version still is not recognized.
>
[quoted text clipped - 8 lines]
> No, it doesn't. Is this a good time to ask what led you to believe it
> might, or should? ;-)
I program AppleScript as well. In fact, this is what introduced me to Perl
and Ruby. Since Perl can handle many of the things I need faster and more
efficiently, I started digging into Perl to do things like sort arrays, etc.
In AppleScript, If I have a script and I need to call on a shell script to
run with specific parameters, I have to issue a "quoted form of ..." to make
sure that the argumetn is quoted to prevent the shell from seeing various
arguments as you noted. This is what led me to ask the question regarding
quoting. I thank you for your explanation of how Perl handles things Sherm.
:)
>> For example, if I had assigned $dir =
>> "/Users/my_username/Desktop/with spaces/" and then I was to rmdir(
[quoted text clipped - 7 lines]
> interpolated into the temp string - but the CPP makes entirely too big
> an issue of it.
** This does not apply to you Sherm **
I asked a question about quoting an argument prior to removing a directory
to learn something about how the language handles things. I don't know if
the rmdir method is recursive and/or forced in Perl.. Telling me to try and
see is a BS answer to give. Of course I could create a directory and try,
but what is the need for a community of "experts" if I can't ask a "simple"
question?
Also... Read perldoc this and that... Most people new to a language will
have no clue what you are talking about. Keep this in mind for the future.
Do you tell a person who can't drive standard ... "Hey it's a car. Just
drive it!"? Of course not. If you don't have the time to provide a proper
answer, or some code to help explain things, please don't waste your time
replying.
--
Ian Ferguson
Toronto, Canada
mailto:theferg2004@rogers.com
Joseph Alotta - 01 Jun 2004 17:36 GMT
> ** This does not apply to you Sherm **
>
[quoted text clipped - 20 lines]
> time
> replying.
I heartily agree. People should be helpful. In the old days of the
internet
this was more common. Being kind is what separates a prince from a
rouge.
Besides the documentation is obscure and lacking and not easy to know
where it is found.
Joe.
Ken Williams - 02 Jun 2004 00:23 GMT
> I program AppleScript as well. In fact, this is what introduced me to
> Perl
[quoted text clipped - 12 lines]
> regarding
> quoting.
The key difference here is that AppleScript is calling the shell to
perform its actions, whereas Perl is calling native system routines.
So no protection from the shell is necessary.
> I asked a question about quoting an argument prior to removing a
> directory
[quoted text clipped - 7 lines]
> "simple"
> question?
Well, in Perl there's more of a culture that tries things - just
because it's so much easier to write one-off simple Perl programs than
one-off Java or C or AppleScript or whatever. So I suspect Ricardo, in
his terse way, had that in mind.
However, using the "try it and see" approach can get you in trouble
too, since people should really rely on the documentation (and a real
understanding thereof) to achieve true enlightenment.
> Also... Read perldoc this and that... Most people new to a language
> will
> have no clue what you are talking about. Keep this in mind for the
> future.
> Do you tell a person who can't drive standard ... "Hey it's a car. Just
> drive it!"? Of course not.
Right, but I don't think you're going to run over any little old ladies
with a test perl script. ;-)
-Ken
Ian Ferguson - 02 Jun 2004 14:58 GMT
"Quoth Ken Williams" <ken@mathforum.org> on 6/1/04 7:23 PM:
>> In AppleScript, If I have a script and I need to call on a shell
>> script to
[quoted text clipped - 9 lines]
> perform its actions, whereas Perl is calling native system routines.
> So no protection from the shell is necessary.
Got you. I was not aware of the interaction behind the scenes apart from
what I needed to do to get proper results. I guess this makes sense in the
end. Thanks for clearing it up. ;)
> However, using the "try it and see" approach can get you in trouble
> too, since people should really rely on the documentation (and a real
> understanding thereof) to achieve true enlightenment.
I agree. I am also not one to just experiment with things that have the
potential to go wrong. For playing with methods like map and grep, no
problem, but when it comes to removal of files... I have no time to take any
chances.
>> Also... Read perldoc this and that... Most people new to a language
>> will
[quoted text clipped - 7 lines]
>
> -Ken
Lol. :)
Thanks to everybody for their help/input. Things are running great now that
I got over this little bump in the road!
--
Ian Ferguson
Toronto, Canada
mailto:theferg2004@rogers.com