in reply to Unlink doesn't work on first file

Hey everyone. Thanks for your insight.

The problem actually wasn't with unlink, but rather it was in the way the program stored the filenames in an array. The program globbed the directory, removed all *.CGI files from the array, and then displayed them in a select box.

Here's the code that displayed the select box:

foreach (@view_list){ if ($first){ print "<option value=\"$_\"> $_ \n"; } else{ print "<option value=\"$_\" selected> $_ \n"; $first=1; }
In that else statement, there was an extra space after the $_ in value, causing the first file in the directory to be stored with an extra space on the end. The program then switched all spaces to %20. The actual filename never had a space so it would never match when unlink was called.

Replies are listed 'Best First'.
Re: Re: Unlink doesn't work on first file
by runrig (Abbot) on Nov 14, 2002 at 19:47 UTC
    else{ print "<option value=\"$_\" selected> $_ \n"; $first=1; }
    In that else statement, there was an extra space after the $_ in value,

    print statements such as the one above are more readable (and easier to catch errors on) when you use the qq operator (just pick a delimiter that isn't in your string):

    print qq!<option value="$_" selected> $_ \n!;