How to upload file using perl
===

i am new to stack overflow so please help me.

I am trying to upload a file using perl cgi but unable to do it. I have searched a lot and found something but it didn't work. 

Here's the code which i tried : 

<pre>

    my $upload_dir = "/home/public_html/upload/avatars";
    my $query = new CGI; 
    my $filename = $query->param("profile_avatar"); 
    my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' ); 
    $filename = $name . $extension; 
    $filename =~ tr/ /_/; 
    my $upload_filehandle = $query->upload("profile_avatar"); 
    open ( UPLOADFILE, ">$upload_dir/$filename" ) or $ses->message("Error in uploading avatar! Please try again.");
    $db->Exec("UPDATE Users SET usr_avatar=? WHERE usr_id=?", $filename, $ses->getUserId );

</pre>

Please help me and guide me.

Thanks for your help. 