Re: real beginners stuff
Jimmy, Sorry I had not read this post before I replied to the other. You need the permissions on a folder to be readable and executable in order for people to read what is in that folder period (not just execute scripts). So your folder needs to be permissions 755. Your script must be readable and executable in order for somebody to run your script, so again permissions 755. 3 digit permission assignments: - first position is the file owners permissions - second position is the file groups permissions (permissions for everyone in the group of the user who owns the file) - third position is the permissions for the whole world. how to get a permission digit: 4 = read 2 = write 1 = execute Add all of the allowed permissions to get the permission digit example, 7 allows anything, 6 is read and write, 5 is read and execute. Directories are kinda strange because you have to be able to execute them in order to get a directory listing. Regards, David - Original Message - From: Jimmy George [EMAIL PROTECTED] To: cgi [EMAIL PROTECTED] Sent: Tuesday, August 13, 2002 1:02 AM Subject: real beginners stuff Hello World If I logon to the web via (say) server_a and then start this script in server_b which has the code in its cgi-bin folder #! /usr/bin/perl -w # use CGI qw(:standard); #use strict; # print END_of_file; Content-type: text/html html headtitleServer Environment/title/head body h2This server is:/h2brbr Server Name: $ENV{SERVER_NAME} Port Number: $ENV{SERVER_PORT} Server Software: $ENV{SERVER_SOFTWARE} /body/html END_of_file should I get to see the %ENV details of server_a? I am getting a 500 error. Permissions are set to 711 for the script and 701 for the folder. cheers Jimmy George -- 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 the code
$self-{_Email} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $self-{_Email} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/ should be $self-{_Email} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $self-{_Email} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/ Regards, David - Original Message - From: Soheil Shaghaghi [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, August 10, 2002 1:41 AM Subject: Problem with the code Hi everyone, The following sub checks for bad e-mail address, and reports it: if (($self-{_Email} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $self-{_Email} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)) { $cool = undef; # No longer cool $message = $self-{_EmailInvalidMessage}; my $m = MessageText-new(Replacements = \%r, Message = $message); $self-{_ErrorEmail} = $m-print; } However, the code is rejecting the domains ending with .info, and .name (the reason is that it has 4 digits after the zero) Can someone please tell me how to change this code so it works please. -- 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: Post to a second CGI script
Jim, My recommendation is to write a session file on your server and pass the session id around with the browser variables. Now whether you use cookies, get or post to pass the session id, you don't have to be passing the actual username. If you don't want to have the user see the session id, put it in a cookie, and check to see if the cookie was created, if not, then send it via a form with post. If you want to be really sneaky about it, get your session id, then encrypt the id before giving it to the individual, so if they modify it, the decrypted version of what they pass back will not only not match theirs, but it cant match any one else's session id because it likely will not translate into a valid session id format. Good Luck, David - Original Message - From: Jim Lundeen [EMAIL PROTECTED] To: begin begin [EMAIL PROTECTED] Sent: Monday, July 29, 2002 6:06 PM Subject: Post to a second CGI script Hello All, I have 2 scripts. One accepts 3 values LOGIN_USERNAME, LOGIN_PASSWORD and ACTION from an HTML form. That script looks in a user table in MySQL to verify the user. If valid, it passes them to MENU.CGI with LOGIN_USERNAME and a unique session number (USN). Here's the question: How to I post the LOGIN_USERNAME and USN to the MENU.CGI script? I don't want the user carrying the info around in the Location bar as ?USN=1234LOGIN_USERNAME=somebody -- I want it to be part of the user's Perl process if you know what I mean, so that if they hit RELOAD the values are still with them. Too, I don't want someone trying to modify the info if it were in the Location bar, so it needs to be a part of the post. Any advice would be much appreciated! Thanks! Jim -- 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: malformed header from script???
Webster, Looks like your content-type is not being printed soon enough. You should consider placing it at the very top of your script unless you expect print some other kind of header (like a Location). print Content-Type: text/html\n\n; Regards, David - Original Message - From: webster [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, July 25, 2002 1:10 PM Subject: malformed header from script??? I'm getting this error: malformed header from script. Bad header=EHLO stanislaw if I turn off use strict, I get the error Premature end of script headers my code is posted below, and it runs all the way through because it sends the email - and the email has The error codes dont have line numbers with them, so Im not sure where to look. Any help?? here is my code. Its purpose is to take information from a form and email it to someone...try not to laugh at it __ #!/usr/bin/perl -w use strict; use CGI; use XML::Twig; use Date::Calc qw( System_Clock ); use SendMail; #---path stuff - you need to set these to values appropriate to your system my $pathToAssignNum = /usr/local/httpd/htdocs/summer/xml/assignNum.txt; my $pathToReport_xml = /usr/local/httpd/htdocs/summer/xml/report.xml; my $genWorkReport_URL = http://somehostname.edu/cgi-bin/genWorkReport.cgi;; my $query = new CGI; #---setup SendMail my $sm = new SendMail(); $sm-setDebug($sm-ON); $sm-To( Jeremy Webster jwebster\@olemiss.edu ); $sm-Subject(Work Order); my $email = $query-param('email'); $sm-From($email); $sm-ReplyTo($email); my $assignName = $query-param('assName'); #pull in some values from the a/v form my $description = $query-param('description'); #convert newline chars to br so it displays nice on webpage my $eol = chr(13).chr(10); #CR/LF if($description =~ m/$eol/){ $description=~s/$eol/br \//g; } my $commissioner = $query-param('commissioners'); if ($commissioner eq Other) {$commissioner = $query-param('otherComish');} my $acctExec = $query-param('AcctExec'); my $ddlMonth = $query-param('ddlMonth'); my $ddlDay = $query-param('ddlDay'); my $ddlYear = $query-param('ddlYear'); my $ddlDeadline = $ddlMonth. .$ddlDay., .$ddlYear; my $aeMonth = $query-param('aeMonth'); my $aeDay = $query-param('aeDay'); my $aeYear = $query-param('aeYear'); my $aeDeadline = $aeMonth. .$aeDay., .$aeYear; my $ihMonth = $query-param('ihMonth'); my $ihDay = $query-param('ihDay'); my $ihYear = $query-param('ihYear'); my $ihDeadline = $ihMonth. .$ihDay., .$ihYear; my $dimensions = $query-param('dim'); my $pageCount = $query-param('PageCount'); my $quantity = $query-param('Quantity'); my $sides = $query-param('sides'); my $colorSpecs = $query-param('colorSpec'); my $dicut = $query-param('Dicut'); my $binding = $query-param('BindingSelect'); my $art = $query-param('artSelect'); my $laminate = $query-param('LaminSelect'); my $paper = $query-param('Paper'); my $otherPaper = $query-param('otherPaper'); if($paper eq Other) {$paper = $otherPaper;} my $envelopes = $query-param('Envelopes'); my $special = ; $special = $query-param('special'); if($special =~ m/$eol/){ $special=~s/$eol/br \//g; } my $artist = $query-param('artFrom'); my $newGuy = $query-param('otherName'); my @people = $query-param('per'); my $seeList =; my $person =;; foreach $person(@people){ if($person eq otherPer){ $seeList .= $newGuy; }else{ $seeList .= $person., ; } } my ($year,$month, $day, $hour, $min, $sec, $doy, $dst); ($year, $month, $day, $hour, $min, $sec, $doy, $dst) = System_Clock(); my $date = $month./.$day./.$year; my $time = $hour.:.$min.:.$sec; #check to make sure fields are filled in properly unless($email){ print $query-header; print Please fill in the Email field and try again; die No email entered; } unless($assignName){ print $query-header; print Please fill in the Assignment Name field and try again; die No name entered; } unless($description){ print $query-header; print Please fill in the description field and try again; die No description entered; } unless($acctExec){ print $query-header; print Please fill in a value for the Account Executive and try again; die No account executive entered; } unless($dimensions){ print $query-header; print Please fill in values for the dimensions of the project and try again; die No dimensions entered; } unless($dicut){ print $query-header; print you forgot to choose a value for Dicut. Please return to form and choose yes or no; die No dicut entered; } unless($pageCount){ print $query-header; print you forgot to specify the Page Count. Please return to form and try again; die No page Count entered; } unless($quantity){ print $query-header; print you forgot to specify the quantity. Please return to form try again; die No quantity entered; } unless($sides){ print $query-header; print you forgot to specify the number of sides. Please return to form try again; die No quantity entered; } unless($paper){ print $query-header; print you
Re: HTTP_REFERER
Shao-Ju, Yes, but it does not exist when there was no referer. So, for example, if somebody just went strait to test.pl, it would not have a referer, but if somebody went to test.html which had a link to test.pl, then you would have a referer which would be the url of test.html Regards, David - Original Message - From: Shao-Ju Chao [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 24, 2002 7:37 AM Subject: HTTP_REFERER I was trying to get referer information from $ENV{'HTTP_REFERER'} but always got empty string. Is this env variable supported by apache server (on linux)? Thanks. = Shao-Ju Chao (Bruce) Do you Survey!? Go to http://www.surveyanywhere.com and create your own survey. __ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com -- 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: HTTP_REFERER
Well, there you have it Shao-Ju. Hey, I learned something new today. Cool. - Original Message - From: Bob Showalter [EMAIL PROTECTED] To: 'Shao-Ju Chao' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, July 24, 2002 7:56 AM Subject: RE: HTTP_REFERER -Original Message- From: Shao-Ju Chao [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 24, 2002 9:49 AM To: [EMAIL PROTECTED] Subject: Re: HTTP_REFERER Thanks. I was setting up some Paypal stuff and want to make sure that the user is actually coming from Paypal (https://www.paypal.com.) and then come to my web page to ativate their account. The return link is on Paypal and when they click the link and return, I checked the HTTP_REFERER and expect it to be https://www.paypal.com...; but it wasn't. Per RFC 2616, clients are not supposed to send a Referer header in a non-secure request when the referring page used a secure transfer (https). -- 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: Web tools
Samuel, Well, you could hop on cpan.org and find yourself a module that will do the ping for you, or you could use a less proper method like the following: - # pretend you got $ipaddress through CGI.pm or something like that print Content-Type: text/html\n\n; my $result = `ping -c 1 $ipaddress`; if ($result =~ /1 packets? received/){ # ping successful print Ping Successful, Result:\nbr . $result; } else { # ping failed print Ping Failed, Result:\nbr . $result; } - Regards, David - Original Message - From: Samuel Yip [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, July 23, 2002 7:01 AM Subject: Web tools Hi, I am new to perl and would like to use perl to do the following: 1. Prompt the user for a IP address. 2. Ping the IP address from the web server and 3. Print out the result to the user on the browser. Anyone knows how should I do it ? Thks -- 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: Buffer output?
Teddy, $|=1; is supposed to perl to print to standard out right away instead of buffer information. You see, by default Perl buffers what it is going to print out until the buffer is full, then prints. For some reason, when I use $|=1; It seems that the first output to STDOUT is buffered, but once it prints the initial buffered part, everything after that is printed immediately. Regards, David - Original Message - From: Octavian Rasnita [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, July 22, 2002 1:40 AM Subject: Buffer output? Hi all, I've seen the following line in more Perl scripts and even in some Perl books, but it wasn't very well explained. $|=1; ## Don't buffer output What does it mean to buffer output? Which is the difference if the $| is 0 or 1? Thank you. Teddy Center: http://teddy.fcc.ro/ 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: regex - problem
Alex, Did you get the problem fixed? Yes it was because you did not escape your . when you wanted a . instead of an any character. ..[a-zA-Z]{2,3} will match .abc, but it will also match abcd but \.[a-zA-Z]{2,3} will require that the first character this part of the regular expression matches is a period, not an any character. Regards, David - Original Message - From: alex [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, July 19, 2002 10:16 AM Subject: regex - problem Hi, I have this unsignificant problem: I try to match an email-adress... works, EXCEPT the very last .com or .de ... it matches .com and .de but not .d nor .x - ok so far. but it also matches .dererere - which it shouldn't. I used the {2,3} but it seems, that the max-count is being ignored. any ideas? thanks in advance if (@ARGV != 1){ print ONE PARAMETER ONLY!!!\n } else { if ($ARGV[0] =~ /^([_a-zA-Z0-9-]+)(.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+)(.[a-zA-Z0-9-]+).[a-zA-Z]{2,3}$/){ @a = split /@/,$ARGV[0]; print user: $a[0]\ndomain: $a[1]\n; print MATCH\n; }else{ print MISMATCH\n; } } -- cheers alex mailto:[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: formate text sequence
Konrad, Is this what your looking for? -- my $input = 'ABCDEFGHI'; my $output = $input; $output =~ s/(\w{3})/\p\$1\\/p\/g; print qq^\$input = $input\n^; print qq^\$output = $output\n^; -- To make it 40 characters instead of 3, simply change the 3 to a 40 in the {}'s Out put from this is -- $input = ABCDEFGHI $output = pABC/ppDEF/ppGHI/p -- Regards, David - Original Message - From: Konrad Foerstner [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 9:43 AM Subject: formate text sequence hi, does anyone know a function or a module which i can use to format a text which i get in a string. i would like to get lines of 40 letters out of the string which are surrounded by p and /p; the result should be stored in an string. short example with 3-letter-lines: $input = 'ABCDEFGHI'; --- $output = 'pABC/ppDEF/ppGHI/p' cu konrad -- 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: Couple of newbie questions
Kerr, Apache spawns a child for each web connection, while doing this, if a cgi script is called, it pulls a copy of the script into memory, executes it. Ways to debug: Yes Apache does have an error log, search your httpd.conf for ErrorLog. That like specifies where Apache will write any errors including errors returned from perl. If you use tail -f /var/logs/error_log (of course replace that with where your error log is), you will be able to watch the log incase any errors pop up. This is very very useful while developing. Other methods tricks are print STDERR \$var = $var\n; This way you can get the values of certain variables when ever they are in question. If you want it to be easier to see and your script is not live, you could even simply print your values to STDOUT (print uses this by default so simply print stuff would do this). Keep in mind, if you have not printed a content-type before attempting to print some debug to the browser client, you will get an Internal Server Error. If you are getting an Internal Server Error and you know that you are printing a valid content-type, this means there are probably other errors in your script (usually syntax). Watch the error log for these. Good Luck, David - Original Message - From: Kerr Wall [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, July 16, 2002 10:53 AM Subject: Couple of newbie questions Hi All, I am currently switching to Perl/CGI from the Java servlet world. I'm wishing I would have made this switch a long time ago and I have a couple of questions: How does perl handle multiple requests. For example, if 10 users are logged into your system and they are all trying to use the same script, how does perl deal with this situation? What is the best way to test and debug? I am use to printing to the console with Java and I'm not sure how I do this with perl. Does apache have a log file that I can write to and how to I keep track of when I want to print the response or print to stdout/log file? Thanks, Kerr Wall -- 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: Counting the time with fractions of a second. The solution!
Teddy, Because times is a perl function, not necessarily a var. Here's what one of my perl books has to say about it: --- The times function returns the amount of job time consumed by this program and any child processes of this program. The syntax for the times function is @timelist = times As you can see, times accepts no arguments. It returns a list consisting of the following four floating-point numbers: - The user time consumed by this program - The system time consumed by this program - The user time consumed by the child processes, if they exist - The system time consumed by the child processes, if they exist --- So there you have it. When you are calling $begin = (times)[0]; You are calling times function and specifying that you only want to get back the first element of the returned array, which happens to be the user time consumed. Regards, David - Original Message - From: Octavian Rasnita [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, July 13, 2002 11:27 AM Subject: Counting the time with fractions of a second. The solution! Hi all, I found the easiest solution (until now) for calculating how much time a script runs. Thank you for other solutions, but they are too complicated. Here is the code you should use for calculating the time a script runs: my $start = (times)[0]; #Here goes the script. my $end = (times)[0]; my $duration = $end - $start; print The script ran for $duration seconds; This will print the duration in fractions of a second like 1.012, etc. This method doesn't require any module. I've used a more simple method a few months ago, but I don't remember it. I don't understand why (times)[0], but it works. I've tried putting $times[0] and if I use it only for finding the start time, it works, but if I use it for the start and the end time, it doesn't work. Can you make some light? Thank you very much. Teddy Center: http://teddy.fcc.ro/ 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: Why Premature end of script headers?
Probably your web server is timing out the request and killing your script. Web servers don't like to run long-running processes like this. Perhaps you can fork off a child and have the child take care of it. Another solution is to have something like the following in your loop: -- local $|=1; # print things right away (no buffering) # $ltime and $ctime should be defined before the loop $ctime = time(); if ($ltime ne $ctime){ print . ; $ltime = $ctime; } -- Then the browser does not time out because it continually gets information, so it simply prints another period to the browser every one second that it is working. This can help you know its still working. Regards, David - Original Message - From: Bob Showalter [EMAIL PROTECTED] To: 'Octavian Rasnita' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, July 15, 2002 9:28 AM Subject: RE: Why Premature end of script headers? -Original Message- From: Octavian Rasnita [mailto:[EMAIL PROTECTED]] Sent: Monday, July 15, 2002 8:18 AM To: [EMAIL PROTECTED] Subject: Why Premature end of script headers? Hi all, I've made a little script that takes the lines from a file, removes the dupplicate lines and prints the result to a new file. I've read the original file line by line because it is a big file (over 7 MB). The problem is that after printing almost 10% from the original file into the new file, the script dies and the only error I get in the log file is: [Mon Jul 15 14:44:48 2002] [error] [client 127.0.0.1] Premature end of script headers: clean.pl I've checked the original file to see if there are some strange characters in that line, or in the next one, but I haven't found something that might cause that problem. Please tell me why is the script dying only after it runs for a few minutes, and after writing over 11000 lines, and not from the beginning, if there is a problem with the script. Can you find any problems with my scriptt? Probably your web server is timing out the request and killing your script. Web servers don't like to run long-running processes like this. Perhaps you can fork off a child and have the child take care of it. See http://www.stonehenge.com/merlyn/WebTechniques/col20.html for a nice technique on this. -- 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: Why Premature end of script headers?
Yes, your right. It seems to me there has got to be a more efficient way to accomplish what is being attempted. Right now, the solution is making a copy of the file, then checking every line of the original against every line of the copy. This method becomes exponentially more processor intensive for additional lines to the file. Perhaps a recognize would be to loop through the lines, give them a line number, and write them to a copy. Then sort the copy alphanumerically, then loop through the copy checking one line against the next, and if the next is a duplicate, through it away, and continue checking it against the next until they are not the same. As soon as their not the same, take the line that is not the same and begin checking it against the next line. So on and so forth. Because every like line will be right next to each other, you don't have to check each line against every other line, just the ones next to it. After your done eliminating the duplicates, sort the file again by line number (this only if its necessary to keep them in a certain order), and your done. Granted this method requires that you find some efficient manner of sorting the lines in large text files, but if somebody knows of something that can do this, viola. Regards, David - Original Message - From: Bob Showalter [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, July 15, 2002 12:00 PM Subject: RE: Why Premature end of script headers? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Monday, July 15, 2002 12:23 PM To: 'Octavian Rasnita'; [EMAIL PROTECTED] Subject: Re: Why Premature end of script headers? Probably your web server is timing out the request and killing your script. Web servers don't like to run long-running processes like this. Perhaps you can fork off a child and have the child take care of it. Another solution is to have something like the following in your loop: -- local $|=1; # print things right away (no buffering) # $ltime and $ctime should be defined before the loop $ctime = time(); if ($ltime ne $ctime){ print . ; $ltime = $ctime; } -- Then the browser does not time out because it continually gets information, so it simply prints another period to the browser every one second that it is working. This can help you know its still working. True. But there are two possible downsides to consider: 1. It ties up a server process for an extended period. 2. The server will kill the CGI script if the client goes away or the connection is lost. -- 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: Executing cgi from perl script
Shane, Um, first of all, you probably shouldn't be modifying your cgi script dynamically, Lots of room for error. What you should be doing instead is perhaps updating a text file that the cgi script will open and use as its Insert content here content. Next, how is the template.cgi being called? Is it an include in an html page or something? Are you opening it with another cgi script? More information is needed to help you finish resolving this problem. Regards, David - Original Message - From: McElwee, Shane [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, July 11, 2002 4:40 PM Subject: Executing cgi from perl script Hi, I want to execute a cgi script from a perl script that first updates the cgi script. The basic code I'm using to open and update the file is: print Content-type: text/html\n\n; open RESULT, template.cgi; while (RESULT) { s/Insert content here/$output/g; print; } close RESULT; The cgi file calls the header and footer for the application. When I run it like this I get a web page with cgi code in the header and footer and the correct content. How do I execute the cgi file after updating it? I'm on the right track? Thanks Shane -- 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: What is this string type? How to play with?
Oops, let me make one small revision to my code: if (exists($form_vars{$name})) { # if this is the first of this form input name. should be if (!exists($form_vars{$name})) { # if this is the first of this form input name. Sorry about that all. Regards, David - Original Message - From: [EMAIL PROTECTED] To: Connie Chan [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, July 11, 2002 11:53 AM Subject: Re: What is this string type? How to play with? Connie, ; has no problem, why you would like to escape( \ )it ? I know that = and ; don't have a problem, I escape them because I escape every special character, that way I don't have to worry about what I do and don't need to escape. I know, bad habit (old habits die hard). Besides, if you 'next' it if that $variable is not a name=value pair, so is that mean this var will throw away ? This is a safety net incase somebody types in the url with something like this: http://www.domain.com/test.cgi?namea=valueanamebnamec=valuec You don't try to split on = when there's not an = in there. Trust me, I've put a lot of thought into this code over the last 2 1/2 years. I don't particularly care for CGI.pm either (but we wont go into that), I wrote my own called Form.pm which I hope to get up on CPAN one of these days. It handles both GET and POST as well as command line parameters (Along with post [MIME], I also accept files). It also works on Linux and Windows. Its also much faster than CGI.pm because its strait to the point, the only thing its intended to do is retrieve data and give it in a useable format. Hmmm... what is this purpose ? $name is probably going to be a var's name, how come it goes with a blank ? and with an assumption that the $name is coming as a URI escaped string ? Well that's exactly what we are doing, unescaping a URI, we just happen to split it into name and value before unescaping it (this is important incase somebody has a %26 in their name or value). Just hard to imagine how come a request coming with same name. Aren't we supposing the later come value with same name will overwrite the first one ? How about this instance: http://www.domain.com/test.cgi?name=joeprefscheckbox=YesEmailMeprefscheckbox=YesPhoneMeprefscheck box=YesSnailMailMe This is a scenario when you want all of the multiple values with the same name, so you need to put it into an array instead of a scalar. I knew right from when you mentioned $ENV{'QUERY_STRING'} That you were intending to write a form input parser. Well if you are only going to use get, consider the following: my @variables = split(/[\\;]/, $ENV{'QUERY_STRING'}); my %form_vars; foreach $variable (@variables) { next if ($variable !~ /\=/); my ($name, $value) = split(/\=/, $variable); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg; if ($value ne ){ # remove this if statement if you want to keep pairs where the name has an empty value if (exists($form_vars{$name})) { # if this is the first of this form input name. $form_vars{$name} = $value; # setting the variable the hash with the name to the value } else { # for repeated times in with the same form input name $form_vars{$name} = [($form_vars{$name})] if (ref($form_vars{$name} ne ARRAY)); # make this an array if this its not one yet push(@{$form_vars{$name}}, $value); # adding the next element to the list } } } This essentially gives you a hash with name value pairs for every single value names, and an array ref for every name that has multiple values. Basically, it gives you anything that was sent (optionally even name empty value sets assuming you remove the if statement around the assignment block). Eventually when I get it on CPAN, it will be a simple as use Form; my %input = Form(); Anyway, good luck, David - Original Message - From: Connie Chan [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, July 11, 2002 10:59 AM Subject: Re: What is this string type? How to play with? Hi David, Hehe... Thanks in advice. Anyway what I am looking for is making those stuff back to what they looks like when they come, that is, the $input in your script... However, may I have some questions about your sample ? =) my @variables = split(/[\\;]/, $input); ; has no problem, why you would like to escape( \ )it ? next if ($variable !~ /\=/); = also no problem , why you would like to escape it too ? Besides, if you 'next' it if that $variable is not a name=value pair, so is that mean this var will throw away ? $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;
Re: What is this string type? How to play with?
Sorry, one more oops $form_vars{$name} = [($form_vars{$name})] if (ref($form_vars{$name} ne ARRAY)); should be $form_vars{$name} = [($form_vars{$name})] if (ref($form_vars{$name}) ne ARRAY); Sorry about these, there were a few recommendations I've received, and I had not implemented them in my original copy before writing this post. So I decided to implement the recommendations before I sent it on to you guys. couple of typo's. That should be all of them though. Regards, David - Original Message - From: [EMAIL PROTECTED] To: Connie Chan [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, July 11, 2002 11:53 AM Subject: Re: What is this string type? How to play with? Connie, ; has no problem, why you would like to escape( \ )it ? I know that = and ; don't have a problem, I escape them because I escape every special character, that way I don't have to worry about what I do and don't need to escape. I know, bad habit (old habits die hard). Besides, if you 'next' it if that $variable is not a name=value pair, so is that mean this var will throw away ? This is a safety net incase somebody types in the url with something like this: http://www.domain.com/test.cgi?namea=valueanamebnamec=valuec You don't try to split on = when there's not an = in there. Trust me, I've put a lot of thought into this code over the last 2 1/2 years. I don't particularly care for CGI.pm either (but we wont go into that), I wrote my own called Form.pm which I hope to get up on CPAN one of these days. It handles both GET and POST as well as command line parameters (Along with post [MIME], I also accept files). It also works on Linux and Windows. Its also much faster than CGI.pm because its strait to the point, the only thing its intended to do is retrieve data and give it in a useable format. Hmmm... what is this purpose ? $name is probably going to be a var's name, how come it goes with a blank ? and with an assumption that the $name is coming as a URI escaped string ? Well that's exactly what we are doing, unescaping a URI, we just happen to split it into name and value before unescaping it (this is important incase somebody has a %26 in their name or value). Just hard to imagine how come a request coming with same name. Aren't we supposing the later come value with same name will overwrite the first one ? How about this instance: http://www.domain.com/test.cgi?name=joeprefscheckbox=YesEmailMeprefscheckbox=YesPhoneMeprefscheck box=YesSnailMailMe This is a scenario when you want all of the multiple values with the same name, so you need to put it into an array instead of a scalar. I knew right from when you mentioned $ENV{'QUERY_STRING'} That you were intending to write a form input parser. Well if you are only going to use get, consider the following: my @variables = split(/[\\;]/, $ENV{'QUERY_STRING'}); my %form_vars; foreach $variable (@variables) { next if ($variable !~ /\=/); my ($name, $value) = split(/\=/, $variable); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg; if ($value ne ){ # remove this if statement if you want to keep pairs where the name has an empty value if (exists($form_vars{$name})) { # if this is the first of this form input name. $form_vars{$name} = $value; # setting the variable the hash with the name to the value } else { # for repeated times in with the same form input name $form_vars{$name} = [($form_vars{$name})] if (ref($form_vars{$name} ne ARRAY)); # make this an array if this its not one yet push(@{$form_vars{$name}}, $value); # adding the next element to the list } } } This essentially gives you a hash with name value pairs for every single value names, and an array ref for every name that has multiple values. Basically, it gives you anything that was sent (optionally even name empty value sets assuming you remove the if statement around the assignment block). Eventually when I get it on CPAN, it will be a simple as use Form; my %input = Form(); Anyway, good luck, David - Original Message - From: Connie Chan [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, July 11, 2002 10:59 AM Subject: Re: What is this string type? How to play with? Hi David, Hehe... Thanks in advice. Anyway what I am looking for is making those stuff back to what they looks like when they come, that is, the $input in your script... However, may I have some questions about your sample ? =) my @variables = split(/[\\;]/, $input); ; has no problem, why you would like to escape( \ )it ? next if ($variable !~ /\=/); = also no problem , why you would
Re: Username Password Question
When you have everything working, and something for security (htaccess), try redirecting by, NOT printing a content-type (text/html or whatever), then print this: print Location: http://www.domain.com/path/morepath/file.html\n\n;; The capitalization and space are very important. Regards, David - Original Message - From: zentara [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, July 04, 2002 8:10 AM Subject: Re: Username Password Question On Wed, 3 Jul 2002 08:30:35 -0700, [EMAIL PROTECTED] (Rhen Hernandez) wrote: hi everyone! I created a password and username for my website. My question is how can i direct the user to the homepage or main page of the website. Right now, the code is set for Permission Granted... I want to direct the user to the main page of the website after he/she is successful completed the form. Maybe I'm wrong here, I'm just quickly reading the code, but I don't think this approach gives you any REAL password protection. If you do the password check as you describe in your code, then redirect to a unprotected page, such as http://mygoodpassword.html what is to stop someone from bypassing your login page and entering the destination page directly in thier browser? You need to either .htaccess protect your destination page, which makes your logon form a waste of time, or you need to output your html from the cgi-script that does the password checking. -- 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.pm
Curtis, Thank you for the compliment. Please do inform me of what should be modified. Thanks, David - Original Message - From: Ovid [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Tuesday, July 02, 2002 6:18 PM Subject: Re: Form.pm --- Todd Wade [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: sub parse_form_input($){ my $input = shift; I told you already. my @variables = split(/\/, $input); this is wrong!!! Todd W. Yes, it's wrong, but we should say that with a smile on our face :) I've glanced through the code and I see a few things that warrant attention. I'll comment later when I have a bit more time. I do have to say, though, that despite some obvious issues, this is some of the nicest hand-rolled CGI parsing code that I have seen. Cheers, Curtis Ovid Poe = Ovid on http://www.perlmonks.org/ Someone asked me how to count to 10 in Perl: push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//; shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A __ Do You Yahoo!? Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com -- 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: Including External Pages
The reason I explained how to slurp the file into a variable was so that it could be printed anytime anywhere. My solution does not force the file contents to be printed right away. This is also useful for if you wish to replace something in the faq before printing it, or adding some to the top and bottom. In short, it gives the programmer much more control before simply printing the file. Regards, David - Original Message - From: Todd Wade [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, July 02, 2002 6:19 PM Subject: Re: Including External Pages [EMAIL PROTECTED] wrote: open(FH, /usr/www/domain/faq.txt); # for read, for write, for append local $/ = undef; # slurp mode (allow for shoving the whole file into a scalar) my $faq = FH; # slurp the whole file into this scalar. close(FH); open(FH, $file) or die(open $file: $!); print(FILE); # print() takes a list. DWIM in action. close(FH) or die(close $file: $!); Todd W. -- 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.pm
Janek, Yes, I could have shorter lines at the cost of the number of lines. Personally, I like taking things like this: -- if ($thisvar eq $thatvar and $thatvar eq $anothervar){ print all three were the same\n; } -- And making them this: -- print all three were the same\n if ($thisvar eq $thatvar and $thatvar eq $anothervar); -- It just seems to me that a lesser number of lines the interpreter has to trudge through, the better. I guess for me, multiple lines are more of a burden than long lines. There are a few small blurbs of code in Form.pm that are exact copies, but the two sections of code only have about 5 lines that are exactly the same which are intertwined with others that are not. I actually spent a few hours looking this up and down attempting to discover if I could eliminate additional code by putting it in another sub. I at length came to the conclusion of what I currently have. David - Original Message - From: Janek Schleicher [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 03, 2002 11:46 AM Subject: Re: Form.pm perl-dvd wrote at Wed, 03 Jul 2002 19:22:49 +0200: Yes, my lines of code are long. For this I apologize. I work on 1600x1200 with Homesite which doesn't wrap lines unless I ask it to. You know, if you have the same circumstances as I do, it sure makes for easy reading (less vertical lines, and all same command on the same line and so on). I think nearly nobody still works with computers having problems to show more than 80 characters in a row. I also think Ovid won't really have such a problem. But I could imagine he has similar reasons like me to avoid long lines of code. Nowadays we print newspapers with very big dimensions. Why do we still use columns ?? Because we can better read it that way. And readability is the mose important part of a computer program. Even without the aspect of readability long lines of code are an alert signal. It's like having a description of something with long and difficult sentences. From a teacher's view it's a sign that the pupil still doesn't understand the problem correctly. And even if he/she does, the next reader won't. There's nearly always a possibility to reduce the line length. (The design is improved by it, too). The trick is like in real language. Split complex statements (like complex sentences) in a sequence of simpler ones. Reduce also doubled code (Remember: Copying Code is a real crime :-) ) Greetings, Janek PS: One year ago, I took a bet with my colleagues. I said, every ugly code could be rewritten in a normal way with sub sensfull sub routines in 80 columns, 50 rows (was Java in Perl I would said 25). Also I could imagine there is such one, it helped us all to fight against the evil :-) -- 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.pm
I did not say that you said this. I did say that was the tone (or feeling created based on what was said). I knew you had mentioned the ; vs thing before. But at that time, I still did not have a solutions to replace it with. I understand the frustration of telling somebody something, then being ignored, but when I suggest something should be done differently to somebody, I always present a solution, that way they don't feel like I'm just telling them they cant or shouldn't do it. The frustrating issue was, I felt you were pouncing on my ambition without any interest in helping. The suggestion you gave me in this email why not use the solution that was already given in message: [EMAIL PROTECTED]">news:[EMAIL PROTECTED] I would be happy to take a look at, but I am uncertain how to access this archive. I remove the emails I get from mailing lists each day, and don't have past records other than emails I have sent. Perhaps you could reply with the proper solution, or give me a url where I could see an example. Thanks, David - Original Message - From: Todd Wade [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 03, 2002 4:35 PM Subject: Re: Form.pm [EMAIL PROTECTED] wrote in message 00d301c222b6$440166d0$d381f6cc@david">news:00d301c222b6$440166d0$d381f6cc@david... I appreciate your feedback. The reason I was frustrated with Todd is because it was strictly criticism. Basically the tone was Your wrong, and you shouldn't be making your own lib anyway. you are putting words in my mouth I didnt say you were wrong, I said the code was wrong. Also, Im sure I have never debated wether or not someone should make their own library. in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED] I mentioned the spec says '' and ';' are legal for seperating name value pairs. I was reminding you that I already mentioned it. my @variables = split(/\/, $input); First, we know that the split is incorrect. A semi-colon is the new, preferred delimiter for form data, beginning with the HTML 4.0 specification. Any suggestions on how to do this? Should I check to see if there are 's and if not attempt to split on ;'s? why not use the solution that was already given in message: [EMAIL PROTECTED]">news:[EMAIL PROTECTED] Todd W. -- 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: Including External Pages
Of course, and usually that's the way I do it. Basically, if you put the local statement in a block, then the scope of the change to the system variable is only effective inside of the block. Just like if you did this: -- { my $cool = stuff; print qq^\$cool is still in scope and equals $cool\n^; } print qq^\$cool is no longer in scope so it is undefined, but if you tried to print it, you would get $cool\n^; -- The difference is that my makes a new lexical variable, where local will make a copy of a current variable which is already in scope for use inside the block (including system vars and globals). David - Original Message - From: Todd Wade [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 03, 2002 5:27 PM Subject: Re: Including External Pages [EMAIL PROTECTED] wrote in message 008801c222a5$a7c3cb10$d381f6cc@david">news:008801c222a5$a7c3cb10$d381f6cc@david... The reason I explained how to slurp the file into a variable was so that it could be printed anytime anywhere. My solution does not force the file contents to be printed right away. This is also useful for if you wish to replace something in the faq before printing it, or adding some to the top and bottom. In short, it gives the programmer much more control before simply printing the file. Regards, David You really didnt need to explain yourself in relpy to my post. Here is a snip from the op's original post: Kyle Babich [EMAIL PROTECTED] wrote in message 000501c2207c$f543f3e0$be683b41@oemcomputer">news:000501c2207c$f543f3e0$be683b41@oemcomputer... What would I use to include external pages in my script? (like if I wanted to print the contents of faq.txt or log.cgi in my script) I was providing the op with an alternative way to get identical results. Sometimes your solution is better, for the reason that you stated, so that the info could be filtered. Sometimes the code I provided is better, for example the file is very large and it is best to avoid loading the data in to memory. Sometimes there are other solutions that are better for other reasons. The point I was trying to make was how print() takes a list of data and not just a simple scalar, a key concept for new perl programmers to understand. It probably took me months to understand it. It had nothing to do at all with your solution. But since your solution involves turning on slurp mode I do suggest explaining what that means, and what side effects it could have to the rest of the code. For instance, if your example is used, and later on in the program in the same scope I say: while (OTHER_FH) { # oops! It is probably going to confuse someone. Again, someone is back in the newsgroup trying to get help tracking down a very difficult-to-track bug. Probably every example in the docs that show modification of $/ in action have the corresponding code wrapped in a block, i.e. { local $/ = undef(); $_ = FH }. Quick quiz: can anyone explain why? Todd W. - Original Message - From: Todd Wade [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, July 02, 2002 6:19 PM Subject: Re: Including External Pages [EMAIL PROTECTED] wrote: open(FH, /usr/www/domain/faq.txt); # for read, for write, for append local $/ = undef; # slurp mode (allow for shoving the whole file into a scalar) my $faq = FH; # slurp the whole file into this scalar. close(FH); open(FH, $file) or die(open $file: $!); print(FILE); # print() takes a list. DWIM in action. close(FH) or die(close $file: $!); Todd W. -- 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.pm
Duh, I should have thought of that one. So the only time this would be an issue is if somebody not knowing that ; can be a element delimiter creates an href with a ; in the name or value. Ok, that solution works for me. Thanks, David - Original Message - From: Ovid [EMAIL PROTECTED] To: [EMAIL PROTECTED]; Todd Wade [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, July 03, 2002 2:38 PM Subject: Re: Form.pm --- [EMAIL PROTECTED] wrote: I would be happy to take a look at, but I am uncertain how to access this archive. I remove the emails I get from mailing lists each day, and don't have past records other than emails I have sent. Perhaps you could reply with the proper solution, or give me a url where I could see an example. split(/[;]/,$tosplit); Cheers, Curtis Ovid Poe = Ovid on http://www.perlmonks.org/ Someone asked me how to count to 10 in Perl: push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//; shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A __ Do You Yahoo!? Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com -- 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: winlinux
You of course have to pay for the full registration, but you can download the demo and try it out from here: http://labf.com/download/winaxe.html Regards. David - Original Message - From: [EMAIL PROTECTED] To: Martin Pestun [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, July 02, 2002 6:57 AM Subject: Re: winlinux i have only had a quick look on google but it seems that you have to buy winlinux on CD. the only downloads i could find were for addons. there appear to be many places to get a 'hacked' version but i won't endorse that (guilty conscience?). -- 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: Printing the Content-type
Look up the wget package for Linux. or you can try the combination of these: HTTP::Request; LWP::UserAgent; Regards, David - Original Message - From: Octavian Rasnita [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, June 28, 2002 6:25 AM Subject: Printing the Content-type Hi all, I try to make a script for downloading files and I use the following line: print Location:$path\n\n; Is it possible to write the Content-type in this line to make the browser to download the file I want instead of printing it into the browser? I want to tell that the file is a zip file or something like that. Thank you. Teddy Center: http://teddy.fcc.ro/ 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: Help! which are the correct parameters?
my $stuff = qq^ here is some stuff and more stuff to boot stuff for me and stuff for you ^; $stuff =~ s/stuff/money/gs; # g says match all occurrences # s says treat $stuff as a single line Regards, David - Original Message - From: Octavian Rasnita [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, June 28, 2002 9:57 AM Subject: Help! which are the correct parameters? Hi all, I want to use regular expressions to match all the links from a web page. I am fighting for a long time but with no results. I don't know what modifiers I need to use for matching all the links even though some of them use multiple lines. I want to also match a link like: a href=http://www.server.com/dir/file.shtml title=Test link This is a test only /a Without the /m modifyer, my regexp matches only the first link that is on a single line. With the /m modifyer, the regexp matches all the links that don't span on multiple lines. But the links that span on multiple lines can't be matched. I've tried the following regexp: $link =~ s/(a href=.*)/a href=http\:\/\/MyServer\.com\/cgi-bin\/script\.pl\?page=$1/mgi; Thank you for any idea. Teddy Center: http://teddy.fcc.ro/ 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: Including External Pages
open(FH, /usr/www/domain/faq.txt); # for read, for write, for append local $/ = undef; # slurp mode (allow for shoving the whole file into a scalar) my $faq = FH; # slurp the whole file into this scalar. close(FH); - Original Message - From: Kyle Babich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, June 30, 2002 3:27 PM Subject: Including External Pages What would I use to include external pages in my script? (like if I wanted to print the contents of faq.txt or log.cgi in my script) Is there a way to do the above except to include a php script instead of a txt file and have both the cgi and php function correctly? Thank you, Kyle -- 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 v/s roll-your-own [WAS:] Displaying Problems
Curtis, Thanks for the reminder, I'll get it up shortly after I get home from work. About 5:00pm Mountain Time. David - Original Message - From: Ovid [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, July 01, 2002 11:39 AM Subject: Re: CGI.pm v/s roll-your-own [WAS:] Displaying Problems --- [EMAIL PROTECTED] wrote: Curtis, You make some good points. I will be leaving in about 10 minutes for a vacation, and wont be back until Monday, so if you wouldn't mind sending an email to the list Monday as a reminder, I will submit the code then. Thanks, David David, Just a reminder regarding posting your alternative to CGI.pm (and thanks to niko for reminding me to remind you :) Cheers, Curtis Ovid Poe = Ovid on http://www.perlmonks.org/ Someone asked me how to count to 10 in Perl: push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//; shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Form.pm
Well, I'm a little bit behind schedule because the home page for Form.pm just got erased (long story). Anyway, I just setup a backup system on my server now so I'll have a weeks worth of daily backup's (ya, I know I should have had this before). But attached are the main functions of Form.pm there are three functions I left out. One is Form,another is read_net_input and the last one is write_file. By the way, do I have any reason to believe that somebody may run off with my code and claim it as their own? I was about to just include a link to the home page for Form.pm in this email, but now that its gone I'm not going to do that. I'm hoping a buddy of mine has a cached copy. I have yet to implement the file size limitations, file upload limitation, and the getwith post option. Soon, I will get the home page back together (I may have to rebuild it from scratch), then I'll post that, and you can just download the actual lib with all of the functions and the perldoc in it. David sub parse_form_input($){ my $input = shift; my @variables = split(/\/, $input); my (%form_vars, %var_count); foreach $variable (@variables) { next if ($variable !~ /\=/); my ($name, $value) = split(/\=/, $variable); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg; if ($value ne ){ if (!defined $form_vars{$name}) { # if this is the first of this form input name. $var_count{$name} = 0; # set the count of the array to 0 incase there is more than one $form_vars{$name} = $value; # seting the variable the hash with the name to the value } else { # for repeated times in with the same form input name $form_vars{$name} = [($form_vars{$name})] if ($var_count{$name} == 0); # set the first element to the first input if this is only the second input with this name $var_count{$name}++; # increase the count of the array for this form input name push(@{$form_vars{$name}}, $value); # adding the next element to the list } } } return(\%form_vars); } sub parse_mform_input($) { my $input = shift; my (%form_vars, @name_file, @list, %var_count); if( $ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/ ) { $boundary = '--'.$1; # Using MIME to split out the form elements. @list = split(/$boundary/, $input); # split out each form variable into @list # this is going to eliminate the first and last element of @list if they are not valid. my $trash = shift(@list) if ($list[0] !~ / name=/); # Through the first element away if it is not a valid element $trash = pop(@list) if ($list[$#list] !~ / name=/); # Through the last element away if it is not a valid element # parsing data whether it be files or just a form. my $file_count = 0; foreach $listitem (@list){ my %form_file; # if it is a file if ($listitem =~ / name=\(.*)\; filename=\(.*?)\[\r\n]{2}/){ # if the data has a filename in it then $form_file{'name'} = $1; # the contents of the () in the regular expresion. $form_file{'file_name'} = $2; # the contents of the () in the regular expresion. next if ($form_file{'file_name'} eq ); $listitem =~ /\r\n\r\n|\n\n/; # running an expression to seperate out the content $form_file{'file_content'} = $'; # rear part $form_file{'file_name'} =~ s/.+\\([^\\]+)$|.+\/([^\/]+)$/$1/; # strip out the directory $form_file{'file_content'} =~ s/[\r\n]{2}$//; # the last \r\n was put in by Netscape $form_file{'file_name'} =~ s/[^a-zA-Z0-9\-_.]//g; # strip out all charicters except - _ . and alpha numaric charicters $form_file{'file_name'} =~ s/\.\.+/\./g; # replace 2 or more periods in a row. if (length($form_file{'file_name'}) 250){ # if the length of the file name is longer than 250 charicters my $extention = substr($form_file{'file_name'}, 0, 10); # get the extention (take into account it may be longer than 3 or for charicters) $form_file{'file_name'} = (substr($form_file{'file_name'}, 0, 240)) . $extention; # cut the file name down } if ($form_file{'file_name'} ne ) { # if the file name is not empty now if (length($form_file{'file_content'}) 0){ # if the file is larger than 0 bytes # creating a garanteed unique file name $form_file{'ip_addition'} = $ENV{'REMOTE_ADDR'}- if ($ENV{'REMOTE_ADDR'}); $form_file{'random_number1'} = rand(100); # srand is set at the
Re: CGI.pm v/s roll-your-own [WAS:] Displaying Problems
The difference is, the efficiency and data structure CGI.pm returns. Mine came to I think 72 times faster when not uploading images, and 2.5 times faster when uploading images. I'm not saying CGI.pm is written poorly or anything, I am saying that it is a little bit bloated and has a lot of functionality that is not needed (especially if the only thing you are doing with it is receiving input). Well personally, I've always used print Content-type:text/html\n\n; but somebody told me this was not the spec, so I read through the spec and looked up how CGI.pm was doing it and what I found was ${CRLF}${CRLF} as the \n\n replacement. I of coarse should have looked a little higher where they defined $CRLF, or at least tested what I had read before posting it, but oh well. From here on out, I'll stick with what I've known to work instead. Like I've said before, it doesn't make much sense to make a wrapper for CGI.pm so that I can have things the way I want them, because this is doubling the work necessary. I'm not making my lib to prove superior, or to say anything like mine is better. I have simply found a very positive solution for me (quick and in a structure that works well for me). If others like my solution, and it works well for them too, more power to them. I will post mine on CPAN, if nobody else in the world feels it is a good solution for them, that's just fine with me. If people like my solution, but have a few suggestions of how to improve it, I welcome that. One thing I am open to after posting my lib to CPAN is suggestions. I'm not exactly close minded here, I'm just the type of person who if I'm not perfectly happy with the way something works (whether programming or in the real world), I determine whether I can fix it, if I can I do. Because this lib puts the received values in a structure that I like to work with, in my mind it fixes things. David - Original Message - From: Todd Wade [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 26, 2002 11:12 PM Subject: CGI.pm v/s roll-your-own [WAS:] Displaying Problems [EMAIL PROTECTED] wrote in message 008d01c21c73$aa978a30$d381f6cc@david">news:008d01c21c73$aa978a30$d381f6cc@david... .. snip I'm sure I'll get lots of hate mail from CGI.pm die hard's, but my other choice is to just not Not trying to post hate mail, just reasoning on the subject. post this at all. What I hope for is several people telling me how to make it slightly more efficient or compatible with other OS's (you see I've only had opportunity to test it on Linux and Win2000, though I've been testing it on Linux for about 2 1/2 years). Lincoln Stein (the original author of CGI.pm) already has (lots of) people doing this for him, and his module has been maintained for around 10 years. Its been tested on scores of OS's. Ive read four of his books. There is a book dedicated to CGI.pm. My point is his module has been rigorously debugged and you are just now here asking people for help debugging yours. Its pretty hard to make it more simple than: use Form; my %input = Form(); But something else has already made it that easy. Im not knocking your module. Im just explaining why people like us trust people like Lincoln Stein's module over yours. For example, Ive seen alot of hand rolled CGI parameter parsers, most of them have a line that says: @pairs = split(//, $ENV{QUERY_STRING}); # WRONG!! This works when the user agent uses an as a delimeter, but some user agents use ; (a semicolon) which is perfectly valid. program chokes. Then people are in the newsgroups trying to get others to help track down a very, VERY difficult-to-track bug. But at the end of the post they say, I dont want to use CGI.pm! Floors me. Really floors me. And this is just one of several examples I've seen. So I know, when I say: print $q-header(); Its going to get it right. BTW, I find the source to CGI.pm very easy to read and makes alot of sence. Ive seen suggestions from you in this thread that are either wrong or wont even work. (What does this do- print Content-type: text/html${CRLF}${CRLF};) Which tells us again Mr. Stein has a thorough understanding of the HTTP protocol, while you stll have a little to learn. Again, this is NOT a flame. I suggest accepting the constructive criticism professionally. Todd W. -- 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: Displaying Problems
You make a very good point fliptop, I did forget the nature of this mailing list. As far as CGI.pm debating, I will step down in this mailing list. David - Original Message - From: fliptop [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: Bob Showalter [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, June 26, 2002 6:24 PM Subject: Re: Displaying Problems On Tue, 25 Jun 2002, [EMAIL PROTECTED] opined: : CGI.pm--a threat to our way of life! Down with the troglodytes! :) :Well, not exactly my point, but ok :) Just kidding :I just think there are too many who close their minds to anything but CGI.pm, :including potentially :more efficient customized solutions. i would guess that, for the purposes of this mailing list, most who recommend using CGI.pm do so because this list is aimed at beginners, and they most definitely should be using it to parse query strings. other available solutions, and the semantics of using them, probably wouldn't be a good place for a beginner to learn about cgi programming. -- 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 v/s roll-your-own [WAS:] Displaying Problems
my point stands :) So out of curiosity, what kind of data structure do you get back with this? If its as I would imagine, then its very close to my own. %hash = ( 'a_name' = 'value', # for single name value pairs 'b_name' = [multiple, values, for, this], # for single name muli-value sets 'c_name' = { 'original_name' = 'filename.jpg', 'size' = '23554', 'location' = '/tmp/fileupload/tmpfile-10028983-88.57.192.3-2783-298374-927837' } # for files ); Of coarse I know the image information is not in there the same way. David - Original Message - From: Scot Robnett [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: Felix Geerinckx [EMAIL PROTECTED] Sent: Thursday, June 27, 2002 8:29 AM Subject: RE: CGI.pm v/s roll-your-own [WAS:] Displaying Problems Picky, picky. :) You're right, my bad. use CGI; my $q = new CGI; my %params = $q-Vars; SR -Original Message- From: Felix Geerinckx [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 27, 2002 2:16 AM To: [EMAIL PROTECTED] Subject: RE: CGI.pm v/s roll-your-own [WAS:] Displaying Problems on Thu, 27 Jun 2002 02:54:10 GMT, [EMAIL PROTECTED] (Scot Robnett) wrote: Its pretty hard to make it more simple than: use Form; my %input = Form(); Let me try. use CGI; %params = $q-Vars; Try again. Your code throws the following error: Can't call method Vars on an undefined value ... -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.372 / Virus Database: 207 - Release Date: 6/20/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.372 / Virus Database: 207 - Release Date: 6/20/2002 -- 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 v/s roll-your-own [WAS:] Displaying Problems
by the way, :) is a smiley, it means I'm joking with you. (reference the last email) With mine, there is nothing beyond what I described. The hash structure I gave you below, that's it. Form.pm takes the input, makes a hash with it, and if you understand how to use a hash and array ref, your set. Its just a hash, no objects, no functions, just a hash. So you use: use Form.pm my %input = Form(); and your done. All the data is sitting in the hash %input. You can at that point do anything you want to with it. Like I say, simple and efficient. If you decide you want to know what you are getting from the cgi input, simply do something to this effect: --- foreach $key(keys(%input)){ # loop through all of the hash elements if (ref($input{$key}) eq ARRAY){ # if this is an array ref local $ = ', '; # change the array delimiter to , temporarily for display print qq^\@{\$input{$key}} = (@{$input{$key}})\n^; # print out the array's values # (make it easy to see which name in the hash this array belongs to) } else { # if its not an array ref print qq^\$input{$key} = $input{$key}\n^; # print out the hash element } } --- Anyway, you will be able to get a closer look at it within a months time if you so choose. David - Original Message - From: Scot Robnett [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 27, 2002 10:03 AM Subject: RE: CGI.pm v/s roll-your-own [WAS:] Displaying Problems I haven't seen the rest of your module, so I'm not so sure that the point really stands. It might. But, adding one line to initialize the CGI object is really not that big a deal considering the kind of power you have associated with that object. How much extra work do I have to do to utilize the keys and values in your hash vs. the CGI.pm hash? The data structure you get back from CGI.pm is: - Called in a scalar context, a tied hash reference. - Called in a list context, a standard hash containing key/value pairs. - Keys/params with multiple values are returned as a packed string separated by \0. Scot R. inSite -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 27, 2002 10:44 AM To: Scot Robnett; [EMAIL PROTECTED] Cc: Felix Geerinckx Subject: Re: CGI.pm v/s roll-your-own [WAS:] Displaying Problems my point stands :) So out of curiosity, what kind of data structure do you get back with this? If its as I would imagine, then its very close to my own. %hash = ( 'a_name' = 'value', # for single name value pairs 'b_name' = [multiple, values, for, this], # for single name muli-value sets 'c_name' = { 'original_name' = 'filename.jpg', 'size' = '23554', 'location' = '/tmp/fileupload/tmpfile-10028983-88.57.192.3-2783-298374-927837' } # for files ); Of coarse I know the image information is not in there the same way. David - Original Message - From: Scot Robnett [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: Felix Geerinckx [EMAIL PROTECTED] Sent: Thursday, June 27, 2002 8:29 AM Subject: RE: CGI.pm v/s roll-your-own [WAS:] Displaying Problems Picky, picky. :) You're right, my bad. use CGI; my $q = new CGI; my %params = $q-Vars; SR -Original Message- From: Felix Geerinckx [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 27, 2002 2:16 AM To: [EMAIL PROTECTED] Subject: RE: CGI.pm v/s roll-your-own [WAS:] Displaying Problems on Thu, 27 Jun 2002 02:54:10 GMT, [EMAIL PROTECTED] (Scot Robnett) wrote: Its pretty hard to make it more simple than: use Form; my %input = Form(); Let me try. use CGI; %params = $q-Vars; Try again. Your code throws the following error: Can't call method Vars on an undefined value ... -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.372 / Virus Database: 207 - Release Date: 6/20/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.372 / Virus Database: 207 - Release Date: 6/20/2002 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.372 / Virus Database: 207 - Release Date: 6/20/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.372 / Virus Database: 207 - Release Date: 6/20/2002 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To
Re: CGI.pm v/s roll-your-own [WAS:] Displaying Problems
That actually has nothing to do with it. It has everything to do with the strong desire to improve circumstances, be innovative, make the world a better place. If you want to call me arrogant for trying to improve my surroundings, go right ahead, but your tacking the wrong name on me. David - Original Message - From: John Brooking [EMAIL PROTECTED] To: [EMAIL PROTECTED]; Todd Wade [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, June 27, 2002 12:57 PM Subject: Re: CGI.pm v/s roll-your-own [WAS:] Displaying Problems After all, Hubris is one of St. Larry's Three Cardinal Virtues! So this seems to me to be a properly Perl-ish attitude. - John --- [EMAIL PROTECTED] wrote: ... minded here, I'm just the type of person who if I'm not perfectly happy with the way something works (whether programming or in the real world), I determine whether I can fix it, if I can I do. = Now it's over, I'm dead, and I haven't done anything that I want; or, I'm still alive, and there's nothing I want to do. - They Might Be Giants, http://www.tmbg.com __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CGI.pm v/s roll-your-own [WAS:] Displaying Problems
No offence taken, I have heard the word hubris before, but I wasn't certain of the meaning, so naturally I looked it up (now that you mention it, I have heard that quote out of the Camel book before). At first I thought it was a compliment the way you said it and all, but after seeing dictionary.com's definition, I wondered. Well thank you for the compliment. David - Original Message - From: John Brooking [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, June 27, 2002 3:39 PM Subject: Re: CGI.pm v/s roll-your-own [WAS:] Displaying Problems Oh, dear, I was afraid that that message might be misinterpreted! I thought my humor was evident enough by the informal language, but I guess I should have put a smiley on it too. I didn't mean hubris in a bad sense. The sense I get from Larry's use of it (from reading the Camel book), and the sense I meant here, was having enough self-confidence to believe that you *can* do all the things you mention, rather than just putting up with what is handed to you because you're too humble to think that little old you could do better. It might tend towards arrogance in some cases, maybe, especially when unwarranted by the actual talent behind it, but true arrogance connotes more negative personality traits, such as not being open to other points of view or debate, and that's *not* what I meant. I did assume familiarity with Larry's philosophy of Laziness, Impatience, and Hubris as The Basis of All Good Software Design, and maybe I shouldn't have. I'd quote some of this from the Camel book, but I don't have it with me. I would summarize it as good programmers don't like write the same thing over and over, yet if they don't like something they got elsewhere, they'll write something themselves that they like better. I suspect he intentionally chose provocative words to get people's attention, but his claim that they lead to good software design implies that far from being bad traits, he thinks that they are actually good traits, properly applied. I apologize that my message was taken negatively. I meant it positively. I support the spirit of your effort. - John --- [EMAIL PROTECTED] wrote: That actually has nothing to do with it. It has everything to do with the strong desire to improve circumstances, be innovative, make the world a better place. If you want to call me arrogant for trying to improve my surroundings, go right ahead, but your tacking the wrong name on me. David - Original Message - From: John Brooking [EMAIL PROTECTED] To: [EMAIL PROTECTED]; Todd Wade [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, June 27, 2002 12:57 PM Subject: Re: CGI.pm v/s roll-your-own [WAS:] Displaying Problems After all, Hubris is one of St. Larry's Three Cardinal Virtues! So this seems to me to be a properly Perl-ish attitude. - John = Now it's over, I'm dead, and I haven't done anything that I want; or, I'm still alive, and there's nothing I want to do. - They Might Be Giants, http://www.tmbg.com __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Extract numbers from in between parentheses with regex
-- my $var = (801) 555-; # ya, ok so I'm in utah :) $var =~ /(\(\d+\))/; # real paren, escape paren, \d = digits, # + = one or more, escape paren, real paren my $area_code = $1; # set to what came from between the real parens -- but if you are looking to match anything between the parens, you probably want something more like this: -- my $var = some text (my comment) and more text; $var =~ /(\([^\(\)]+\))/; # real paren, escape paren, [^\(\)] = any non ( or ), # + = one or more, escape paren, real paren my $matched_value = $1; # set to what came from between the real parens -- Regards, David - Original Message - From: Kristofer Hoch [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 26, 2002 10:21 AM Subject: Extract numbers from in between parentheses with regex Hi all, Please forgive the simple nature of this question. I have never really used regular expression extensivly. Here goes. I am trying to extract a number from in between two parenthesis. I want the first value I find (from right to left) in a string. These numbers could be phone number area codes, or comments. Could someone please help, so that I can shamelessly use it all over the place? Thank you Kristofer. _ Send and receive Hotmail on your mobile device: http://mobile.msn.com -- 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: Displaying Problems
Kyle, Well, I'd start by printing an actual content type instead of depending on CGI.pm for that: --- print content-type: text/html\n\n; --- Second, I would condense your if to this --- my $c = param('c'); my $content = $c; $content = \n if ($c eq h or $c eq eh or $c eq hd or $c eq p or $c eq c or $c eq su); --- Then I would HIGHLY recommend that you not depend on CGI.pm so heavily. I would suggest you print out your own html, then you can see exactly what it is displaying and know what to change. If you wanted to print it all in one clump, you could do it like this. --- # the qq^ makes it use ^ as the quote. Just make sure if you us a ^ inside that you escape it (like this \^ ) print qq^ html head title$thetitle/title /head body bgcolor=#FF !-- the rest of your html goes in here -- /body /html ^; --- Trust me on this one, it will save you so much headache if you will just print your own html. Regards, David - Original Message - From: Kyle Babich [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, June 24, 2002 2:09 PM Subject: Displaying Problems For the following the syntax is correct but when I try to open it nothing displays, what should I change? #!/usr/bin/perl -wT use strict; use CGI::Pretty qw/ :standard /; $CGI::DISABLE_UPLOADS = 1; $CGI::POST_MAX = 512 * 1024; print header ( text/html ); my $date = localtime; my $c = param('c'); my $content = c; if ($c eq h) { $content = qq{\n}; } elsif ($c eq eh) { $content = qq{\n}; } elsif ($c eq hd) { $content = qq{\n}; } elsif ($c eq p) { $content = qq{\n}; } elsif ($c eq c) { $content = qq{\n}; } elsif ($c eq su) { $content = qq{\n}; } my @nav = (Home,E-Mail Hosting,Help Desk,Policies,Contact,Signup); my @loc = (index.cgi?c=h,index.cgi?c=eh,index.cgi?c=hd,index.cgi? c=p, index.cgi?c=c,index.cgi?c=su); print start_html( -title = IMAP.cc E-Mail Hosting, -head = Link( { -rel = stylesheet, -type = text/css, -href = style.css } ), ), body( -bgcolor = \#FF ), table({ -width = 95\%, -cellspacing = 0, -cellpadding = 0, -border = 1, -bordercolor = \#00}, tbody( Tr( td( {-width = 100\%}, table({ -width = 100\%, -cellspacing = 0, -cellpadding = 1, -border = 1, -bordercolor = \#00 -align = center}, tbody( Tr( td( {-width = 100\%, -bgcolor = \#00, -align = center}, Font({ -face = Verdana, Arial, Times New Roman, -size = 4, -color = \#FF}, IMAP.cc ) ),),),),),),),), end_html -- -- 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: Displaying Problems
Bob, I fail to see how writing code with errors is somehow CGI.pm's fault No its not. But I'll tell you one thing, people who depend so heavily on CGI.pm generally have a good understanding of how to use CGI.pm, but have less understanding of what is really going on. Me personally, I want to know what's really happening. And once I get to that point, not only can I become more efficient, but I can make better decisions for my own application. You see, just like sterio-typing can frequently be incorrect (because it uses blanket statements), CGI.pm is not the most efficient and for that matter appropriate for many situations. Except that that's not RFC2616-compliant, while CGI.pm's output is So what exactly is the RFC2616 compliant content type? You know its funny, but it seems that so many who stick up for CGI.pm so strongly are quick to say that CGI.pm is doing things right and that it does them better, but they seem to purposely avoid giving the actual solution. It seems to me that our way of life (freedom and prosperity) came about from people thinking for them selves and from innovation, learning and continued drive to improve what was given us. I do a little system admin on the side, and I've come to find that learning the actual conf files is such a boon over simply using the GUI app. So much understanding has come and it takes me to a more advanced level. Many times I can discover a problem, or have understanding of the underlying problem when coming across things I don't expect. In my mind programming is the same. I want to know what's going on, so I can make a wise and educated decision of how to approach it. David - Original Message - From: Bob Showalter [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Tuesday, June 25, 2002 8:39 AM Subject: RE: Displaying Problems -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, June 25, 2002 10:26 AM To: Kyle Babich; [EMAIL PROTECTED] Subject: Re: Displaying Problems Kyle, Well, I'd start by printing an actual content type instead of depending on CGI.pm for that: --- print content-type: text/html\n\n; Except that that's not RFC2616-compliant, while CGI.pm's output is. Most browsers will accept this, but you still shouldn't generate it. ... Then I would HIGHLY recommend that you not depend on CGI.pm so heavily. I would suggest you print out your own html, then you can see exactly what it is displaying and know what to change. I fail to see how writing code with errors is somehow CGI.pm's fault. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Displaying Problems
Bob, CGI.pm--a threat to our way of life! Down with the troglodytes! :) Well, not exactly my point, but ok :) Just kidding I just think there are too many who close their minds to anything but CGI.pm, including potentially more efficient customized solutions. David - Original Message - From: Bob Showalter [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Tuesday, June 25, 2002 9:33 AM Subject: RE: Displaying Problems -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, June 25, 2002 11:12 AM To: Bob Showalter; [EMAIL PROTECTED] Subject: Re: Displaying Problems Bob, ... So what exactly is the RFC2616 compliant content type? cf. ftp://ftp.isi.edu/in-notes/rfc2616.txt, section 2.2 You know its funny, but it seems that so many who stick up for CGI.pm so strongly are quick to say that CGI.pm is doing things right and that it does them better, but they seem to purposely avoid giving the actual solution. See above. It seems to me that our way of life (freedom and prosperity) came about from people thinking for them selves and from innovation, learning and continued drive to improve what was given us. I do a little system admin on the side, and I've come to find that learning the actual conf files is such a boon over simply using the GUI app. So much understanding has come and it takes me to a more advanced level. Many times I can discover a problem, or have understanding of the underlying problem when coming across things I don't expect. In my mind programming is the same. I want to know what's going on, so I can make a wise and educated decision of how to approach it. CGI.pm--a threat to our way of life! Down with the troglodytes! :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Displaying Problems
Bob, That's interesting. You know, I work with about 5 other perl programmers, most of which do use CGI.pm, but none of them use it for anything other that gathering input from the web. I have also downloaded many packages from CPAN, I would say a majority of them use CGI.pm, but very rarely do I see it used for anything but gathering data. I'm not suggesting we shouldn't follow the standard. I am suggesting that this particular standard will never be enforced, because if it was, I'd be willing to bet, it would break a great percentage of perl scripts out there. But yes, I agree with you that we should all try to follow the specs pretty closely. Anyway, personally, I don't use CGI.pm at all, and it would be a real shame if I began including the whole thing just for that. It would just seem smarter for me to begin using this print Content-type: text/html${CRLF}${CRLF}; instead. I created a lib for receiving data from GET, POST or shell. I will be releasing it to CPAN soon, and expect to get this sort of thing quite a bit. That is good, because I want my lib to be very efficient and proper. The reason I wrote my own is because I like my variables in a easy to use structure: %hash = ( 'a_name' = 'value', # for single name value pairs 'b_name' = [multiple, values, for, this], # for single name muli-value sets 'c_name' = { 'original_name' = 'filename.jpg', 'size' = '23554', 'location' = '/tmp/fileupload/tmpfile-10028983-88.57.192.3-2783-298374-927837' } # for files ); With this structure, I can get to everything very easily. It didn't make much sense to use CGI.pm to gather the data, smush it into a data structure, only to loop through all the data and shove it into another structure. I'm sure I'll get lots of hate mail from CGI.pm die hard's, but my other choice is to just not post this at all. What I hope for is several people telling me how to make it slightly more efficient or compatible with other OS's (you see I've only had opportunity to test it on Linux and Win2000, though I've been testing it on Linux for about 2 1/2 years). Its pretty hard to make it more simple than: use Form; my %input = Form(); David - Original Message - From: Bob Showalter [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Tuesday, June 25, 2002 11:12 AM Subject: RE: Displaying Problems -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, June 25, 2002 12:47 PM To: Bob Showalter; [EMAIL PROTECTED] Subject: Re: Displaying Problems Ok, so here's the deal: Some HTTP/1.0 software has interpreted a Content-Type header without charset parameter incorrectly to mean recipient should guess. Senders wishing to defeat this behavior MAY include a charset parameter even when the charset is ISO-8859-1 and SHOULD do so when it is known that it will not confuse the recipient. By the way, I did not upper case the MAY and SHOULD, those were that way in the doc which means they were trying to emphasize them. I'd have to say that MAY doesn't suggest that it is a requirement for the content-type to work properly. This is the relevant paragraph from 2.2 that I was going for: HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all protocol elements except the entity-body (see appendix 19.3 for tolerant applications). The end-of-line marker within an entity-body is defined by its associated media type, as described in section 3.7. Appendix 19.3 (Tolerant Applications) says, in part: The line terminator for message-header fields is the sequence CRLF. However, we recommend that applications, when parsing such headers, recognize a single LF as a line terminator and ignore the leading CR. But, section 3.7 says: When in canonical form, media subtypes of the text type use CRLF as the text line break. HTTP relaxes this requirement and allows the transport of text media with plain CR or LF alone representing a line break when it is done consistently for an entire entity-body. HTTP applications MUST accept CRLF, bare CR, and bare LF as being representative of a line break in text media received via HTTP. In addition, if the text is represented in a character set that does not use octets 13 and 10 for CR and LF respectively, as is the case for some multi-byte character sets, HTTP allows the use of whatever octet sequences are defined by that character set to represent the equivalent of CR and LF for line breaks. This flexibility regarding line breaks applies only to text media in the entity-body; a bare CR or LF MUST NOT be substituted for CRLF within any of the HTTP control structures (such as header fields and multipart boundaries). Note especially the last sentence. A nit-pick, to be sure. But little things like this cause programs to break all the time. Like I said, most (maybe
Re: calling sub based on database list?
No, this is quite a simple problem actually. Here's how. my $alias = home|htmlBody,Header,homebody,footer; my ($name, $subs) = split(/\|/, $alias); my @subs = split(/\,/, $subs); foreach $sub(@subs){ my $return_val = {$sub}($pass_in_vars); } So the first part I assume you've got where you pull your strings into vars, but don't put the on the front of them. Then what you are doing with {$sub}($pass_in_vars); is you are taking the string htmlBody or whatever and saying I want to execute a sub called whatever string is in $sub. You use the same method as when you are dereferencing say an array ref. For example my $stuff = [first element, second element, third element]; my @thearray = @{$stuff}; Same technique. Regards, David - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, June 21, 2002 9:58 AM Subject: calling sub based on database list? Ok, I got sorta a hard questionI think that involves calling randomly changing subrutines. What I'm Trying to do is this. 5 libaries are required into my CGI(PERL) program Each of them has their own set of subrutines. Now when someone accesses my site they also send a page referance eg main.cgi?page=home What im trying to get my code to do is take 'home' and then start runing subrutines based on a file entry that can be edited from my admin section of this site. So basicly the file looks like this. home|htmlBody,Header,homebody,footer So it should get the list of subrutined to call but I can not figure out how to call them since they are strings and not hard coded into the code. Basicly I can get the values and print them out but not call them. Does anyone have and tips for calling a sub using the name from a string? perl.call('htmlBody') does not work as one site pointed out. I guess thats for something else all together. Thanx Chris -- 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: return =1
Octavian, Secondly, by your explanation, I'm not sure whether you know this, but your if should be like this: -- my $test = sub_name(); if ($test){ # stuff } -- Or -- if (sub_name()){ # stuff } -- Regards, David - Original Message - From: Shawn [EMAIL PROTECTED] To: Octavian Rasnita [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Sunday, June 23, 2002 9:27 PM Subject: Re: return =1 Hello Octavian, You need to say return(0) or return(1), not return = 0 or 1. Shawn - Original Message - From: Octavian Rasnita [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, June 23, 2002 1:33 AM Subject: return =1 Hi all, If I put at the end of a subroutine a line: return = 0; or return =1; How can I check if the return value is true or false? I've tried with if (subroutine_name) { } But it always give me the true value. Am I missing something, or am I doing something wrong? Thanks. Teddy Center for the blind: http://teddy.fcc.ro/ 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: text problem
Martin, Well, you can use a simple html tag called pre. --- open(FILE, /path/file); local $/ = undef; # slurp mode, pull all data coming in one shot (so it all goes into a scalar) $contents_of_file = FILE; close(FILE); print qq^ pre $contents_of_file /pre ^; --- Is that what you are looking for or do you want to actually split up the data into individual variables? Regards, David - Original Message - From: Martin Pestun [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, June 24, 2002 6:54 AM Subject: text problem Hi everybody I've got text file on the local machine and Apache too. What I don't know is how can I display this file like html file using cgi. The file looks like: USER PID PPID %CPUTIME COMMAND user 26794 26002 0.00:00 user 4687 4685 0.00:00 -ksh user 15120 15118 0.00:00 -ksh user 18918 18821 0.00:00 -ksh user 21894 21885 0.00:00 -ksh user 26719 26716 0.10:00 -ksh user 26795 26719 0.00:00 -ksh I mean that the result of this cgi program is displayed the same like file text. Can you help me? Martin Pestun -- 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: PERL!! : )
You know, I'm a not a Microsoft fan by any means (if you ask people who know me, you would probably get more rash descriptions of how I feel about them). When it comes to using an os as a client, Windows 2000 is pretty nice. But when it comes to running a server, I will avoid windows at all costs. I have two Linux servers, one for my local development, and one for a business I'm starting (linxsatellite.com), and they are beyond awesome. I do have a win2k server that I have to run out of necessity. I've got a Win only chat application for ldschat.com and will soon be hosting the site on that machine too (to cut down on costs since ldschat.com doesn't make money), but I WOULD NEVER TOUCH IIS. Apache 2.0 for win32 is a boon for any who MUST run a Windows machine as a server. If I had my choice of servers, Linux rocks my world. David - Original Message - From: Bill Odom [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, June 20, 2002 2:00 PM Subject: Re: PERL!! : ) JP: While I agree with Brent (hi, Brent), it doesn't have to be an all-or-nothing decision. I've had a lot of success running Perl *with* ASP. In fact, I'm finishing a project right now that - has to run on IIS - has to run under ASP So what is a self-respecting Perl programmer to do? Use PerlScript, ActiveState's extension that allows Perl to run as a full-fledged ASP scripting language. You get all the advantages of ASP, all the power of Perl, and none of the gut-wrenching inadequacy of VBScript or soullessness of JavaScript. I've built very large applications this way. It really works. It's also a great way to introduce Perl to an all-Microsoft shop, demonstrate Perl's power and maintainability, and start to loosen the Microsoft death-grip. --Bill Odom Heh, I probably came off a bit too harsh, Micro$oft really does it all to themselves... - Perl is MUCH more widely used than ASP. - Perl is more maintainable (good management buzzword). I would bet the farm that there are more *GOOD* Perl programmers than ASP programmers. I would bet the ASP has more programmers, but most of them could not program their way out of a wet paper bag. - Perl undoubtably has more modules available than ASP. www.cpan.org - Does your boss *really* want to run IIS? What do you want to patch today? Note: If your boss is strictly set on running IIS, RUN, don't walk to the nearest exit!When (and I said when) it gets hacked, who is going to take the fall??? Brent -- 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
The template replacement I cant give because I wasn't the one who wrote it, but Form.pm is my CGI.pm replacement for receiving data. I wrote it approximately 2 1/2 years ago and have been tweaking and improving it since. I'll release it to C-PAN within the next month I think, look for it there. It will be called Form.pm written by David Hicken. David - Original Message - From: Niko Gunadi [EMAIL PROTECTED] To: Beginners cgi [EMAIL PROTECTED] Sent: Friday, June 21, 2002 3:43 AM Subject: Re: CGI.pm On Thu, Jun 20, 2002 at 10:51:14AM -0500, David T-G wrote: David -- ...and then [EMAIL PROTECTED] said... % % Personally, I don't. My development team and I have created a few tools that we use which are % extremely quick and easy to use. I created a CGI input retrieval lib that works on both Linux and Sounds pretty slick, even if fairly customized. Got a pointer to it for us lookers? Your var and replacement stuff sounds quite interesting. -- 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]