mikael-g has asked for the wisdom of the Perl Monks concerning the following question:

please watch my code ....(it is working )
to create a file name with extensison.
#!/usr/bin/perl print "Content-type:text/html\n\n"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } $date=$FORM{'date'}; $bar=".txt"; $date=$date . " " . $bar; $dates=$FORM{'date'}; open(INF,"$date") or dienice("Ej ....datum! $date: $! \n");
As you see my code expects a variable to create a file . understandable i guess !!

in this case , when the user presses a java calender and
chosses a date , the date will be used as afile name
with a file extension , such as db or .txt .
the problem is the file is not loading with extension.
but loads without extension.
this means the file will be in binary format.
how can i tackle this oproblem ??

update (broquaint): added <code> tags

Replies are listed 'Best First'.
Re: File extension --
by arthas (Hermit) on Jun 12, 2003 at 08:53 UTC

    Hi!

    You shouldn't put a space between the filename and the extension, the correct code is:

    $bar = ".txt"; $date = $date.$bar;

    Also, if you ae opening a file for writing you should use the > charachter:

    open(INF,">$date") or dienice("Ej ....datum! $date: $! \n");

    Is dienice() a function you defined somewhere?

    As a last thing, I suggest you use CGI to parse form input.

    Michele.

Re: File extension --
by benn (Vicar) on Jun 12, 2003 at 10:38 UTC
    A slight clarification...

    but loads without extension. this means the file will be in binary format.

    The file will be in whatever format you save it out as. A filename extension is merely a 'hint' to (some) OS's as to the format of the file - you could put a .txt extension on a binary file and it'd still be a binary file, or put a .exe extension on a textfile and it'd still load as text.

    There's no magic involved in filenames other than that provided by the OS when you launch the file and it decides what application to load (which can be a PITA with MSIE for instance, which prefers the filename extension over the MIME type).

    Cheers, Ben.

Re: File extension --
by BUU (Prior) on Jun 12, 2003 at 17:44 UTC