http://www.perlmonks.org?node_id=176713

ycjj has asked for the wisdom of the Perl Monks concerning the following question:

How can I create a file named "default.asp?11=1"?
Thanks!
  • Comment on How can I create a file named "default.asp?11=1"?

Replies are listed 'Best First'.
Re: How can I create a file with filename as
by Pug (Monk) on Jun 24, 2002 at 13:25 UTC
    Use open like you would for any other file.
    Like this.
    open WFILE, "> default.asp?11=1" or die "Can't open default:$!"; print WFILE $data; close WFILE;
Re: How can I create a file named
by Anonymous Monk on Jun 26, 2002 at 02:05 UTC
    Depending on the file system that you are trying to save it to, you may not be able to. FAT, FAT32, and NTFS don't allow '?' in the file name. Looking at the extension I suspect that is probably the problem, you'll have to use another character.

    or, just do something like hex encode the filename, like

    my $name = "abba?@fzabb=11'a"; $name = unpack 'H*', $name; # name is now 616262613f3d31312761
    To retrieve the original name you'd pack it instead of unpack'ing.
Re: How can I create a file named
by dwatson06 (Friar) on Jun 29, 2002 at 14:02 UTC
    Is '11=1' not part of your Get? Normally pages are created as 'pagename.(asp,pl, cgi, etc)'. The question mark tells the page that there are parameters coming in. For this one, 11 is 1. So if you create an asp page as default.asp then call it passing ?11=1.
    If it's vbscript (ASP) then you can just put in tags...
    <%=response.write 11%>
    and it should print out 1.
Re: How can I create a file named "default.asp?11=1"?
by igoryonya (Monk) on Dec 06, 2009 at 12:59 UTC
    I agree with the hex conversion in file names, but I'd say only convert file name invalid characters to hex as it's done in URLEncode almost. The invalid characters in windows filenames are:
    \/:*?"<>|
    append % to the beginning of the encoded char and also encode the % char.
    my $name = "abba?@fzabb=11'a" $name =~ s/([\\\/:\*\?"<>\|])/\%unpack('H*', $1)/g; # name is now: abba%3f@fzabb=11'a%22
    Or you can use ord instead of unpack.