Hello to all monks,

I am trying to do something which I am not sure is possible or not. (Can't even think if it's a good practice or not as this moment). I have created a dynamic webpage (perl v5.8) using cgi (Testing.pl) which when opened from browser pulls data from a MySQL table and show user in form of editable text fields.

User can modify any of those fields and when submit button is clicked, the changes are updated in the same table.

As of now I am checking each of the value that is displayed on webpage and can be changed by users and applying business rules on all those. But as these are 139 rows, after submit button is clicked, the page is taking 11 seconds to do all processing, update the DB and show the page with the changes.

In an attempt to reduce this time, I am trying to check if I can create an array (@compare_1) with values stored when user fetches the page and compare this array with a second array (@compare_2) which is created with the values sent over when submit button is clicked. Then I want to run all the business logic only on these changed vales.

I am trying with the code below and though the values are getting stored in arrays, but I can't save @compare_1 when the script is run for first time (when Testing.pl is fetched) and then use it for comparison when script is run for second time (when submit button is clicked on Testing.pl)

Is it possible to do what I am trying here? I have no knowledge of JavaScript and already facing hard time to maintain whatever JavaScript I have already used to display pop up messages etc.

Thank you for the time to read such lengthy post. Following is not running code but just snipet of my actual code related to this operation.

my $formStatus = $query->param('submitButton'); my $sql13 = "SELECT name, sub_name, good_high, critical_low, warning_l +ow, warning_high FROM comm_desk_thresholds WHERE user = ? "; my $sth13 = $dbh->prepare($sql13); $sth13->execute($userName); my @compare_1; while (my @row_13 = $sth13->fetchrow_array) {#Storing list of values w +hen page is loaded before submit button is clicked push @compare_1, @row_13; } if ( $formStatus eq "Submit" ) { # This code will run only when Submit + button is clicked my $sql14 = "SELECT name, sub_name, good_high, critical_low, warni +ng_low, warning_high FROM comm_desk_thresholds WHERE user = ? "; my $sth14 = $dbh->prepare($sql14); $sth14->execute($userName); print $fh "After $sql14 executed (Performance_2): ". localtime()." +\n"; my @compare_2; while (my @row_14 = $sth14->fetchrow_array) {#Storing list of valu +es after submit button is clicked push @compare_2, @row_14; } my @diff; for ( my $i=0; $i <($#compare_1+1); $i++) { if ( $compare_1[$i] ne $compare_2[$i] ) { push @diff, $compare_2[$i]; } } #Run business logic for only those elements in @diff. }
UPDATE: Changed subject line to mark Solved as NetWallah's suggestion worked for me.

In reply to [Solved]: Is it possible to save an array and use when then script is called second time? by Perl300

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.