Front page | perl.beginners |
Postings from February 2002
RE: AARGHHH,..... chdir(yes - no)
Thread Previous
|
Thread Next
From:
Bob Showalter
Date:
February 12, 2002 05:51
Subject:
RE: AARGHHH,..... chdir(yes - no)
Message ID:
2E4528861499D41199D200A0C9B15BC031B822@taylorwhite.com
> -----Original Message-----
> From: david wright [mailto:dwright5@nyc.rr.com]
> Sent: Monday, February 11, 2002 9:02 PM
> To: beginners@perl.org
> Subject: AARGHHH,..... chdir(yes - no)
>
>
> Man, i am going crazy on this,... this is actually within a
> package but
> that doesn't matter in this case (that's why i have line #20). Anyway,
> i have #, (commented out) lines for testing purposes. I have isolated
> the problem to this area. line 27 vs. 29. chdir will not
> open any file
> passed to it in the form of a $. line 27 works fine. so i
> know that the
> code works. I tried creating line #25 to add quotes around
> the $ to see
> if that helps, it didn't. i moved chomp, took it out, etc,... i have
> line #28 in there to just check that i typed the correct line
> and that
> it is interpreted correctly. I have typed the path exactly as
> shown in
> line #27 and as a regular path (/etc/etc) and a variety of
> ways. It just
> seems like chdir($) is not supported on my machine. (OS X.1
> perl 5.6) I
> know someone here will have an answer, ... thanks
>
> sub openfolder_a { # This is
> where you are
> asked what file to open
> 20 my $self = shift @_;
> 21 my($folder_a, $folder_b, $checkit_a);
> 22 print "What folder do you want to open?
> (Need complete
> path name: /Volumes/OS\ X\ Users/etc,...)\n";
> 23 $folder_a=<>;
> 24 chomp $folder_a;
> 25 #$folder_a ="\"$folder_a\"";
> 26 #chomp $folder_a;
> 27 #chdir("/Volumes/Music\ Tunes/Toad\ Music")
> || die "cant
> open that, sorry: $!";
> 28 print $folder_a;
> 29 chdir($folder_a) || die "cant open that, sorry: $!";
> 30 # opendir(FOLDER_A,"$folder_a") || die "cant open
> $folder_a: $!";
> 31 # $checkit_a = readdir(FOLDER_A);
> etc,etc,...
OK, this line works:
chdir("/Volumes/Music\ Tunes/Toad\ Music");
Note that the backslashes above are processed by the Perl parser to escape
(i.e. treat literally), the space characters that follow. These backslashes
are *not* being passed to chdir(). It is not necessary to escape the blanks
here. You could just say:
chdir("/Volumes/Music Tunes/Toad Music");
Now, I suspect that when you are prompted to enter a path at lines 22-23,
you are entering backslashes. In this case, the backslashes *are* being
passed to chdir(), and since they aren't part of the path name, the chdir()
is failing.
Backslashes only escape characters when they appear inside string literals
in
your program. They are treated just like any other character when you read
them from a file or from the keyboard.
Try the following:
$folder_a = "/Volumes/Music Tunes/Toad Music";
chdir($folder_a) or die;
Does that work? If so, then try reading it from input. If it doesn't work,
the problem is in the input somewhere.
Thread Previous
|
Thread Next