in reply to Re^3: Problems around Param (CGI->param or CGI->multi_param instead of CGI->Vars )
in thread Problems around Param

This somewhat I need, but the values are coming from the cgi form. those comment1 and cause1 are some demo values. am collecting actual strings from the form and assigning them to the hash.

Now while printing I don't need the names 'element' and 'element_drp', rather their values passed through the form.

I hope I am more clear with my question this time. some more code snippet:

sub first_process { $data_dir="/data_dir/saurav/data"; open(F1,"<$data_dir/comment_job.config") || die "Cannot open f +ile1:$!\n"; open(F2,"<$data_dir/comments_saurav.dat") || die "Cannot open +file2:$!\n"; while(<F1>){ chomp; chomp(my $f2=<F2>); push (@comment, $_ . "|" . $f2 . "\n"); } } print $q->start_form( -name => 'main', -method => 'POST', -action => 'comment_saurav.cgi', ); # Part which is printing the table print $q->start_table; &first_process; foreach (@comment) { #array starts here ($jobname, $element, $comment)= split /\|/; my $element_drop=$element . "_drp"; print $q->Tr( $q->td($jobname), $q->td( $q->textfield(-name => $element, -size => 50, -default=> $ +comment) ), $q->td( $q->popup_menu(-name => $element_drop, -values => ['N/A',' +Infra Issue','UpStream Delay','Teradata Issue', 'AbInitio Issue','Oth +ers'], -default => 'N/A', -labels => \%cause_opt ) ) ); }#array ends here #---------------End of table-------------------------------- print $q->end_table;
Below is my current action page:
my $q = new CGI; my $params = $q->Vars; my %params = $q->Vars; my @hash_array_keys=keys %params; my @hash_array_values=values %params; open FILEHANDLE, ">/tmp/hash.dat" or die "Can not open hash.dat"; $, = "\n"; for my $k (sort @hash_array_keys) { print FILEHANDLE $k, $params{$k}; } #print FILEHANDLE values %params; close FILEHANDLE;

Replies are listed 'Best First'.
Re^5: Problems around Param (CGI->param or CGI->multi_param instead of CGI->Vars )
by Anonymous Monk on Aug 26, 2015 at 10:52 UTC
    Please provide Dumper($q) from your action page
      name1 NAname10 N/Aname100 NAname100_drp N/Aname101 N/Aname101_drp N/Aname102 N/Aname102_drp N/Aname103 N/Aname103_drp N/Aname104 N/Aname104_drp N/Aname105
      where name<number> and name<number>_drp are the keys and N/A values.

        Ok, combine that with what poj posted, seems to work

        #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; use CGI qw//; my $din = { qw{ name1 N/A name10 N/A name100 N/A name100_drp N/A name101 N/A name101_drp N/A name102 N/A name102_drp N/A name103 N/A name103_drp N/A name104 N/A name104_drp N/A name105 N/A }}; dd( $din ); my $q = CGI->new( $din ); print $q->self_url, "\n"; for my $k ( sort $q->param ) { if ($k =~ /(.+)_drp$/){ print join'|', scalar $q->param( $1 ), scalar $q->param( $k )."\n" +; } } __END__ { name1 => "N/A", name10 => "N/A", name100 => "N/A", name100_drp => "N/A", name101 => "N/A", name101_drp => "N/A", name102 => "N/A", name102_drp => "N/A", name103 => "N/A", name103_drp => "N/A", name104 => "N/A", name104_drp => "N/A", name105 => "N/A", } http://localhost?name10=N%2FA;name102_drp=N%2FA;name100=N%2FA;name1=N% +2FA;name100_drp=N%2FA;name101=N%2FA;name104=N%2FA;name101_drp=N%2FA;n +ame102=N%2FA;name103=N%2FA;name105=N%2FA;name104_drp=N%2FA;name103_dr +p=N%2FA N/A|N/A N/A|N/A N/A|N/A N/A|N/A N/A|N/A
Re^5: Problems around Param (CGI->param or CGI->multi_param instead of CGI->Vars )
by poj (Abbot) on Aug 26, 2015 at 11:49 UTC
    #!perl use warnings; use strict; use CGI; open FH, '>','/tmp/hash.dat' or die "Can not open hash.dat : $!"; my $q = new CGI; for my $k ( sort $q->param ) { if ($k =~ /(.+)_drp$/){ print FH join'|', $q->param( $1 ),$q->param( $k )."\n"; } } close FH;
    poj
      Thanks poj. I am getting desired result. But the issue I am facing is the inputs are not coming in the order in which they are inserted to the hash. I know hash doesn't store values in order, but is there any way to achieve this ? Note: I don't have Tie::IxHash; installed on my system and I am not authorized to install this.

        I don't understand, are you saying that the order appearing in hash.dat is not the same as they appear on the html table ?

        Is there any pattern to the order you want them in ? For example the number before the underscore.

        poj