CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Problem With a Perl Script

 



Charles
Novice

Dec 21, 2002, 11:22 AM

Post #1 of 7 (899 views)
Problem With a Perl Script Can't Post

I am having a problem with a perl script that I have. I have modified it but there is something wrong with it. Could someone take a look at it and see what is wrong with it?

I have added shipping name to this script.

I am attaching the file cause there is a lot of perl code in it.
Attachments: admin_tracking.pl (44.0 KB)


davorg
Thaumaturge / Moderator

Dec 22, 2002, 3:48 AM

Post #2 of 7 (882 views)
Re: [Charles] Problem With a Perl Script [In reply to] Can't Post

What do you mena by "there is something wrong with it"? What unexpected behaviour do you see? What errors do you get?

It's impossible to know what the problem is as this is just a library file. We never see any of the code which calls these functions. However here are a few issues that you might like to address.

* No "use strict" or "use warnings".

* Use of "chop" instead of "chomp".

* No check on return from "open" calls.

* No check on return from "flock" calls.

* "Magic numbers" in "flock" calls.

* Unnecessary quoting of variables.

Take a look at some of these issues and your problem might become clearer.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Paul
Enthusiast

Dec 22, 2002, 6:54 AM

Post #3 of 7 (881 views)
Re: [davorg] Problem With a Perl Script [In reply to] Can't Post

...in addition to that list:

* Incorrect regex syntax
* Improper use of == and eq
* Memory intensive code
* Improper use of scalar references (or maybe it was a typo?)
* Unnecessary quoting of characters inside quotes.
* A _HUGE_ amount of redundant regexes on line 1145 onwards.


(This post was edited by Paul on Dec 22, 2002, 6:55 AM)


Charles
Novice

Dec 22, 2002, 2:12 PM

Post #4 of 7 (875 views)
Re: [Paul] Problem With a Perl Script [In reply to] Can't Post

Below is the modified perl. I don't Perl that well.

This file checks the order in which i would modifiy data(I think)

I get an error message: ERROR: You did not complete all the necessary fields required to edit a online order. No updates have been made. Please try again.
I don't understand why I am getting this error messge.

I am a beginner at Perl(just barely)



#######################################################################

# Sub Admin Tracking Process Edit Order #
#######################################################################

