Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2011
    Thanked 0 Times in 0 Posts

    creating a file and writing to it in CGI perl


    I am sorry guys as I am putting atleast one thread daily. But this really helping me to enhance my knowledge and passion for perl.

    This time its very silly question. But I am unable to do it.

    I have perl program where I have created a form whose action is another perl program which displays the fields user has selected or filled.

    Now I want same content to be written in one of the file. I tried creating a file handler and writing to it, however I am unable to see any text in this new file.

    Can anyone help here.

    Here is the code:

    #!/usr/bin/perl -w
    use strict;
    use warnings;
    use CGI qw(:standard);

    use CGI qw(:standard Vars);

    my ($os, $hardware, $branch, $ddk_version, $sdk_version, $tdk_version, $tests, $priority, $emailID, $requests_file);
    my (@tests, @test_config);

    print header;
    print start_html( -title => "Request Submitted",
    -bgcolor => "silver",
    -text => "11");

    print "<br> <h2>Details You Submitted!</h2> <br><br>";
    my %form = Vars();

    chop ($form{tests}); # This line is important to remove last character from the "tests" list.

    foreach my $key (keys %form){
    print "$key = $form{$key}<br><br>\n";

    print"<br><br><br><h3> Thank You!! Visit Again. </h3><br>";

    print end_html; # End of HTML web page.

    $os = $form{os};
    $hardware = $form{hardware};
    $branch = $form{branch};
    $ddk_version = $form{ddk_version};
    $sdk_version = $form{sdk_version};
    $tdk_version = $form{tdk_version};
    $tests = $form{tests};
    $priority = $form{priority};
    $emailID = $form{email};

    @test_config = ($os, $hardware, $branch, $ddk_version, $sdk_version, $tdk_version, $tests, $priority, $emailID);

    #print "@test_config\n"; # wonder...

    $requests_file = "requests_file";
    open (FILE,">$requests_file");
    print(FILE @test_config);
    print(FILE "\n");

    If I enable the print statement which is commented. It prints the data on the web page... (I wonder how this is getting printed on the web page though this statement is after print end_html)

    And last part of writing same to file request_file is not working.

    Any help would be appreciated.

    Last edited by rkaranjkar; 01-17-2011 at 01:00 PM.

  2. #2
    New Coder
    Join Date
    Jan 2011
    Thanked 0 Times in 0 Posts
    Problem resolved.
    Only I need to move the bottom code to the top :-).



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts