Re: checking if its a real number
On Wed, 26 Feb 2003 16:30:56 -0800, T. Murlidharan Nair wrote: Is there a quick and easy way to check this. I was trying using a reg exp if(/^[-0-9][\.0-9]*/) { do something } In CPAN there's also a module Regexp::Common that has a lot of commonly requested regexps. E.g. also $RE{num}{real} Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: checking if its a real number
On Wed, 26 Feb 2003 19:47:35 -0500, Casey West wrote: Here's a nice trick. Use the int() function. It's documented in perlfunc, a short to the documentation is 'perldoc -f int'. When passed a string, int() will return 0. When passed a number, it will return the integer version of that number. Armed with this knowledge, it's fair to assume that when passed an integer, the following expression will be true: $data == int( $data ); Sorry, but that's wrong. Have a look to this one liner: perl -e '$x = 123kg; print $x is , ($x == int($x)) ? numeric : a string' int() interpretes its argument in numeric context what will be with most strings 0 (if the string starts with a non-number). But if it starts with something number-like it's whole a different story. Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CGI.pm strange results
On Mon, 3 Mar 2003 16:07:26 -0500, [EMAIL PROTECTED] (Todd Wade) wrote: Zentara [EMAIL PROTECTED] wrote in message You might want to try assigning a variable name to param(quantity) first, before you set up the table. I don't know why, but sometimes the scripts don't like it any other way. I've run into this type of thing before, and just take the easy way out, and assign a variable. This is not true at all. Well what ever the reason is, it has worked that way sometimes for me. When you start deeply nesting and quoting in tables and here documents, Perl will sometimes fail to interpolate unless you force the value into a variable. I guess I havn't learned the trick yet. If you look at the html source, there are multiple input fields are named quanity. You need a way of indexing your quanity fields so you know which value of the array to fetch while looping through the selected items. Yeah, I realized that while thinking about it later. Another solution is to put an separate order button along each item, or he can rename the quantity parameter to quantity-furry, quantity-stripped, etc,etc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CGI.pm strange results
Zentara [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Mon, 3 Mar 2003 16:07:26 -0500, [EMAIL PROTECTED] (Todd Wade) wrote: Zentara [EMAIL PROTECTED] wrote in message You might want to try assigning a variable name to param(quantity) first, before you set up the table. I don't know why, but sometimes the scripts don't like it any other way. I've run into this type of thing before, and just take the easy way out, and assign a variable. This is not true at all. Well what ever the reason is, it has worked that way sometimes for me. When you start deeply nesting and quoting in tables and here documents, Perl will sometimes fail to interpolate unless you force the value into a variable. I guess I havn't learned the trick yet. Sorry, not true at all. There really is no trick. Interpolating is interpolating is interpolating. When you start ?deeply nesting? and quoting in tables and here documents, perl will never fail to interpolate unless you don't understand the syntax and semantics of injecting values into literals. Perhaps you could post an example, because I am very curious. But taking an educated guess at the problem you are having, I would say you are talking about getting CGI.pm's param() function to return in a string. my( $string ) = you ordered $q-param('quantity') foobars\n; The quoting mechanism knows nothing about evaluating expressions. That's what concatenation is for: my( $string ) = you ordered . $q-param('quantity') . foobars\n; Todd W. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to access CGI
Hi How do i access the files in my CGI-BIN, when my web site data is stored in /htdocs (a different directory). /home/httpd/htdocs/index.htmlweb site files /home/httpd/cgi-bin/ cgi files Cheers _ It's fast, it's easy and it's free. Get MSN Messenger today! http://messenger.msn.co.uk -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
using CGI.pm for catalog
Hello, I am having a problem understanding why I can't get the data from the form page to CGI script. Here is the page in question: http://www.coraconnection.com/paul_s/pages/catalog.html In the HTML form method=post action=/cgi-bin/build_order.cgi !-- there are several items of the form -- img src=../images/GUC-247-small.jpg alt=GUC-247-small width=120 height=179 some descriptive text goes here. div class=item ORDER input type=checkbox name=hand-bag-style-dots value=GUC-247-small onclick=upDateQuantity() br QUANTITY input type=text size=2 name=quantity value=0 tabindex=26 onchange=checkNumber(this.value,0) /div In the PERL #!/usr/bin/perl -w use CGI qw/:standard/; new attempt: -- still not working ! @bags = param('handbag'); # get all of the bags styles @bag_quantity = param('quantity'); # get all of the bags quantity my $count=0; print qq|table border=1\ntr\n|; print qq|th colspan=2Description/ththQuantity/ththPrice/th\n|; print /tr\n; foreach my $bag (@bags){ my ($description,$imgName) = split (/,/,$bag) if ($bag =~ m/,/); print tr\n; print qq|tdimg src=../paul_s/images/| . $imgName . qq|.jpg alt=$imgName width=120 height=179 alt= bag /td\n|; print td$description/td; print td$bag_quantity[$count]/tdtd\$Price goes here/td\n; print /tr\n; $count++; } print /table\n; Old version that did not work, #!/usr/bin/perl -w use CGI qw/:standard/; #... unrelated code removed ... print qq|table border=1\n|; foreach $name (param()){ my $val= param($name); my $nextRow = ($name =~ m/.jpg/); print tr if $nextRow; print qq|tdimg src=../paul_s/images/| . $val . qq|.jpg alt=$name width=120 height=179 alt= bag /td\n|; print td$name: $val/td; print td, param(quantity), /tdtd\$Price goes here/td\n; print /tr\n if $nextRow; } print /table\n; Please point out what I have done wrong. Thanks Dave Gilden ( kora musician / audiophile / web master @ cora connection / Ft Worth, Tx, USA) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CGI.pm strange results
On Tue, 4 Mar 2003 at 08:12, Todd W opined: TW:my( $string ) = you ordered $q-param('quantity') foobars\n; TW: TW:The quoting mechanism knows nothing about evaluating expressions. That's TW:what concatenation is for: TW: TW:my( $string ) = you ordered . $q-param('quantity') . foobars\n; or sprintf: my $string = sprintf you ordered %d foobars, $q-param('quantity'); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
data structures
I am trying to build a data structure, and am tripping up here. any suggestions? Thx! Dave !/usr/bin/perl -w snip... @bags = param('handbag'); get all of the bags styles @bag_quantity = param('quantity'); get all of the bags quantity foreach my $bag (@bags){ ($bag_name,$imgName) = split (/,/,$bag); push %bags_ordered,$bag_name; push %bags_ordered{$bag_name}{image_name} = $imgName; } foreach my $q (@bag_quantity){ push %bags_ordered{$bag_name}{$bag_quantity} =$q; } Data structure: %bags_ordered = ( bag-style1 = { price = 10, image_name = 'FIO-142b-small', quantity= 5 }, bag-style2 = { price = 12, image_name = 'GUC-208-small', quantity= 5, }, ); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: data structures
any suggestions? I'll try. @bags = param('handbag'); get all of the bags styles Missing comment... @bags = param('handbag'); # get all of the bags styles push %bags_ordered,$bag_name; You can't push onto a hash, only an array. So either %bags_ordered need to be an array, or you mean something else. Maybe this is what you mean... use strict; # a big bonus for debugging use Data::Dumper; # for testing my %bags_ordered; my @bags = param('handbag'); # get all of the bags styles my @bag_quantity = param('quantity'); # get all of the bags quantity for (my $i = 0; $i @bags; $i++) { # split the bag item my ($bag_name, $imgName) = split (/,/, $bags[$i]); # create an empty hash if this is a new bag $bags_ordered{$bag_name} = {} unless exists $bags_ordered{$bag_name}; # set the image name $bags_ordered{$bag_name}-{image_name} = $imgName; # set the quantity. should it be additive with +=? $bags_ordered{$bag_name}-{quantity} = $bag_quantity[$i]; } # print the structure for testing using Data::Dumper print Dumper \%bags_ordered; Rob -Original Message- From: David Gilden [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 04, 2003 4:57 PM To: [EMAIL PROTECTED] Subject: data structures I am trying to build a data structure, and am tripping up here. any suggestions? Thx! Dave !/usr/bin/perl -w snip... @bags = param('handbag'); get all of the bags styles @bag_quantity = param('quantity'); get all of the bags quantity foreach my $bag (@bags){ ($bag_name,$imgName) = split (/,/,$bag); push %bags_ordered,$bag_name; push %bags_ordered{$bag_name}{image_name} = $imgName; } foreach my $q (@bag_quantity){ push %bags_ordered{$bag_name}{$bag_quantity} =$q; } Data structure: %bags_ordered = ( bag-style1 = { price = 10, image_name = 'FIO-142b-small', quantity= 5 }, bag-style2 = { price = 12, image_name = 'GUC-208-small', quantity= 5, }, ); -- 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: data structures / CGI.pm
Good afternon, I am not seeing consistent results from my script below. It seems that sometimes it works and other times I get '0's in the quantity field. As I don't write PERL often enough this is probably poorly written code! Thanks for any help. Dave HTML at: http://www.coraconnection.com/paul_s/pages/catalog.htm #!/usr/bin/perl -w use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use strict; my (@bags,@bag_quantity); my ($bag_name,$imgName); my (%bags_ordered,%prices); my $n=0; my $bags_ordered; use Data::Dumper; # Build data structure @bags = param('handbag'); # get all of the bags styles @bag_quantity = param('quantity'); # get all of the bags quantity foreach my $bag (@bags){ ($bag_name,$imgName) = split (/,/,$bag); $bags_ordered{$bag_name} = {} unless exists $bags_ordered{$bag_name}; # thanks rob! $bags_ordered{$bag_name}-{image_name} =$imgName; $bags_ordered{$bag_name}-{quantity} = $bag_quantity[$n]; $n++; } ## I don't think '-' really needed # will the order be correct, don think so! Prices amounts with out '$' # %prices = ( 'bag-style-dots' = 12, 'bag-style-dogs' =5, 'bag-style-cats' =44, 'bag-style-leather' =15, 'bag-style-fur' =23, 'bag-style-stripes' =12, 'bag-style1' =14, 'bag-style2' =6, 'bag-style3' =51, ); # #%bags_ordered = ( #bag-style1 = { price = 10, # image_name = 'FIO-142b-small', #quantity= 5 # }, # #bag-style2 = { price = 12, # image_name = 'GUC-208-small', # quantity= 5, # }, # #); print header; # print HTML print START_HTML; !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd; html lang=en head titleCatalog/title style type=text/css media=all !-- [EMAIL PROTECTED] ../paul_s/css/list.css; -- /style style type=text/css media=screen !-- #catalog td {text-align:center; } -- /style link rel=stylesheet href=/paul_s/css/main.css type=text/css /head body bgcolor=white text=black img src=../paul_s/images/banner.jpg alt= tmp banner width=720 height=76 border=1 h1 align=centerComplete your order/h1 pmore text on how complete your order../p START_HTML [EMAIL PROTECTED] = param(); #foreach my $name (@test){ #my $val = param($name); # print qq|p\$name $name \$val $val/p\n|; # } print Dumper \%bags_ordered; print hr noshade\n; print qq|table border=1 width=600\ntr\n|; print qq|th colspan=2Description/ththQuantity/ththPrice/th\n|; print /tr\n; foreach my $bag (keys %bags_ordered){ print tr\n; print qq|tdimg src=../paul_s/images/| . $bags_ordered{$bag}{image_name} . qq|.jpg alt=$imgName width=120 height=179 alt= bag /td\n|; print td$bag/td; print td$bags_ordered{$bag}{quantity}/tdtd\$$prices{$bag}/td\n; print /tr\n; } print trtdnbsp;/tdtdsubtotal/td\n; print trtdnbsp;/tdtd fill in /td\n; print /table\n; #print ORDER_HTML; #ORDER_HTML # print end html tags print end_html; # print start_form( -method = 'post' , -action =finnish-not done.pl); exit; == Cora Connection: Your West African Music Source Resources, Recordings, Instruments More! http://www.coraconnection.com/ == -- 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]
Help really needed in this script: error: Prematue end of script header
Hi, I have with the help of one of the guys of this list got this script to take an image from one directory and then rename it with the time and date of the image and then store it onto a new directory. I sotred the image in the cgi-bin, and then tried to run the file, i got errors, when i went to the errorlog i got an error saying: Prematue end of script header: /home/httpd/cgi-bin.renamer.cgi Regards, Mel #!/usr/bin/perl use strict; use warnings; =head1 NAME # renamer - renames files received by ftp, moving them to a new directory =head1 SYNOPSIS nohup ./renamer image /home/httpd/htdocs /home/me/images jpg =head1 DESCRIPTION #The above instructs renamer to look for files called image.jpg in /home/httpd/htdocs. #It checks once per minute for such a file to appear. If it sees a #readable file called /home/httpd/htdocs.jpg it moves it to #/home/httpd/htdocs/image.200302251530.jpg where the number is a #time stamp with year (four digits), month, day of the month, hour (in #24 mode), and minute. #Read the bugs section closely. =head1 BUGS #The original and new directories must be on the same file system. #The program probably does not work on windows systems. #The daemon behavior is weak. #Not much testing has been done, so the script may have other problems. =cut my $usage = EOUSAGE; usage: $0 initial_name original_dir new_dir suffix example: $0 pic /home/httpd/htdocs /home/me/images jpg EOUSAGE my $check_file = shift or die $usage; my $original_dir = shift or die $usage; my $new_dir = shift or die $usage; my $suffix = shift or die $usage; exit if (fork()); while (1) { process($check_file) if (-r $original_dir/$check_file.$suffix); sleep 60; } sub process { my $file = shift; my ($hour, $min, $mon, $day, $year) = (localtime)[1..5]; $year += 1900; $mon++; my $stamp = $year$mon$day$hour$min; print renaming $original_dir/$file.$suffix to $new_dir/$file.$stamp.$suffix\n; rename $original_dir/$file.$suffix, $new_dir/$file.$stamp.$suffix or warn couldn't rename file $file to $new_dir/$file.$stamp.$suffix\n; } _ It's fast, it's easy and it's free. Get MSN Messenger today! http://messenger.msn.co.uk -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help really needed in this script: error: Prematue end of script header
mel awaisi wrote: Hi, I have with the help of one of the guys of this list got this script to take an image from one directory and then rename it with the time and date of the image and then store it onto a new directory. I sotred the image in the cgi-bin, and then tried to run the file, i got errors, when i went to the errorlog i got an error saying: Prematue end of script header: /home/httpd/cgi-bin.renamer.cgi Regards, The script you have written is running as a pseudo-daemon, so you will not want to run it as a cgi script. It should be running constantly, aka run it from a terminal and background it. You need to separate the parts of your app that will always be running, aka the script that grabs the photos and moves them, from the parts that are web viewable, on demand, more than one occurrence, etc. If your updating is only going to be once a minute you might also consider just using cron rather than sleeping for 60 seconds, but this is a design decision. snip exit if (fork()); This probably doesn't do what you want. Check out: perldoc -q fork perldoc -f fork perldoc perlipc fork returns the PID of the forked child upon success, and the PID will always be positive so the above will always exit the program, which is naturally not what you want. while (1) { process($check_file) if (-r $original_dir/$check_file.$suffix); sleep 60; } Here do you want to pass only the filename sans-suffix? This is a design decision. Later when you strip the subs into libraries you will run into scoping issues. Essentially, ANYTHING used inside the sub should either be created there or passed into it. For instance you might be better off passing in the $suffix, $check_file, etc. sub process { my $file = shift; my ($hour, $min, $mon, $day, $year) = (localtime)[1..5]; perldoc -f localtime 1 or more of your above variables will not be set correctly. $year += 1900; $mon++; my $stamp = $year$mon$day$hour$min; print renaming $original_dir/$file.$suffix to $new_dir/$file.$stamp.$suffix\n; rename $original_dir/$file.$suffix, $new_dir/$file.$stamp.$suffix or warn couldn't rename file $file to $new_dir/$file.$stamp.$suffix\n; In warnings like the above you should always include $!, it is a special variable that will tell you why what you were trying to do failed. Looks like a good start... If you were in my class you would be well on your way to an A, you included the strict/warnings and documentation (two *very* good habits). http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]