sub admin_tracking_process_edit_order {

$form_data_tracking_ref_no = "$form_data{'ref'}";
$form_data_tracking_order_completed = "$form_data{'1'}";
$form_data_tracking_order_completed =~ s/\|//g;
$form_data_tracking_order_completed =~ s/\"/''/g;
$form_data_tracking_name = "$form_data{'17'}";
$form_data_tracking_name =~ s/\|//g;
$form_data_tracking_name =~ s/\"/''/g;
$form_data_tracking_address = "$form_data{'2'}";
$form_data_tracking_address =~ s/\|//g;
$form_data_tracking_address =~ s/\"/''/g;
$form_data_tracking_city = "$form_data{'3'}";
$form_data_tracking_city =~ s/\|//g;
$form_data_tracking_city =~ s/\"/''/g;
$form_data_tracking_state = "$form_data{'4'}";
$form_data_tracking_state =~ s/\|//g;
$form_data_tracking_state =~ s/\"/''/g;
$form_data_tracking_zip = "$form_data{'5'}";
$form_data_tracking_zip =~ s/\|//g;
$form_data_tracking_zip =~ s/\"/''/g;
$form_data_tracking_country = "$form_data{'6'}";
$form_data_tracking_country =~ s/\|//g;
$form_data_tracking_country =~ s/\"/''/g;
$form_data_tracking_ship_name = "$form_data{'7'}";
$form_data_tracking_ship_name =~ s/\|//g;
$form_data_tracking_ship_name =~ s/\"/''/g;
$form_data_tracking_ship_address = "$form_data{'8'}";
$form_data_tracking_ship_address =~ s/\|//g;
$form_data_tracking_ship_address =~ s/\"/''/g;
$form_data_tracking_ship_city = "$form_data{'9'}";
$form_data_tracking_ship_city =~ s/\|//g;
$form_data_tracking_ship_city =~ s/\"/''/g;
$form_data_tracking_ship_state = "$form_data{'10'}";
$form_data_tracking_ship_state =~ s/\|//g;
$form_data_tracking_ship_state =~ s/\"/''/g;
$form_data_tracking_ship_zip = "$form_data{'11'}";
$form_data_tracking_ship_zip =~ s/\|//g;
$form_data_tracking_ship_zip =~ s/\"/''/g;
$form_data_tracking_ship_country = "$form_data{'12'}";
$form_data_tracking_ship_country =~ s/\|//g;
$form_data_tracking_ship_country =~ s/\"/''/g;
$form_data_tracking_phone = "$form_data{'13'}";
$form_data_tracking_phone =~ s/\|//g;
$form_data_tracking_phone =~ s/\"/''/g;
$form_data_tracking_fax = "$form_data{'14'}";
$form_data_tracking_fax =~ s/\|//g;
$form_data_tracking_fax =~ s/\"/''/g;
$form_data_tracking_email = "$form_data{'15'}";
$form_data_tracking_email =~ s/\|//g;
$form_data_tracking_email =~ s/\"/''/g;
$form_data_tracking_text_description = "$form_data{'16'}";
$form_data_tracking_text_description =~ s/\|//g;
$form_data_tracking_text_description =~ s/\r/ /g;
$form_data_tracking_text_description =~ s/\t/ /g;
$form_data_tracking_text_description =~ s/\n/ /g;
$form_data_tracking_text_description =~ s/\<\#\/TEXTAREA\>/\<\/TEXTAREA\>/gi;

$form_data_tracking_status = "$form_data{'status'}";

if ($form_data_tracking_order_completed eq "" || $form_data_tracking_name eq "" || $form_data_tracking_address eq "" || $form_data_tracking_city eq "" || $form_data_tracking_state eq "" || $form_data_tracking_zip eq "" || $form_data_tracking_country eq "" || $form_data_tracking_phone eq "" || $form_data_tracking_email eq "" || $form_data_tracking_text_description eq "") {

### ERROR

$admin_stats_action_update = "Error encountered when user attempted to edit the online order entry for tracking number $form_data_tracking_ref_no without all fields completed at the Edit Online Order page.";
&admin_stats_log_admin_stats;

$fd_update_msg = "97";
$fd_pg = "admin_tracking_editdelete_display_orders";
&run_admin_script;

} else {

if ($form_data_tracking_status eq "pending") {$calc_data_path = "$data_path_tracking_pending";}
else {$calc_data_path = "$data_path_tracking_completed";}

open (FILE, "$calc_data_path$form_data_tracking_ref_no.$data_ext");
flock (FILE, 2);

@lines = <FILE>;

close(FILE);

foreach $line(@lines){

(
$tracking_db_ref_no,$tracking_db_description,$tracking_db_value) = split(/\|/,$line);

chop($tracking_db_value);

$tracking_db_description = "tracking_$tracking_db_description";

$$tracking_db_description = "$tracking_db_value";

} ######### End of foreach statement.

open (FILE, ">$calc_data_path$form_data_tracking_ref_no.$data_ext");
flock (FILE, 2);

print (FILE "1\|ref_no\|$form_data_tracking_ref_no\n");
print (FILE "2\|order_completed\|$form_data_tracking_order_completed\n");
print (FILE "3\|time\|$tracking_time\n");
print (FILE "4\|date\|$tracking_date\n");
print (FILE "5\|name\|$form_data_tracking_name\n");
print (FILE "6\|address\|$form_data_tracking_address\n");
print (FILE "7\|city\|$form_data_tracking_city\n");
print (FILE "8\|state\|$form_data_tracking_state\n");
print (FILE "9\|zip\|$form_data_tracking_zip\n");
print (FILE "10\|country\|$form_data_tracking_country\n");
print (FILE "11\|ship_name\|$form_data_tracking_ship_name\n");
print (FILE "12\|ship_address\|$form_data_tracking_ship_address\n");
print (FILE "13\|ship_city\|$form_data_tracking_ship_city\n");
print (FILE "14\|ship_state\|$form_data_tracking_ship_state\n");
print (FILE "15\|ship_zip\|$form_data_tracking_ship_zip\n");
print (FILE "16\|ship_country\|$form_data_tracking_ship_country\n");
print (FILE "17\|phone\|$form_data_tracking_phone\n");
print (FILE "18\|fax\|$form_data_tracking_fax\n");
print (FILE "19\|email\|$form_data_tracking_email\n");
print (FILE "20\|product_info\|$tracking_product_info\n");
print (FILE "21\|shipping_option\|$tracking_shipping_option\n");
print (FILE "22\|discount_number\|$tracking_discount_number\n");
print (FILE "23\|discount_price\|$tracking_discount_price\n");
print (FILE "24\|shipping_price\|$tracking_shipping_price\n");
print (FILE "25\|sales_tax_price\|$tracking_sales_tax_price\n");
print (FILE "26\|total_price\|$tracking_total_price\n");
print (FILE "27\|time_last_update\|$time_update\n");
print (FILE "28\|date_last_update\|$date_update\n");
print (FILE "29\|text_description\|$form_data_tracking_text_description\n");

close(FILE);

$admin_stats_action_update = "User successfully edited the online order entry for tracking number $form_data_tracking_ref_no at the Edit Online Order page.";
&admin_stats_log_admin_stats;

$fd_update_msg = "98";
$fd_pg = "admin_tracking_editdelete_display_orders";
&run_admin_script;

} ######### End of if statement.

}



davorg
Thaumaturge / Moderator

Dec 23, 2002, 11:34 AM

Post #5 of 7 (867 views)
Re: [Charles] Problem With a Perl Script [In reply to] Can't Post

Well the error message you describe isn't in the code that you've shown us - so it can't be caused by a problem in that code can it?

And you haven't taken any notice of the advice that you were given earlier. For example, you still don't check the return values from your "open" calls.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Charles
Novice

Dec 23, 2002, 7:43 PM

Post #6 of 7 (861 views)
Re: [davorg] Problem With a Perl Script [In reply to] Can't Post

I am not really familer with Perl at all. That is why I posted in the Beginner Area!!!!

I am just looked at the Perl Code and copied then pasted and changed a few things. I just don't understand how the numbers come into play. I am thankful of the other info too, but I am just learning Perl.


bcross
New User

Jan 27, 2003, 8:01 AM

Post #7 of 7 (790 views)
Re: [Charles] Problem With a Perl Script [In reply to] Can't Post

To the best of my knowledge, none of the "errors" mentioned above will cause the script NOT to function, however, there is more to this than just the file you have attached. This file contains sub routines but are not called. There must be another file with it that calls the subs.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives