RE: complex data file parsing
Thanks for the information. That was much more than I expected. You right about the T line. That was a typo. The T is in the firth position of the last line of each order block. As far as your follow up question on the B lines, only line with a B in the beginning in set?, I'm not sure if I understand. If you mean that there will only be 1 line per order (set of lines A-T) with a B in the first position, you are correct. Also, as far as your assumption, The way I do it assumes that the first and only first line of each set beginns with an A (and falsly buts that A at the end of the privious record, but doesnt matter for the aim her, does it?), I'm not sure what you mean by this either. However, it sounds like you have it correct. Lines that indicate the beginning of an order block, will only ever start with an A in the first position. Finally, the final assumption, that The push assumes that there are always exactly 5 records between B and email and that this is the only line with a B in record (and comes before the lines with ADV_. I think that this is correct. An example line is B,W29116,test,test,[EMAIL PROTECTED], The positions are 0,1,2,3,4, so that equals 5, and it will ALWAYS be five. Finally, the B line will ALWAYS come before the ADV_ lines. This appears to be correct judging that the output of the script is e-mail addresses. I tested the script, and I was able to output e-mail addresses. However, using the data that I posted, it does not quite output exactly what I need. Based on this sample of order.csv and the script that you sent me (I added the line print @email to view the output): for (my $i=0; $i=$#fields; $i++){ if ($fields[$i] eq B) {$b_index=$i; next;} elsif ($fields[$i] =~ /^ADV_.*/) {push @email, $fields[$b_index+4]; last;} print @email; ): A,W29073,Thu Apr 05 15:25:08 2001 B,W29073,Scott,S,[EMAIL PROTECTED],249 Tah Ave,,Sth San Francisco,CA,~US,5- P,W29073, X,W29073,Company Name,A,Department Name,San Francisco 00),Purchase Order Number,254 S,W29073,UPS Next Day Air,Scott S,2 Tah Ave,,Sth San Francisco,CA,~US,5- I,W29073,AVHQ_101090lfbl,6.000,$28.50,$171.001.00,,2,0 I,W29073,AVHQ_101090xlfbl,4.000,$28.50,$114.001.00,,3,0 T,W29073,$285.00$53.09,$338.09,,10.00, A,W29101,Wed Apr 11 07:43:33 2001 B,W29101,harold,m,[EMAIL PROTECTED],10 wind ridge parkway,,Atlanta,GA,~US,5 P,W29101, X,W29101,Company Name,,Department Name,,Purchase Order Number,10252 S,W29101,UPS Regular Ground,harold m,10 wind ridge parkway,,Atlanta,GA,~US,5 I,W29101,ADV_Carb-Natxxl,1.000,$16.50,$16.501.50,,4 T,W29101,$17.50,,7.000,$1.23,$9.28,$28.01,,1.50, A,W29116,Thu Apr 12 11:42:21 2001 B,W29116,test,test,[EMAIL PROTECTED],test,,test,GA,~US,1 P,W29116,Credit,Offline,Visa,,04/04 X,W29116,Company Name,,Department Name,,Purchase Order Number, S,W29116,UPS Regular Ground,test test,test,,test,GA,~US,1 I,W29116,ADV_1601,1.000,$14.00,$14.001.50,,3 T,W29116,$14.00,,7.000,$0.98,$9.94,$24.92,,1.50, I would expect to see: [EMAIL PROTECTED]@test.com However, I see: [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@masnc.n [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@masnc [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@mas [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@m [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED] @[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED] [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@masnc.ne [EMAIL PROTECTED]@masnc.net What is going wrong? Am I trying to view the output incorrectly? Thanks for any additional direction. Andrew -Original Message- From: wolf blaum [mailto:[EMAIL PROTECTED] Sent: Thursday, January 22, 2004 3:28 PM To: Hughes, Andrew; Perl Beginners Mailing List Subject: Re: complex data file parsing hi, I know that each block always starts with and A in the first position of the first line and ends with a T in the last position of the last line. isnt it a T in the first position of the last row of the set? I know that the second line starts with a B, and the data in the 5th space on this line is the e-mail address, which is what I ultimately want. However,... only line with a B in the bigining in set? I am trying to get a list of email addresses for people who have ordered products that begin with ADV. These can appear in multiple I lines. Therefore you can never predict how many lines make up 1 order block. What about: #! /usr/bin/perl use strict; use warnings; my @email; open (FH, complex.txt) or die $!; local $/ = \nA,; # make \nA, the record seperator while(FH){ # read the next record my @fields = split ,|\n, $_; # split at , or \n my $b_index;# 0 for every new record for (my $i=0; $i=$#fields; $i++){ if ($fields[$i] eq B) {$b_index=$i; next;} elsif ($fields[$i] =~ /^ADV_.*/) {push @email, $fields[$b_index+4]; last;} } } works
RE: complex data file parsing
Thanks so much. I've been tinkering around with this all afternoon. I think that it is there. I'm going to mess around with it more over the weekend. I'll let you know how it goes. Thanks so much, Wolf! Andrew -Original Message- From: wolf blaum [mailto:[EMAIL PROTECTED] Sent: Friday, January 23, 2004 3:30 PM To: Hughes, Andrew; Perl Beginners Mailing List Subject: Re: complex data file parsing Hi, As far as your follow up question on the B lines, only line with a B in the beginning in set?, I'm not sure if I understand. If you mean that there will only be 1 line per order (set of lines A-T) with a B in the first position, you are correct. yes, thats what I meant. Sorry about my lazyness. Adittionally I get to correct all my embarassing typos... Also, as far as your assumption, The way I do it assumes that the first and only first line of each set beginns with an A (and falsly buts that A at the end of the privious record, but doesnt matter for the aim her, does it?), I'm not sure what you mean by this either. However, it sounds like you have it correct. Lines that indicate the beginning of an order block, will only ever start with an A in the first position. Well, what that $/=\nA does is, it changes the amount of data the while (FH) reads into $_ Usually that is a line - in your case, the change of $/ gets it to read a whole order into $_: from A, to T,. end of line here. Thats what you need. However, I cheat: it acctually reads from A,... to T, \nA, into $_, so even the (A,) belongs to the next record, it ends up in the privious one. Thats kind of wrong, given your record structure but does not matter for the purpous you described. See the print $_ in the code below. Finally, the final assumption, that The push assumes that there are always exactly 5 records between B and email and that this is the only line with a B in record (and comes before the lines with ADV_. I think that this is correct. well good:) I tested the script, and I was able to output e-mail addresses. However, using the data that I posted, it does not quite output exactly what I need. Based on this sample of order.csv and the script that you sent me (I added the line print @email to view the output): for (my $i=0; $i=$#fields; $i++){ if ($fields[$i] eq B) {$b_index=$i; next;} elsif ($fields[$i] =~ /^ADV_.*/) {push @email, $fields[$b_index+4]; last;} 1 print @email; ): What is going wrong? Am I trying to view the output incorrectly? The line 1 is still in the for loop. So you print all emails seen so far for every field the split gave you. Code with more debug in the right place: --- #! /usr/bin/perl use strict; use warnings; my @email; open (FH, complex.txt) or die $!; local $/ = \nA,; # make \nA, the record seperator while(FH){ # read the next record print This record holdes:\n$_ \n; my @fields = split ,|\n, $_; # split at , or \n my $b_index; # 0 for every new record for (my $i=0; $i=$#fields; $i++){ if ($fields[$i] eq B) {$b_index=$i; next;} elsif ($fields[$i] =~ /^ADV_.*/) {push @email, $fields[$b_index+4]; last;} } # end for print End of record.\n\n } # end while print @email; #last line in script - On my box that prints the 2 emails you wanted. I hope I didnt get something totally screwed. Let me know if that does it or not. Thx, Wolf -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
complex data file parsing
I am trying to make sense of a comma delimited log file in which multiple lines make up 1 record. Here is an example: A,W29073,Thu Apr 05 15:25:08 2001 B,W29073,Scott,S,[EMAIL PROTECTED],249 Tah Ave,,Sth San Francisco,CA,~US,5- P,W29073, X,W29073,Company Name,A,Department Name,San Francisco 00),Purchase Order Number,254 S,W29073,UPS Next Day Air,Scott S,2 Tah Ave,,Sth San Francisco,CA,~US,5- I,W29073,AVHQ_101090lfbl,6.000,$28.50,$171.001.00,,2,0 I,W29073,AVHQ_101090xlfbl,4.000,$28.50,$114.001.00,,3,0 T,W29073,$285.00$53.09,$338.09,,10.00, A,W29101,Wed Apr 11 07:43:33 2001 B,W29101,harold,m,[EMAIL PROTECTED],10 wind ridge parkway,,Atlanta,GA,~US,5 P,W29101, X,W29101,Company Name,,Department Name,,Purchase Order Number,10252 S,W29101,UPS Regular Ground,harold m,10 wind ridge parkway,,Atlanta,GA,~US,5 I,W29101,ADV_Carb-Natxxl,1.000,$16.50,$16.501.50,,4 T,W29101,$17.50,,7.000,$1.23,$9.28,$28.01,,1.50, A,W29116,Thu Apr 12 11:42:21 2001 B,W29116,test,test,[EMAIL PROTECTED],test,,test,GA,~US,1 P,W29116,Credit,Offline,Visa,,04/04 X,W29116,Company Name,,Department Name,,Purchase Order Number, S,W29116,UPS Regular Ground,test test,test,,test,GA,~US,1 I,W29116,ADV_1601,1.000,$14.00,$14.001.50,,3 T,W29116,$14.00,,7.000,$0.98,$9.94,$24.92,,1.50, Here's what I know: I am trying to get a list of email addresses for people who have ordered products that begin with ADV I know that the second field is the order number that ties all of the lines for one order together. I know that each block always starts with and A in the first position of the first line and ends with a T in the last position of the last line. I know that the second line starts with a B, and the data in the 5th space on this line is the e-mail address, which is what I ultimately want. However,... I am trying to get a list of email addresses for people who have ordered products that begin with ADV. These can appear in multiple I lines. Therefore you can never predict how many lines make up 1 order block. I can handle all of the pieces except for the parsing of files that have each complete record on its own line. The problems is that the records are split across multiple line and the # of lines can increase based on how many line items (I rows) there are on the order Can anyone offer me some direction? Should I try to leave these lines separate? Should I try to start each line with A and then put each of the subsequent lines end to end until I hit another A? Thanks, Andrew Andrew Hughes Insider's Advantage Webmaster Phone: (404) 575-6389 Fax: (404) 575-6374 Online ordering is now available. Visit http://insidersadvantage.com for details. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: perl / MySql application overview question
Thanks for the detailed answer. I have dealt with JOIN clauses briefly in the past, but not in this context. I will have to revisit on my own. As far as grabbing the unique id, I am definitely going to use the DBI module for contacting MySQL. When I am looking at your piece of code, I had a few questions though. Let's say that I use this code to connect and insert data into table called pageInfo in a database called Project. pageInfo Table: id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY pageName VARCHAR(200) pageTitle TEXT pageContent TEXT my $dbh = WebDB::connecteclub (); $sth = $dbh-prepare(insert into pageInfo(id, pageName, pageTitle, pageContent) values(?,?,?,?)) or die; $sth-execute(undef, $cgi-param('pageName'), $cgi-param('pageTitle'), $cgi-param('pageContent')) or die; How would the suggested code below then grab that generated id from the record created by the process above? Also, let's say that there are two people who submit the form at the same moment. Will this code be able to ensure that the correct id is selected to be stored into the cookie? my $newid = $sth-{'Database'}-{'mysql_insertid'}; unless ($newid) { # handle error here } Thanks, Andrew -Original Message- From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED] Sent: Sunday, August 10, 2003 7:46 PM To: Hughes, Andrew Cc: '[EMAIL PROTECTED]' Subject: Re: perl / MySql application overview question Hughes, Andrew wrote: I have a multi-table MySQL database that holds different pieces of information that will all be displayed on a web page template. The general principle is that non web people will be able to populate web pages through an admin panel. The data in all of the MqSQL tables will be entered by the user through forms on the web and bought into a page template using the unique id for each page. The user will login with a username and password. This information will then be stored in a session using Apachee::Session and a cookie. The first form that the user submits will contain general information about the page itself. All of this information will be stored in one row in the table and a unique id will be generated in MySQL for that webpage. Subsequent forms will request other information for different areas of that one page. I plan on relating all of the information in the rest of the tables to build that one page back to the specific page based on that page's unique id that was generated. I was planning on doing that by somehow getting that generated unique id into the cookie immediately after it is generated in the MySQL database. Then, every time information is added to another table that relates back to the webpage, I will enter that id from the cookie in the MySQL insert statement. Here are my questions: Is this a proper approach? If not, what is a better / correct approach? If it is, how would I go about it? I am not asking for someone to do it for me. I was just wondering if there were some terms / buzzwords / tutorials that I should follow up on. This sounds like a common approach and certainly a viable one. In general you are talking about precisely what an RDBMS is for and the tables you refer to are in general called lookup tables. In other words you store the main record in a master table then you lookup into another table based on a unique id from the master. One item you will want to look into is a join clause. A join clause allows you to combine fields from multiple tables in a single select statement so that you don't have to do multiple independent selects to retrieve the same effect, but that is OT for this forum, but have a look at the MySQL documentation for JOIN. As for retrieving the ID generated by an auto increment in MySQL if you are using DBI (which I hope you are) then you can using something like the following after an insert: my $newid = $sth-{'Database'}-{'mysql_insertid'}; unless ($newid) { # handle error here } Though this may not be portable to other engines, but it saves you the pain of having to do multipe statements in an atomic manner (locking), etc. You will run into other design problems as you go along, and a lot of questions, that really can't be avoided without experience, but overall your design is fairly sound for some applications and obviously you have given it some or a lot of thought before starting, which is usually the critical and first mistake made (aka to dive right in). Good luck, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
perl / MySql application overview question
I have a multi-table MySQL database that holds different pieces of information that will all be displayed on a web page template. The general principle is that non web people will be able to populate web pages through an admin panel. The data in all of the MqSQL tables will be entered by the user through forms on the web and bought into a page template using the unique id for each page. The user will login with a username and password. This information will then be stored in a session using Apachee::Session and a cookie. The first form that the user submits will contain general information about the page itself. All of this information will be stored in one row in the table and a unique id will be generated in MySQL for that webpage. Subsequent forms will request other information for different areas of that one page. I plan on relating all of the information in the rest of the tables to build that one page back to the specific page based on that page's unique id that was generated. I was planning on doing that by somehow getting that generated unique id into the cookie immediately after it is generated in the MySQL database. Then, every time information is added to another table that relates back to the webpage, I will enter that id from the cookie in the MySQL insert statement. Here are my questions: Is this a proper approach? If not, what is a better / correct approach? If it is, how would I go about it? I am not asking for someone to do it for me. I was just wondering if there were some terms / buzzwords / tutorials that I should follow up on. Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problems getting a simple form to work.
I think you meant, Thanks, Rob. Andrew -Original Message- From: Mike Butler [mailto:[EMAIL PROTECTED] Sent: Friday, April 04, 2003 4:45 PM To: Rob Benton Cc: Hughes, Andrew; [EMAIL PROTECTED] Subject: RE: Problems getting a simple form to work. Thanks, Andrew. That did it. It's working now. :) :) :) Thanks everyone for all your help. - Mike -Original Message- From: Rob Benton [mailto:[EMAIL PROTECTED] Sent: Friday, April 04, 2003 4:38 PM To: Mike Butler Cc: Hughes, Andrew; [EMAIL PROTECTED] Subject: RE: Problems getting a simple form to work. Give this a shot and see if it errors: use CGI; my $query = new CGI; my %params = $query-Vars; my $username = $params{'username'}; On Fri, 2003-04-04 at 15:29, Mike Butler wrote: Thanks, Andrew. I added CGI::Carp qw(fatalsToBrowser); to the script. That's a big help. The error message that I get now is: Software error: Undefined subroutine main::param called at simpleform.cgi line 6. Line 6 is my $username = param('username'); Any idea why param is undefined? Thanks, - Mike -Original Message- From: Hughes, Andrew [mailto:[EMAIL PROTECTED] Sent: Friday, April 04, 2003 3:09 PM To: [EMAIL PROTECTED] Subject: RE: Problems getting a simple form to work. I would also add use CGI::Carp qw(fatalsToBrowser); along with use CGI; use strict; This way your errors will get displayed in your browser. Also, check with your hosting company to make sure that your path to perl is correct (ex. is it #!/usr/local/bin/perl -wT vs. #!/usr/bin/perl -wT) Andrew -Original Message- From: Li Ngok Lam [mailto:[EMAIL PROTECTED] Sent: Friday, April 04, 2003 2:37 PM To: Mike Butler; [EMAIL PROTECTED] Subject: Re: Problems getting a simple form to work. [..] #!/usr/local/bin/perl -wT use CGI; use strict; $username = param('username'); should be : my $username = param('username'); because you've using strict; print Content-type: text/plain\n\n; For what I know, I would write as Content-type: text/html\n\n; print You entered: $username\n; The permissions look like this: Permissions for cgi-bin: rwxr-xr-x Permissions for simpleform.cgi rwxr-xr-x Permissions for simpleform.htm: rwxr-xr-x I have changed form method=post action=../cgi-bin/simpleform.pl to form method=post action=http://www.mikyo.com/cgi-bin/simpleform.cgi;. 2 suggestion here : 1. use CGI::Carp 'fatalsToBrowser'; # the die message will goto your browser. 2. Try simpler script, so you will know if your form is going to a right place : #!/usr/bin/perl print Content-type: text/html\n\n; print Hello world; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: form user interface issue
Okay, I think that I'm getting closer. I've condensed my code so that it is a little clearer. form method=post action=2003springcontest.pl onSubmit=return submitIt(this) input type=text name=check_email maxlength=60 input type=submit name=choice value=Check /form perl decision making code: if ($choice eq ) { checkemailform(); # displays form } elsif ($choice eq check) { checkemail(); # inserts the data } Are you suggesting this for the form?: form method=post action=2003springcontest.pl onSubmit=return submitIt(this) input type=text name=check_email maxlength=60 input type=hidden name=choice value=Check input type=submit value=Check /form I took the name value out of the submit input tag and included a hidden field that includes a the name choice and the value check, which is what I logic code is looking for. Do you think this is the correct path? Thanks in advance. I appreciate your input. Thanks, Andrew -Original Message- From: Octavian Rasnita [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 01, 2003 11:01 AM To: Hughes, Andrew; [EMAIL PROTECTED] Subject: Re: form user interface issue That form probably has a submit button that has a parameter name= The script might be checking for that param('...'). If the form is submitted by pressing the button, that parameter from the submit button is sent to the server while if the form is submitted by pressing enter from another form field, it is not, so the script will fail when checking for it. The solution is to put another hidden field like input type=hidden name=... value=... and remove the name=... parameter from the submit tag. Teddy, Teddy's Center: http://teddy.fcc.ro/ Email: [EMAIL PROTECTED] - Original Message - From: Hughes, Andrew [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, April 01, 2003 6:31 PM Subject: form user interface issue I have a form that I am using to add data to a mysql database table. I am using a .pl scrtipt to generate the html. I am using cgi.pm and param() to insert the form data. And, I am using to the printHTML; function to display my forms within the .pl script. The problem is that when the user completes the form and hits the enter key (as opposed to the mouse to submit the form), the form goes blank and nothing happens. However, if a user uses the mouse, everything works fine. Please let me know what you think the problem is. Any assistance would be greatly appreciated. Thanks, Andrew Here's the code: ..snip1.. my $choice = lc(param(choice)); my $check_email = WebDB::trim_and_collapse_whitespace (lc(param(check_email))); ..snip1.. ..snip2.. if ($choice eq ) { checkemailform(); # displays form } elsif ($choice eq check) { checkemail(); # inserts the data } ..snip2.. ..snip3.. sub checkemailform { print Content-type:text/html\n\n; print checkemailform; html head titleInsider's Advantage/title meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 style type=text/css !-- .main {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-weight: normal; color: #00;} .mainsmall {font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #00;} .head {font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; color: #00;} -- /style SCRIPT LANGUAGE=JAVASCRIPT TYPE=TEXT/JAVASCRIPT function submitIt(form) { if (!validEmail(form.check_email.value)) { alert(Invalid AOLTW Business E-Mail Address.) form.check_email.focus() form.check_email.select return false } } function validEmail(check_email) { invalidChars = /:,; if (check_email ==) { return false } for (i=0; iinvalidChars.length; i++) { badChar = invalidChars.charAt(i) if (check_email.indexOf(badChar,0) -1) { return false } } atPos = check_email.indexOf(@,1) if (atPos == -1) { return false } if (check_email.indexOf(@,atPos+1) -1) { return false } periodPos = check_email.indexOf(.,atPos) if (periodPos == -1) { return false } if (periodPos+3 check_email.length) { return false } return true } //end validEmail /SCRIPT /head body bgcolor=#FF text=#00 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 form method=post action=2003springcontest.pl onSubmit=return submitIt(this) table width=500 border=0 align=center cellpadding=2 cellspacing=0 tr td colspan=2 class=main align=centerimg src=http://insidersadvantage.com/images/promotions/2003brochure/signup_head .jpg border=0/td /tr tr td colspan=2 class=mainPlease enter your work email address below so that we may determine whether or not you are an E-Club member. /td /tr tr td colspan=2 class=main* i bIndicates a required field./b/i/td /tr tr td width=175 align=right class=mainWork Email Address:/td td width=325 class=main input type=text name=check_email maxlength=60 */td /tr tr td colspan=2 align=centerinput type=submit name=choice value=Check /td /tr tr td colspan=2 class
form user interface issue
I have a form that I am using to add data to a mysql database table. I am using a .pl scrtipt to generate the html. I am using cgi.pm and param() to insert the form data. And, I am using to the printHTML; function to display my forms within the .pl script. The problem is that when the user completes the form and hits the enter key (as opposed to the mouse to submit the form), the form goes blank and nothing happens. However, if a user uses the mouse, everything works fine. Please let me know what you think the problem is. Any assistance would be greatly appreciated. Thanks, Andrew Here's the code: ..snip1.. my $choice = lc(param(choice)); my $check_email = WebDB::trim_and_collapse_whitespace (lc(param(check_email))); ..snip1.. ..snip2.. if ($choice eq ) { checkemailform(); # displays form } elsif ($choice eq check) { checkemail(); # inserts the data } ..snip2.. ..snip3.. sub checkemailform { print Content-type:text/html\n\n; print checkemailform; html head titleInsider's Advantage/title meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 style type=text/css !-- .main {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-weight: normal; color: #00;} .mainsmall {font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #00;} .head {font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; color: #00;} -- /style SCRIPT LANGUAGE=JAVASCRIPT TYPE=TEXT/JAVASCRIPT function submitIt(form) { if (!validEmail(form.check_email.value)) { alert(Invalid AOLTW Business E-Mail Address.) form.check_email.focus() form.check_email.select return false } } function validEmail(check_email) { invalidChars = /:,; if (check_email ==) { return false } for (i=0; iinvalidChars.length; i++) { badChar = invalidChars.charAt(i) if (check_email.indexOf(badChar,0) -1) { return false } } atPos = check_email.indexOf(@,1) if (atPos == -1) { return false } if (check_email.indexOf(@,atPos+1) -1) { return false } periodPos = check_email.indexOf(.,atPos) if (periodPos == -1) { return false } if (periodPos+3 check_email.length) { return false } return true } //end validEmail /SCRIPT /head body bgcolor=#FF text=#00 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 form method=post action=2003springcontest.pl onSubmit=return submitIt(this) table width=500 border=0 align=center cellpadding=2 cellspacing=0 tr td colspan=2 class=main align=centerimg src=http://insidersadvantage.com/images/promotions/2003brochure/signup_head .jpg border=0/td /tr tr td colspan=2 class=mainPlease enter your work email address below so that we may determine whether or not you are an E-Club member. /td /tr tr td colspan=2 class=main* i bIndicates a required field./b/i/td /tr tr td width=175 align=right class=mainWork Email Address:/td td width=325 class=main input type=text name=check_email maxlength=60 */td /tr tr td colspan=2 align=centerinput type=submit name=choice value=Check /td /tr tr td colspan=2 class=mainnbsp;/td /tr /table /form /body /html checkemailform } ..snip3.. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: CPAN/Matt's???
I just got it as well. If you click on the MSA logo, it takes you to this page http://www.cpan.org/index2.html What's going on? Andrew -Original Message- From: Scot Robnett [mailto:[EMAIL PROTECTED] Sent: Monday, March 31, 2003 7:44 PM To: [EMAIL PROTECTED] Subject: CPAN/Matt's??? Is anyone else seeing Matt's script archive when they try to go to CPAN? Scot R. inSite -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: downloading data as text file
I wrote this script to back up a table in my mySQL database. It also names the file with the exact time from the server that the backup occurred. It might not be the best approach, but it worked for me as the only user. Just adjust the column names to fit your needs. When I posted a similar question, I also received information about a mysql command named mysqldump http://www.mysql.com/doc/en/mysqldump.html. My hosting company would not let me use this command, so I wrote the following script: sub backup { my $dbh = shift; my ($sth, $stmt, $count, $row); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my $time = localtime(time); my $currentyear = $year + 1900; my $currentmonth = $mon + 1; my $currentday = $mday; my $currenthour = $hour; my $currentmin = $min; my $currentsec = $sec; my $filename = $currentyear$currentmonth$currentday$currenthour$currentmin$currentsec.txt ; print Content-type:text/html\n\n; printENTRYFORM; html head titleSurvey Backup!/title style type=text/css !-- .main { font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #00;} .mainsmall { font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #00;} .head { font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; color: #FF;} -- /style /head body bgcolor=#FF leftmargin=0 topmargin=10 marginwidth=0 marginheight=10 ENTRYFORM print $timebr; print $sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdstbr; print $filename; open(OUTFILE,$filename) or dieerror(Can't open $filename: $!); $stmt = qq { select * from Survey }; $sth = $dbh-prepare ($stmt); $sth-execute (); while (my $row = $sth-fetchrow_hashref()) { print OUTFILE $row-{participantId}|$row-{participantDate}|$row-{participantFirstName}| $row-{participantLastName}|$row-{participantPhone}|$row-{participantPhone Extension}|$row-{participantState}|$row-{participantDivision}|$row-{parti cipantEmail}\n; } $sth-finish(); close(OUTFILE); printENTRYFORM2 /body /html ENTRYFORM2 } Hope this helps! Andrew -Original Message- From: T. Murlidharan Nair [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 11:49 AM To: [EMAIL PROTECTED] Subject: downloading data as text file Hi!! I need to provide the users that access my database a way to download data as a text file. The data is stored in a mysql database, has anyone done this, if so I would really appreciate their help. Thanks and Cheers always!! Murli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problem with regular expressions!!!
This is a newbie observation, but aren't you not supposed to name one of your own variables with a number as the first value after a $, @, or % as in the case of $2? Could this be part of the problem? Andrew -Original Message- From: Marcelo Taube [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 18, 2003 4:29 PM To: [EMAIL PROTECTED] Subject: Problem with regular expressions!!! As u probably have guessed some part of my code is not working properly and i don't understand why!! This is the code. # $file_completename =~ /(.*?)\.(.*)/; if ($2 eq $extension]) { #DO SOMETHING!!! } # As u see, i'm trying to separate the complete name of a file in two parts, the filename ($1) and the extension($2)... then i check to see whatever a extension is of some kind and if it is, i do something. However this doesn't work. Because in $2, perl adds a . before the extension. 4 example: if file_completename equal to myfile.jpeg, then $2 equials to .jpeg, but it should be jpeg. What am i doing wrong? Thank u very much, Marcelo Taube _ The new MSN 8: advanced junk mail protection and 2 months FREE* http://join.msn.com/?page=features/junkmail -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
delete pattern from text file
I am trying to use the following piece of code for subscribers to unsubscribe from my mailing list. The problem is that when the user clicks submit the file gets read into memory. If I open the file as open (DELETEFILE, . etc., the list gets overwritten entirely with nothing. It appears that nothing get saved in memory because I'll try to output @emailfile using print @emailfile; to test what is being saved and it is blank as well. If I open the file as open (DELETEFILE, . etc, the info gets stored into memory because I can print it out using print @emailfile which gives me the entire file. Then, when I try to print back to the file, it is the entire array. Nothing has changed. Can anyone see what I am doing wrong or offer a better approach? On a side note, I am doing all of the email validating and taint checking in a previous subroutine. Thanks, Andrew sub deleteFromSubscribeList { open (DELETEFILE, . $mailingListPath . $mailingListName) or die cannot open file for appending: $!; flock (DELETEFILE, 2) or die cannot lock file exclusively: $!; my @emailfile = DELETEFILE; # seek (DELETEFILE, 0, 0);# truncate (DELETEFILE, 0); # print @emailfile; foreach my $line (@emailfile) { if ($line !~ /^\Q$deleteEmail/o) { print DELETEFILE $line; # } } close (DELETEFILE) or die cannot close message file: $!; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: question about uninitialized variable
As a relative newbie myself, it appears that you have in essence applied a variable to a variable. I typically use the format my $name=param(name); when I have a form that has a field called name. This form field value (andrew for example) would be stored in param(name) which is then stored in the variable $name. Based on your code snippet, you do not appear to have a value in either holder $name or param(name). As I said earlier, I am pretty new at this too. Others please jump in. Andrew -Original Message- From: Tony Bandy [mailto:[EMAIL PROTECTED] Sent: Friday, March 07, 2003 1:43 PM To: [EMAIL PROTECTED] Subject: question about uninitialized variable Hello everyone, Fairly new to the list here (and perl), so if this is an inappropriate post, please forgive me. I've got the Learning Perl book plus a few others...but I'm still scratching my head over this one. Just a beginning test page where the end-user submits a name and gets a page back with that name in it. The page works,however, the warning I keep getting is: Use of uninitialized value in concatenation (.) or string... I also noticed this same type of warning when I attempt to take the same thing (user input) and try to compare it to another variable, using this example-- $my other variable=~/$name/ operator. I can't get anything to match. Here is a snippet of code that will generate the error messsage above: #!c:\Perl\Perl5.00402\bin\perl.exe -w #Set Perl Parameters #use strict; #The CGI.pm module will take input from the form and process it for you. use CGI qw(:standard); my $name=param(name); print h2You entered: $name p\n; Thanks in advance for any help you might be able to provide a newbie. -- Tony Bandy [EMAIL PROTECTED] OHIONET -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cgi.pm printing 1, not print statement
I have a basic script using cgi.pm that is supposed to take one form filed and pass it to a subroutine where I will validate the input. However, when it gets passed, all that prints to the browser is a 1. Can anyone offer any suggestions before I pull the rest of my hair out? Here is the script: #!/usr/bin/perl use strict; use lib qw(/home/usr25/data/lib/mailer); use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use ahSubscribe; my $choice = lc (param (choice)); if ($choice eq ) { subscribeForm(); } elsif ($choice eq subscribe) { validateEmail( param ( email ) ); } ### sub subscribeForm { print header(), start_html (-title = Subscribe Form, -bgcolor = #ff); print start_form (-action = url()), table( Tr ( td (E-mail Address:), td (textfield (-name = email, -size = 20)) ), Tr ( td ({-colspan = 1}, submit (-name = choice, -value = subscribe)), # td ( ) ), ), end_form (); print end_html(); } ### sub validateEmail { my $email = shift; print header(), start_html (-title = Validate Email, -bgcolor = #ff), print p (this is what you entered $email); print end_html(); } ### When I view the source of the generated page, it won't even print the static text in the paragraph tag. Take a look: ?xml version=1.0 encoding=utf-8? !DOCTYPE html PUBLIC -//W3C//DTD XHTML Basic 1.0//EN http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd; html xmlns=http://www.w3.org/1999/xhtml; lang=en-USheadtitleValidate Email/title /headbody bgcolor=#ff1/body/html Any suggestions are greatly appreciated! Thanks in advance, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: cgi.pm generate html vs. print EndOfHTML;
Actually, I am sort of embarrassed (and proud) to say that I figured out that one late last night. It works now. Thanks for all of your help ... and patience as usual. Andrew -Original Message- From: fliptop [mailto:[EMAIL PROTECTED]] Sent: Friday, January 17, 2003 8:15 AM To: Hughes, Andrew Cc: '[EMAIL PROTECTED]' Subject: RE: cgi.pm generate html vs. print EndOfHTML; On Thu, 16 Jan 2003 at 16:32, Hughes, Andrew opined: HA:I am pointing to the results.tmpl file which is in the same folder as the HA:the .pl script. I found another test script on the web on another website, HA:and I have the same problem -- the tags are not replaced with the HA:information in the script. Could it be a permission issues on the .tmpl HA:file or the .pl file? you need to point to the perl script, not the template file. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: cgi.pm generate html vs. print EndOfHTML;
My problem had to do with the content header. I also did not realize that you are supposed to point the .pl file in the browser. Rookie mistakes! As far as the TMPL_VAR tags, all of the tutorials that I have seen look like this TMPL_VAR NAME=SECRET_MESSAGE -- as opposed to TMPL_VAR SECRET_MESSAGE. Thanks, Andrew -Original Message- From: Derrick Spell [mailto:[EMAIL PROTECTED]] Sent: Friday, January 17, 2003 1:53 PM To: Hughes, Andrew Cc: [EMAIL PROTECTED] Subject: Re: cgi.pm generate html vs. print EndOfHTML; I'm new to the HTML::Template module as well, but from what I can see, it beats the pants off using print eohJust out of curiosity (and maybe for the sake of the list) did your problem have to do with the syntax of the TMPL_VAR tag? I don't think you are suppose to use a name attribute, I think you just put the name of the parameter in the tag. TMPL_VAR SECRET_MESSAGE instead of TMPL_VAR NAME=SECRET_MESSAGE Don't be embarrassed - in three days nobody on this list figured it out! -Derrick On Friday, Jan 17, 2003, at 09:03 US/Eastern, Hughes, Andrew wrote: Actually, I am sort of embarrassed (and proud) to say that I figured out that one late last night. It works now. Thanks for all of your help ... and patience as usual. Andrew -Original Message- From: fliptop [mailto:[EMAIL PROTECTED]] Sent: Friday, January 17, 2003 8:15 AM To: Hughes, Andrew Cc: '[EMAIL PROTECTED]' Subject: RE: cgi.pm generate html vs. print EndOfHTML; On Thu, 16 Jan 2003 at 16:32, Hughes, Andrew opined: HA:I am pointing to the results.tmpl file which is in the same folder as the HA:the .pl script. I found another test script on the web on another website, HA:and I have the same problem -- the tags are not replaced with the HA:information in the script. Could it be a permission issues on the .tmpl HA:file or the .pl file? you need to point to the perl script, not the template file. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: cgi.pm generate html vs. print EndOfHTML;
Thanks for the feedback. Before I get started on the html::template tutorial, I wanted to try a quick sample page using html::template. However, when I try it, I cannot get the tag in the html to process. Could someone take a look and let me know what you think I am doing incorrectly? This is the .pl file #! /usr/bin/perl -w # nationalConsumerShoppingSurveyResults.pl use strict; use lib qw(/home/ahughes/myLibrary); use CGI qw(:standard escape escapeHTML); use CGI::Carp qw(fatalsToBrowser); use HTML::Template; my $bar = 'World'; my $template = HTML::Template-new(filename = 'results.tmpl'); $template-param(SECRET_MESSAGE = $bar); print $template-output; This is the .tmpl file: !-- results.tmpl -- html head titleUntitled Document/title meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 /head body bgcolor=#FF text=#00 h1Hello TMPL_VAR NAME=SECRET_MESSAGE/h1 /body /html When I view the source of results I see the tag TMPL_VAR NAME=SECRET_MESSAGE where I expect to see World. Any thoughts? Andrew -Original Message- From: fliptop [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 16, 2003 7:07 AM To: Hughes, Andrew Cc: '[EMAIL PROTECTED]' Subject: Re: cgi.pm generate html vs. print EndOfHTML; On Wed, 15 Jan 2003 at 21:11, Hughes, Andrew opined: HA:does anyone have any strong feelings (know of tutorials) toward an HA:altrnative method like html::template or html::mason? Any and all HA:suggestions are greatly appreciated. http://www.peacecomputers.com/addressbook/step5.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: cgi.pm generate html vs. print EndOfHTML;
I added the content header line, and it does not work with that in there. I am pointing to the results.tmpl file which is in the same folder as the the .pl script. I found another test script on the web on another website, and I have the same problem -- the tags are not replaced with the information in the script. Could it be a permission issues on the .tmpl file or the .pl file? -Original Message- From: fliptop [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 16, 2003 12:59 PM To: Hughes, Andrew Cc: '[EMAIL PROTECTED]' Subject: RE: cgi.pm generate html vs. print EndOfHTML; On Thu, 16 Jan 2003 at 11:49, Hughes, Andrew opined: HA:Thanks for the feedback. Before I get started on the html::template HA:tutorial, I wanted to try a quick sample page using html::template. HA:However, when I try it, I cannot get the tag in the html to process. Could HA:someone take a look and let me know what you think I am doing incorrectly? HA: HA:my $template = HTML::Template-new(filename = 'results.tmpl'); HA:$template-param(SECRET_MESSAGE = $bar); you should probably print Content-type: text/html\n\n; here. HA:print $template-output; HA: HA: HA: HA:This is the .tmpl file: HA: HA:!-- results.tmpl -- HA:html HA:head HA:titleUntitled Document/title HA:meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 HA:/head HA: HA:body bgcolor=#FF text=#00 HA:h1Hello TMPL_VAR NAME=SECRET_MESSAGE/h1 HA: HA:/body HA:/html HA: HA: HA: HA:When I view the source of results I see the tag TMPL_VAR HA:NAME=SECRET_MESSAGE where I expect to see World. are you pointing to the perl script with your browser (and not the template file)? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cgi.pm generate html vs. print EndOfHTML;
I have to say that as a relative beginner, I have really noticed that using cgi.pm to generate forms and entire web pages is a more than a little time consuming. In the interest of time, I have been using print EndOfHTML; to print the html code (esp. forms) in my programs. There are limitations to this approach as well. The major one that I run into problems with is error-checking. I have not attempted to use html::Template or html::Mason yet, but I think that it is my next step. Can anyone tell me the limitations of using print EndOfHTML; to print my html vs. cgi.pm? Also, does anyone have any strong feelings (know of tutorials) toward an altrnative method like html::template or html::mason? Any and all suggestions are greatly appreciated. Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Apache::Session
Hello all, I am trying to use the Apache::Session module to create and store session information. This is my first attempt at using a session to store user info, so please stick with me. The book that I have been using for direction is Paul Dubois' MySQL and Perl for the Web. In it (pg. 329), he suggests that I create a package called WebDB::Session to avoid session-opening code in each script that uses session management. It acts as a front-end interface to the Apache::Session module. I have done this. However, each time I try to run the sample script, I receive the following error: # Session ID: f5d5d5b8652054c33708d1bdabb51122 Session Stage: 1 Content-type: text/html Software error: Can't locate object method sesion_id via package WebDB::Session (perhaps you forgot to load WebDB::Session?) at stages_url.pl line 63. # Does anyone have any suggestions? There is a fair amount of code involved, so I wanted to wait before posting all of it. Any assistance is greatly appreciated. Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
how to print mysql table to text file backup with perl
I have a mysql table with about 3000 rows of data on which that I need to perform a daily backup. Because I am on a shared hosting account I do not have administrative rights to the database. To back it up currently I have a script that prints each line of data to the browser delimited with pipes using this code: $stmt = qq { select * from 2002brochurecontest }; $sth = $dbh-prepare ($stmt); $sth-execute (); $count = 0; while (my $row = $sth-fetchrow_hashref()) { print $row-{id}|$row-{t}|$row-{f_name}|$row-{l_name}|$row-{w_phone}|$row-{w _phone_ext}|$row-{division}|$row-{email}|$row -{eclub}|$row-{country}|$row-{brochure}|$row-{purchase}, br(); } $sth-finish(); I take the output and print it to my browser. Then I cut and paste it into a text file. To avoid this extra step and to learn something new, I would like to print the data to a text file. Each day I would just overwrite the same text file with the data, so I would not have to create a new file every time the script runs. Can anyone point me in the right direction? Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: how to print mysql table to text file backup with perl
Thanks so much. I got some help offline that did the trick. The suggestion that worked was to do the following: my $filename = out.txt; open(OUTFILE,$filename); $stmt = qq { select * from 2002brochurecontest }; $sth = $dbh-prepare ($stmt); $sth-execute (); $count = 0; while (my $row = $sth-fetchrow_hashref()) { print OUTFILE $row-{id}|$row-{t}|$row-{f_name}|$row-{l_name}|$row-{w_phone}|$row-{w _phone_ext}|$row-{division}|$row-{email}|$row -{eclub}|$row-{country}|$row-{brochure}|$row-{purchase}\n; } $sth-finish(); close(OUTFILE); Thanks, Andrew -Original Message- From: LRMK [mailto:[EMAIL PROTECTED]] Sent: Monday, January 06, 2003 2:16 PM To: Hughes, Andrew; [EMAIL PROTECTED] Subject: Re: how to print mysql table to text file backup with perl where do you want to save your file on your PC or on the server Sign L Rakhitha Malinda Karunarathne Web :- rakhitha.cjb.net Email :[EMAIL PROTECTED] Rakhitha Malinda Karunarathne. - Original Message - From: Hughes, Andrew [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, January 07, 2003 12:58 AM Subject: how to print mysql table to text file backup with perl I have a mysql table with about 3000 rows of data on which that I need to perform a daily backup. Because I am on a shared hosting account I do not have administrative rights to the database. To back it up currently I have a script that prints each line of data to the browser delimited with pipes using this code: $stmt = qq { select * from 2002brochurecontest }; $sth = $dbh-prepare ($stmt); $sth-execute (); $count = 0; while (my $row = $sth-fetchrow_hashref()) { print $row-{id}|$row-{t}|$row-{f_name}|$row-{l_name}|$row-{w_phone}|$row-{w _phone_ext}|$row-{division}|$row-{email}|$row -{eclub}|$row-{country}|$row-{brochure}|$row-{purchase}, br(); } $sth-finish(); I take the output and print it to my browser. Then I cut and paste it into a text file. To avoid this extra step and to learn something new, I would like to print the data to a text file. Each day I would just overwrite the same text file with the data, so I would not have to create a new file every time the script runs. Can anyone point me in the right direction? Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: how to print mysql table to text file backup with perl
That makes a lot of sense. If I strip out the pipes, tabs, hard returns etc. going into the database table, do you think that I should be okay not using the module? My gut response to my own question is not to assume anything. Thanks, Andrew -Original Message- From: fliptop To: Hughes, Andrew Cc: [EMAIL PROTECTED] Sent: 1/6/2003 6:21 PM Subject: RE: how to print mysql table to text file backup with perl On Mon, 6 Jan 2003 at 15:11, Hughes, Andrew opined: HA:my $filename = out.txt; HA:open(OUTFILE,$filename); HA: $stmt = qq { select * from 2002brochurecontest }; HA: $sth = $dbh-prepare ($stmt); HA: $sth-execute (); HA: $count = 0; HA: while (my $row = $sth-fetchrow_hashref()) HA:{ HA:print OUTFILE HA:$row-{id}|$row-{t}|$row-{f_name}|$row-{l_name}|$row-{w_phone}|$ row-{w HA:_phone_ext}|$row-{division}|$row-{email}|$row HA:-{eclub}|$row-{country}|$row-{brochure}|$row-{purchase}\n; HA: } HA:$sth-finish(); HA:close(OUTFILE); that's fine, but what if your data contains pipes? you should look into one of the csv modules on cpan. here's one i've used in the past with good success: http://search.cpan.org/author/JWIED/Text-CSV_XS-0.23/CSV_XS.pm by default, it uses a comma, but you can specify any character to use as the delimiter. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
replacing numbers around a decimal
I am creating a little calculator that is going to need to take a user entered number that will always have 2 decimal places (using sprintf). It could be 89562321.29 or it could be 101.00) and take the last 4 digits (with the period included, so five places) and do two things: 1)Store the number in a variable. For the two examples above that would be 21.29 and 01.00 respectively would be stored in their own variable x=21.29 or it could be x=01.00; and 2) replace the last 4 numbers (5 places) with 00.00 -- always. For the two examples above they would become 89562300.00 and 100.00. Can anyone point me in the right direction? Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: replacing numbers around a decimal
Thanks Felix. I actually used $start_discounted_gift_cert = ($total_start) * ($start_discounted_gift_cert_of_total); $start_discounted_gift_cert = sprintf(%8.2f,$start_discounted_gift_cert); $giftcert_remainder_first = substr($start_discounted_gift_cert, -5); $giftcert_remainder_first = sprintf(%8.2f,$giftcert_remainder_first); substr() works perfectly. Even though substr() works well, i believe that it was created to be used with strings not numbers. I know that you are all busy, but can anyone point out anything fundamentally wrong with my approach? Thanks, Andrew -Original Message- From: Felix Geerinckx [mailto:felix_geerinckx;hotmail.com] Sent: Thursday, October 17, 2002 3:06 PM To: [EMAIL PROTECTED] Subject: Re: replacing numbers around a decimal on wo, 16 okt 2002 20:03:31 GMT, Andrew Hughes wrote: I am creating a little calculator that is going to need to take a user entered number that will always have 2 decimal places (using sprintf). It could be 89562321.29 or it could be 101.00) and take the last 4 digits (with the period included, so five places) and do two things: 1)Store the number in a variable. For the two examples above that would be 21.29 and 01.00 respectively would be stored in their own variable x=21.29 or it could be x=01.00; and 2) replace the last 4 numbers (5 places) with 00.00 -- always. For the two examples above they would become 89562300.00 and 100.00. Can anyone point me in the right direction? my $number = 89562321.29; my $big = int($number/100)*100; my $small = $number - $big; printf(%.2f - %05.2f\n, $big, $small); -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
FW: replacing numbers around a decimal
Never mind. I figured it out using substr(). Thanks, Andrew -Original Message- From: Hughes, Andrew Sent: Wednesday, October 16, 2002 4:04 PM To: [EMAIL PROTECTED] Subject: replacing numbers around a decimal I am creating a little calculator that is going to need to take a user entered number that will always have 2 decimal places (using sprintf). It could be 89562321.29 or it could be 101.00) and take the last 4 digits (with the period included, so five places) and do two things: 1)Store the number in a variable. For the two examples above that would be 21.29 and 01.00 respectively would be stored in their own variable x=21.29 or it could be x=01.00; and 2) replace the last 4 numbers (5 places) with 00.00 -- always. For the two examples above they would become 89562300.00 and 100.00. Can anyone point me in the right direction? Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Running CGIs offline
I am running windows 2000 professional on my laptop and I am using Indigoperl (http://www.indigostar.com/indigoperl.htm). It was extremely easy to download, install and use. Andrew -Original Message- From: Scot Robnett [mailto:[EMAIL PROTECTED]] Sent: Monday, July 22, 2002 1:19 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: Running CGIs offline I have been interested in this sort of thing for awhile also. Looking forward to any helpful info! Scot R. inSite -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Monday, July 22, 2002 12:06 PM To: [EMAIL PROTECTED] Subject: Running CGIs offline I'm interested in taking a website, composed of HTML and perl cgis and moving it offline. I want to burn it to a CD that will run on Mac and PC, Explorer and Navigator. Are there tools to do this sort of thing? A browser-based perl interpreter? A CGI faker? Thank you for whatever you say! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
printf not printing correctly
I am having a problem making printf work correctly. The following line of code: printf(\$%4.2\n, $subtotal); prints outputs: $%4.2 to my browser. Subtotal is defined and if it equals 21 and I type: print qq($subtotal); it outputs 21. Does anyone have any suggestions? Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: printf not printing correctly
Thanks! It works now. -Original Message- From: Bob Showalter [mailto:[EMAIL PROTECTED]] Sent: Monday, July 22, 2002 2:57 PM To: 'Hughes, Andrew'; '[EMAIL PROTECTED]' Subject: RE: printf not printing correctly -Original Message- From: Hughes, Andrew [mailto:[EMAIL PROTECTED]] Sent: Monday, July 22, 2002 2:53 PM To: '[EMAIL PROTECTED]' Subject: printf not printing correctly I am having a problem making printf work correctly. The following line of code: printf(\$%4.2\n, $subtotal); ^ need an f here. printf(\$%4.2f\n, $subtotal); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
multi-page form and cgi.pm
I have been given the task of creating a multi-page form that will consist of 4 parts. The final page will the list out everything that the users have entered and ask if they would like to go back to any of the 4 sections to update the information. Once the users are satisfied with the final product, they will print it out. I know how to do this with multiple scripts and html forms and hidden fields. However, I would like to try to use one script with subroutines. I guess my main stumbling block is passing hidden form fields between subroutines. Can anyone offer me a simple example of how to go about passing a form field from one subroutine to another subroutine where it is a hidden field using cgi.pm? And/Or, can anyone point me in toward an applicable tutorial? Thanks in advance, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
more redirect script problems
I am still trying to create this redirect script that is called when the referring page refreshes after 0 seconds (with a meta tag) to the redirect.pl. I am having a couple of problems. The first is that when it refreshes the scripted does not recognize the page as the referring page. Each time I test it, my else statement is executed with the message, CGI=HASH(0x80fbc2c)-referer is not a valid. Please check the address and try again. When I hard code a link to the script, and click on it, I get an error that reads, Undefined subroutine main::meta called at redirect.pl line 14. Does anyone have an idea on how to make this script work or to go about it differently? Any/All suggestions are appreciated. Thanks, Andrew _ #!/usr/bin/perl -wT use CGI; use CGI::Carp 'fatalsToBrowser'; use strict; my $q = new CGI; my $referer = $q-referer; #my $onesite_atlhmbnk = $q-param('http://www.mysite.com/atlhmbnk/index.html'); #my $onesite_atlcas = $q-param('http://www.mysite.com/atlcas/index.html'); #my $onesite_brook = $q-param('http://www.mysite.com/brook/index.html'); if ($referer eq http://www.mysite.com/atlhmbnk/index.html;) { print $q-header(text/html), $q-start_html(-head=meta({-http_equiv='Refresh', -content='0; URL=http://www.mysite.com/atlcas/site.html'})), $q-p(This is atlcas), $q-end_html; } elsif ($referer eq http://www.mysite.com/atlcas/index.html;) { print $q-header(text/html), $q-start_html(-head=meta({-http_equiv='Refresh', -content='0; URL=http://www.mysite.com/atlhmbnk/site.html'})), $q-p(This is atlhmbnk), $q-end_html; } elsif ($referer eq http://www.mysite.com/brook/index.html;) { print $q-header(text/html), $q-start_html(-head=meta({-http_equiv='Refresh', -content='0; URL=http://www.mysite.com/brook/site.html'})), $q-p(This is brook), $q-end_html; } else { print $q-header(text/html), $q-start_html, $q-p($q-referer is not a valid. Please check the address and try again.), $q-end_html; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
redirect script problems
I am trying to write a script that will send a user to a certain webpage based on the refering url. I am embedding it in a .shtml page as an include. There are 3 urls that I will redirect to based on the refering url. The way it is now, if I type in the url http://www.mysite.com/atlhmbnk/index.shtml; in my browser, I get a web page that reads, This is atlcas. If I type in the url http://www.mysite.com/atlcas/index.shtml; in my browser, I get a webpage that reads, This is atlcas. If I type in the url http://www.mysite.com/brook/index.shtml; in my browser, I get a webpage that reads, This is atlcas. If I include the redirect.pl file in a file named test.pl to test the else statement, I still get a webpage that reads, This is atlcas. Any assistance would greatly be appreciated. Thanks, Andrew #!/usr/bin/perl -w use CGI; use strict; my $q = new CGI; my $referer = $q-referer; my $onesite_atlhmbnk = $q-param(http://www.mysite.com/atlhmbnk/index.shtml;); my $onesite_atlcas = $q-param(http://www.mysite.com/atlcas/index.shtml;); my $onesite_brook = $q-param(http://www.mysite.com/brook/index.shtml;); if ($referer eq $onesite_atlcas) { print $q-header(text/html), $q-start_html, $q-p(This is atlcas), $q-end_html; } elsif ($referer eq $onesite_atlhmbnk) { print $q-header(text/html), $q-start_html, $q-p(This is atlhmbnk), $q-end_html; } elsif ($referer eq $onesite_brook) { print $q-header(text/html), $q-start_html, $q-p(This is brook), $q-end_html; } else { print $q-header(text/html), $q-start_html, $q-p($q-referer is not a valid. Please check the address and try again.), $q-end_html; } ### -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
real beginner help needed
I need help. I inherited this script that adds people to a text file for our mailing list. It works in Explorer. However, it does not work in Netscape. Valid email addresses are blocked and the subroutine dienice is called in Netscape. It is pretty short and simple. I do not have time to rewrite it right now. Could anyone make any suggestions? Thanks in advance, Andrew #!/usr/bin/perl print Content-type:text/html\n\n; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split (//, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($l))/eg; $FORM{$name} = $value; } chdir '../../discounts/ia/'; $DESTINATION=http://www.website.com/eclub_thankyou.adp;; $f_name=$FORM{'f_name'}; $l_name=$FORM{'l_name'}; $company=$FORM{'company'}; $email=$FORM{'email'}; $us_state=$FORM{'us_state'}; $birth_month=$FORM{'birth_month'}; $birth_year=$FORM{'birth_year'}; $country=$FORM{'country'}; $salary=$FORM{'salary'}; $home=$FORM{'home'}; $clothing=$FORM{'clothing'}; $jewelry=$FORM{'jewelry'}; $air=$FORM{'air'}; $food=$FORM{'food'}; $hotel=$FORM{'hotel'}; $entertainment=$FORM{'entertainment'}; $auto=$FORM{'auto'}; $household=$FORM{'household'}; $electronic=$FORM{'electronic'}; $vacation=$FORM{'vacation'}; $tm = time; $now = localtime($tm); if ($FORM{'email'} !~ /[\w\-]+\@[\w\-]+\.[\w\-]+/) { dienice(Please enter a valid email address); } open(OUTF,eclub.xls); flock(OUTF,2); seek(OUTF,0,2); print OUTF $f_name\t$l_name\t$company\t$email\t$us_state\t$birth_month\t$birth_year\t$ country\t$salary\t$home\t$clothing\t$jewelry\t$air\t$food\t$hotel\t$entertai nment\t$auto\t$household\t$electronic\t$vacation\t$now\n; close(OUTF); print EndHTML; HEAD meta http-equiv=Refresh content=0; URL=$DESTINATION /HEAD EndHTML sub dienice { my($msg) = @_; print h2Error/h2\n; print $msg; exit; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mail script not working for Netscape (was real beginner help needed)
This is the piece of code that is giving me the problem I believe. It is the one that is supposed to check to make sure that a user enters a valid email address. When I comment it out, it works in both IE and NN. if ($FORM{'email'} !~ /[\w\-]+\@[\w\-]+\.[\w\-]+/) { dienice(Please enter a valid email address); } Thanks for your patience with my beginner faux pas. I will be a better member of this list from here on out. Andrew -Original Message- From: John Brooking [mailto:[EMAIL PROTECTED]] Sent: Thursday, May 23, 2002 1:24 PM To: Hughes, Andrew; [EMAIL PROTECTED] Subject: Re: Mail script not working for Netscape (was real beginner help needed) Can you post some of the relevant code? (If it's long, please consider putting it up as an HTML page and just sending us the URL.) Not that I'm promising I personally will have time to look at it or know the answer... --- Hughes, Andrew [EMAIL PROTECTED] wrote: I need help. I inherited this script that adds people to a text file for our mailing list. It works in Explorer. However, it does not work in Netscape. Valid email addresses are blocked and the subroutine dienice is called in Netscape. It is pretty short and simple. I do not have time to rewrite it right now. Could anyone make any suggestions? Thanks in advance, Andrew #!/usr/bin/perl print Content-type:text/html\n\n; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split (//, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($l))/eg; $FORM{$name} = $value; } chdir '../../discounts/ia/'; $DESTINATION=http://www.website.com/eclub_thankyou.adp;; $f_name=$FORM{'f_name'}; $l_name=$FORM{'l_name'}; $company=$FORM{'company'}; $email=$FORM{'email'}; $us_state=$FORM{'us_state'}; $birth_month=$FORM{'birth_month'}; $birth_year=$FORM{'birth_year'}; $country=$FORM{'country'}; $salary=$FORM{'salary'}; $home=$FORM{'home'}; $clothing=$FORM{'clothing'}; $jewelry=$FORM{'jewelry'}; $air=$FORM{'air'}; $food=$FORM{'food'}; $hotel=$FORM{'hotel'}; $entertainment=$FORM{'entertainment'}; $auto=$FORM{'auto'}; $household=$FORM{'household'}; $electronic=$FORM{'electronic'}; $vacation=$FORM{'vacation'}; $tm = time; $now = localtime($tm); if ($FORM{'email'} !~ /[\w\-]+\@[\w\-]+\.[\w\-]+/) { dienice(Please enter a valid email address); } open(OUTF,eclub.xls); flock(OUTF,2); seek(OUTF,0,2); print OUTF $f_name\t$l_name\t$company\t$email\t$us_state\t$birth_month\t$birth_year\t$ country\t$salary\t$home\t$clothing\t$jewelry\t$air\t$food\t$hotel\t$entertai nment\t$auto\t$household\t$electronic\t$vacation\t$now\n; close(OUTF); print EndHTML; HEAD meta http-equiv=Refresh content=0; URL=$DESTINATION /HEAD EndHTML sub dienice { my($msg) = @_; print h2Error/h2\n; print $msg; exit; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] = When you're following an angel, does it mean you have to throw your body off a building? - They Might Be Giants, http://www.tmbg.com Word of the week: Serendipity, see http://www.bartleby.com/61/93/S0279300.html __ Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience http://launch.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Text file manipulation
I have a pipe delimited text file that I use as a mailing list I have information in the following format: lastname|firstname|company|email|state|date I am using it as a mailing list. However, over the last half year, it has gotten pretty big, and has some duplicates in it. For reporting sake, I would like to delete the duplicate records based on email addresses. If you sign up three times, I only want to keep your first record in there. I want this file: jones|Bob|Acme1|[EMAIL PROTECTED]|GA|2/25/2002 jones|Bob|Acme1|[EMAIL PROTECTED]|GA|2/28/2002 smith|Jan|Acme2|[EMAIL PROTECTED]|FL|3/1/2002 johnson|Salley|Acmeshop|[EMAIL PROTECTED]|TN|4/5/2002 SMITH|JAN|ACME2|[EMAIL PROTECTED]|FL|5/2/2002 to change to this file: jones|Bob|Acme1|[EMAIL PROTECTED]|GA|2/25/2002 smith|Jan|Acme2|[EMAIL PROTECTED]|FL|3/1/2002 johnson|Salley|Acmeshop|[EMAIL PROTECTED]|TN|4/5/2002 Can anyone point me in the right direction? I appreciate any help. Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
permissions question
I have a pipe delimited text file in which I am collecting form submissions. I have the permissions currently set to 666. The problem is that if someone can figure out the path the .txt file, they can view it from their browser. I do not want this to happen. After a period of time, I am planning to ftp into the server and grab the .txt file to use the addresses for a mailing. What permissions should I use in order to have people write to the database from my form in their browser, but not view the text file from their browser? Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: permissions question
I can see how that would be ideal. However, I am not able to do that at this time. Short of keeping it outside of a web server, what security precautions (including permissions 666 etc.) could I take to keep people from viewing the text file from the browser. Thanks, Andrew -Original Message- From: Lisa Nyman [mailto:[EMAIL PROTECTED]] Sent: Monday, February 25, 2002 8:58 AM To: Hughes, Andrew Subject: Re: permissions question Hi, Any sort of data file should be maintained outside of web server space with permissions that allow the web demon to access it in the manner it needs to. Your CGIs can get to the file but web browsers can't. Lisa Wolfisch Nyman [EMAIL PROTECTED] IT Warrior Princess Life is too short to wear ugly underwear. Get the facts at http://quickfacts.census.gov/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Limiting form field submission length with perl
I have a form that people are going to be filling out online. I am using JavaScript on the front-end to validate the form. However, for security sake and for my own knowledge, I would like to know how to limit the length of form submissions on my server validation sequence. I don't want to cut the field off and accept incomplete information. I want to let the user know that their submission is too long (i.e. it must be less than). if ($FORM{'field'} is less than 25 characters) { subroutine(Please limit your response to less than 25 characters.); } elsif ... Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
text file database question
I have been given the task to create a contest for which appox. 90,000 people might be signing up(collected info: name, company, email, phone, address1, address2). Due to various reasons, I am not able to use a true database like mySQL to store the information. At this point I am going to have to use a text file, which I have used in the past, but not at this level of possible entries (we are really going to be promoting this heavily on and offline). Please let me know if you think this is a possible dangerous level of entries for a text file. Also, in my experience with text files, I have not been able to stop people from hitting submit a few times before the form submits (i.e. I have multiple lines of the same entry). How would I stop this -- still talking about text files? Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
formatting database text
I have created a news article database where non-technical people can cut and paste articles to be stored in a mySQL database table. Everything works. However when I display these in a browser, I want to have p class=whatever/p tags around each paragraph, so that the non-technical people do not have to worry about adding these tags. I was thinking the logic would go something like this: When displaying the body field of the database, before anything else print p class=whatever Then, for each blank line print /pp class=whatever Finally, after the last paragraph print /p Should I do this when the articles go into or are pulled out of the database? How do I go about doing this? All suggestions are welcome. Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
news articles database
I want to create an website where my brother can load his news articles for searching, sorting, displaying and printing online. I can figure out the basics with perl (CGI.pm and DBI) and mySQL. However, I was wondering what would be the best way to go about storing each article's content considering that I will want to format the output and keep paragraph breaks online etc. Do I store them as .txt files, .doc files or cut an paste the content? Any input from people who have gone down this path or can point out some possible pitfalls is greatly appreciated. Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]