Gossamer Forum
Home : General : Perl Programming :

Perl and Calling Unix Commands

Quote Reply
Perl and Calling Unix Commands
I am calling the following cgi program from a webpage to Upload a File and Convert the tab Separation to Comma only if the Format is 6 or 7. The following program seems to work when i run it from Unix but it fails when i call from the webpage Mad

#!/usr/local/bin/perl
$format=$query->param("P_FORMAT");
$SAVE_DIRECTORY="/u03/test/upload_files";

if ($query->param("file_01") =~ /([^\/\\]+)$/) {
$Filename = $1;
$File_Handle = $query->param("file_01");
}
$BytesRead = 0;
$Buffer = "";

if ($format =~ /6/ || $format =~ /7/) {
$rmFile= $SAVE_DIRECTORY . "/" . $Filename . ".bak";
system "rm -rf $rmFile";
$Convrsn="'s/\t/,/g'";
system "perl -pi.bak -e $Convrsn $SAVE_DIRECTORY\/$Filename";
if ($format =~ /6/) {$format = "1";}
if ($format =~ /7/) {$format = "5";}
}
printf("$format\n");
Quote Reply
Re: [chev] Perl and Calling Unix Commands In reply to
Start by using error checking in your code.

Also you are using a redundant regex here...

if ($format =~ /6/ || $format =~ /7/) {

....use:

if ($format == 6 or $format == 7) {
Quote Reply
Re: [Paul] Perl and Calling Unix Commands In reply to
Thanks for the tip. The File works like a charm when being called from Unix (i have msu access to the Directory and the Files) but when i try doing the same from Webpage it fails but the *.bak file gets created BUT not the Replcament of Tab by Comma, am not sure if this kind of partial execution can happen(!!).

Can we set the access rights for the Files being Uploaded from Webpage automatically for the owner of the File to change the access rights with chmod?