flynn7312 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; use JSON; use CGI; my $cgi = CGI->new; print $cgi->header('application/json;charset=UTF-8'); my %errors; my %data; if ( my $lparnmame = $cgi->param('lparname')) { if ( $lparname eq "") { $errors{'lparname'}='Lparname is required'; } } if ( my $from = $cgi->param('from')) { if ( $from eq "") { $errors{'from'}='From is required'; } } if ( my $to = $cgi->param('to')) { if ( $to eq "") { $errors{'to'}='To is required'; } } if ( my $email = $cgi->param('email')) { if ( $email eq "") { $errors{'email'}='Email is required'; } } if (%errors) { $data{'success'}=0; $data{'errors'}=\%errors; } else { $data{'success'}=1; $data{'message'}='Success'; } my $json=JSON->new; print $json->encode(\%data);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI/JSON and explicit package names.
by marto (Cardinal) on Jul 14, 2015 at 14:20 UTC | |
by Athanasius (Archbishop) on Jul 14, 2015 at 14:29 UTC | |
|
On the importance of reading and pasting error messages
by 1nickt (Canon) on Jul 14, 2015 at 14:42 UTC | |
by SuicideJunkie (Vicar) on Jul 15, 2015 at 14:43 UTC | |
by flynn7312 (Acolyte) on Jul 17, 2015 at 08:23 UTC |