My first response is that you should simply be doing
test($sandbox);, not test("$sandbox");. That isn't going to make a difference here, but my $directory = "@_"; makes me cringe. Doing my ($directory) = @_; would seem to be more standard.
Along the same lines, doing if ("$pwd" eq "$directory") { also does too much string interpolation. Just do if ($pwd eq $directory) {.
Now the problem you're having is that you're saying if the two variables are string-wise equivalent, complain that you're not in the same directory, otherwise say that you are. You probably wanted one of the following:
unless ($pwd eq $directory) {
or
if ($pwd ne $directory) {
That should fix your problem. | [reply] [d/l] [select] |
I think you want
"$pwd" eq "$directory" to be "$pwd" ne "$directory" | [reply] [d/l] [select] |
<whisper>
pssst.. you don't need the quotes around the variable names.
</whisper>
Cheers,
KM
| [reply] |
Jim,
I'm not sure exactly what you're trying to accomplish, but here's a whack at it: You want to check the current working directory (CWD) against the directory you have placed into $sandbox. If they're the same, you print "You are in the same directory as..." and, if they are different, you print "You are in directory...". Does that sound right?
If that's the case, I believe you have your if test backwards. If the two are equal, you want to print the line, "You are in..." and if they're different, you want to print "You are not in..."
Try this:
if ( "$pwd" eq "$directory" ) {
print "You are in $directory\n";
} else {
print "You are not in the same directory as $directory!\n";
}
It's quite possible I'm missing what you're really trying to do, but this was what I could come up with.
-Sherlock | [reply] [d/l] |
I don't know...maybe I didn't get enough sleep last night. the "ne" vs "eq" worked.
The use of my "s is habit from shell scripting. Am I really to believe that Perl will not get things confused if I don't use "s for somethings? If so, great!! If not, what should I watch out for? When should I absolutely use "s in my scripts (besides the obvious prints, etc)?
As I recall, I tried calling a function that I had written and I tried passing a value to the function without using quotes. When I tried to compile it Perl screamed at me because the value was not quoted. Once I quoted it all was well.
Sorry to have caused a burden guys. This really was, after looking at your responses, a dumb question. Thanks for the help.
----------
- Jim | [reply] |
| [reply] |
Execellent. Thanks guys!
----------
- Jim
| [reply] |
If you pass a value, you need to quote it. If you pass a scalar ($foo), then you do not need to quote it. You're passing variables around, not values.
| [reply] |