in reply to From chat to here :) chdir() and test -f issues.

In debugging tons of code, i have found one other thing that often causes issues is non-printing charachters. While from the code i would not imagine that is the issue, when you can see a file that a script cannot,it is usually either :
A: Permissions (see above post)
B: Wrong file name (test using "| cat -v" to find non-printing)

Just thnking, the code s/.*: (.*)\n+/$1/; does not remove \r if it is there ... could it be there ?
may the foo be with you

Replies are listed 'Best First'.
Re: Re: From chat to here :) chdir() and test -f issues.
by snafu (Chaplain) on Jul 05, 2001 at 00:30 UTC
    Ok. Im gonna test to see if there are any '/r's in the string but I can't seem to think of a good way to see non-printing characters in a string (cat only works while streaming the contents of files afaik.) Anyway, if anyone has any good ideas on this one Im open to them.

    On the other hand, the only thing that still wags my head on this is the fact that if I break the chdir()'s up into seperate changes (ie :

    chdir("$HOME/$gamedir/maps"); # does not work in the script
    vs

    chdir("$HOME/$gamedir"); chdir("maps"); # works fine.
    )

    This still makes me wonder...why would invisible characters cause problems for the first example but not for the second. This is the question I was originally getting at, although I don't think I stated it very well. :) Come on! It was 430AM =).

    Anyway, Im curious to see if anyone can answer that one. Thanks again guys.

    ----------
    - Jim

Re: Re: From chat to here :) chdir() and test -f issues.
by snafu (Chaplain) on Jul 05, 2001 at 00:56 UTC
    Ah, this was excellent for helping working on my debugging abilities. Here is what I did.

    I ran a regex on the $gamedir variable to match the first non-character character and replace it with a "*". Sure enough there was an invisible character at the end of the string but I do not think it was a '\r' as I had already used s regex to strip '\r' (admittedly I may have done that part incorrectly though)...code to follow. Anway, I decided to simply chop() the last character (hoping there was only one) and that worked. Here is the code and output:

    Finding the problem

    my $funcName = (caller(0))[3]; my $player_name = shift; my $mapname = shift; (my $gamedir = &send(1,"sv_gamedir")) =~ s/.*: (.*)[\r\n]+/$1/; (my $testgamedir = $gamedir) =~ s/\W/*/; print STDERR "\$HOME = $HOME\n\$testgamedir = $testgamedir\n\$mapn +ame = $mapname\n";

    output:

    $HOME = /services/qw $testgamedir = fortress* $mapname = 2fort5 Map doesn't exist! -> /services/qw/fortress/maps/2fort5.bsp

    As we can see by the

    fortress*
    that there was at least one white character there.

    After chop()

    my $funcName = (caller(0))[3]; my $player_name = shift; my $mapname = shift; (my $gamedir = &send(1,"sv_gamedir")) =~ s/.*: (.*)[\r\n]+/$1/; chop($gamedir); (my $testgamedir = $gamedir) =~ s/\W/*/; print STDERR "\$HOME = $HOME\n\$testgamedir = $testgamedir\n\$mapn +ame = $mapname\n";
    output:

    $HOME = /services/qw $testgamedir = fortress $mapname = 2fort5 Map exists! -> /services/qw/fortress/maps/2fort5.bsp

    ----------
    - Jim