Guest User

Untitled

a guest
Oct 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5. use Data::Dumper;
  6.  
  7. sub parse_post_data($) {
  8. my $data_str = shift;
  9. return "" if ($data_str eq "");
  10.  
  11. my @matches = $data_str =~ /\"([^=]*)\"\s*?=\s*?>\"([^"}]*)\"/g;
  12. my %matches_hash = @matches;
  13.  
  14. if (%matches_hash) {
  15. #print Dumper(\%matches_hash) . "\n";
  16. }
  17. return %matches_hash;
  18. }
  19.  
  20. my $first_submission='{"param1"=>"val1", "param2"=>"val2", "param3"=>{"param4"=>"value4", "param5"=>"value5"}, "param6"=>"model1[field1],model1[field2]"}';
  21. my $second_submission='{"param1"=>"new_value1", "param2"=>"val2", "param3"=>{"param4"=>"new_value4", "param5"=>"value5"}, "param6"=>"model1[diff_field1],model1[field2]"}';
  22.  
  23. my %first_submission_data = parse_post_data($first_submission);
  24. my %second_submission_data = parse_post_data($second_submission);
  25.  
  26. foreach my $key (keys %first_submission_data) {
  27. if ($first_submission_data{$key} ne $second_submission_data{$key}) {
  28. print "Value of $key is different. " .
  29. "It was '$first_submission_data{$key}', now it is '$second_submission_data{$key}'\n";
  30. }
  31. }
  32.  
  33. # will output:
  34. # Value of param4 is different. It was 'value4', now it is 'new_value4'
  35. # Value of param6 is different. It was 'model1[field1],model1[field2]', now it is 'model1[diff_field1],model1[field2]'
  36. # Value of param1 is different. It was 'val1', now it is 'new_value1'
Add Comment
Please, Sign In to add comment