Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

How can I create a file named "default.asp?11=1"?

by ycjj (Initiate)
on Jun 24, 2002 at 08:21 UTC ( #176713=perlquestion: print w/replies, xml ) Need Help??

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 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
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 screamingeagle (Curate) on Jun 25, 2002 at 01:32 UTC
    try this :
    open WFILE,">default.asp\?11=1" or die "error : $!"; print WFILE "test data"; close WFILE;

    Originally posted as a Categorized Answer.

Re: How can I create a file named "default.asp?11=1"?
by igoryonya (Pilgrim) 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.
Re: How can I create a file named
by ycjj (Initiate) on Jun 26, 2002 at 02:25 UTC
    thanks Anonymous Monk ! You are right, I tried the next sample in Linux
    I get that file.
    open WFILE, "> default.asp?aa=1" or die "Can't open default:$!"; print WFILE $data; close WFILE; --------------------------------- Depending on the file system that you are trying to save it to, you may not be able to. FAT and FAT32 don't allow '?' in the file name. And probably NTFS doesn't either (I'm not sure on that) looking at the extension I suspect that is probably the problem, you'll have to use another character.

    Originally posted as a Categorized Answer.

Re: How can I create a file named
by ycjj (Initiate) on Jun 25, 2002 at 01:50 UTC
    Thanks! I tried like open WFILE,">default.asp\?11=1" or die "error : $!"; it couldn't run well. I got error message like : "Invalid argument at XX line"

    Originally posted as a Categorized Answer.

Re: How can I create a file named
by ycjj (Initiate) on Jun 25, 2002 at 00:40 UTC
    thanks! but I can't finish it. if exist "?" in file name , it display the error message "Invalid argument at XX line" while I run it.

    Originally posted as a Categorized Answer.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://176713]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2023-09-29 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?