in reply to strange regexp problem

thanks for everybody.My changed code is like this:

print $cwd; $cwd = dirname $0;

it print ".",so $1 is undef. So it is the reason

My code want to delete the last chapter of the directory(englist is not my native language,I don't know whether I express clearly).But I don't know why dirname return this.Maybe it has a bug

Replies are listed 'Best First'.
Re: strange regexp problem
by Abigail-II (Bishop) on Apr 06, 2004 at 09:41 UTC
    Your code, albeit odd, is correct. The "problem" is that $0 doesn't contain what you expect it to contain. $0 contains the path of program how you called it. If you called it as ./program (which can happen if . is in your PATH, and you called it as program), then $0 will contain ./program, making that the directory name is just a dot.

    You might to special case this, and stick in a .., use FindBin, or call your script in a different way.

    Abigail

      thanks!I call that program like what you said.I will try to use FindBin to find absolute directory of the program.