Re: File name problem
At 21:08 07.7.2001 'ã.' +0400, you wrote: Hello from Russia How can I set a name for some file? Here is some code from my script. sub set_cyk3{ my $name=join(,@_); $name=date/$name; my $c_a=val1=$value1,val2=$value2; my $cookie=cookie(-name='something', -value=$c_a, -expires='+30m'); print header(-type=application/octet-steam,-cookie=$cookie); } You should send an additional header info: Content-Disposition: attachment; filename=yourfilename.ext but I don't know how to sent it in CGI header() function. It may be somewhat like this: print header(-type=application/octet-steam, -disposition=attachment; filename=yourfilename.ext, -cookie=$cookie); but not sure. Check in CGI.pm set_cyk3(readme.doc); open(FILE, dirnicecool/readme.doc) || die(Cant open data file); binmode STDOUT;binmode FILE; print FILE; close(FILE); The browser promts to save the file with the name start.cgi(it is the name of the script) but I want it to be readme.doc That is the problem. And what is Content-Disposition ? Excuse my English, it leaves much to be desired. Please reply to my e-mail box. Kamelia _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
Re: Required Fields Module
Jason Purdy wrote: Example Hash: %requiredFields = ( 'upload_file' = 'Document Source', 'doc_url||docfile'= 'Specify either Document URL or Document File', 'capture_date' = 'Capture Date' ); Example Usage: #!/usr/local/bin/perl use CGI; require 'rfields.pl'; $query = new CGI; # let's start by checking the required fields checkRequiredFields($query, %requiredFields); ... Code: sub checkRequiredFields { my ($formHandle, %reqdFields) = @_; my ($incomplete) = 0; my (@incFields) = (); foreach $field (keys %reqdFields) { if ($field =~ /(.*)\|\|(.*)/) { $incomplete = 1 push (@incFields, $reqdFields{$field}) if ( (!$formHandle-param($1) || $formHandle-param($1) eq '') (!$formHandle-param($2) || $formHandle-param($2) eq '') ); } else { $incomplete = 1 push (@incFields, $reqdFields{$field}) if !$formHandle-param($field) || $formHandle-param($field) eq ''; } } if ($incomplete) { print H2Incomplete Form/H2\n; print You missed the required fields:BR\nUL\n; foreach $incField (@incFields) { print LI$incField\n; } print /UL\n; print CENTERIUse your browser's back button try again/I/CENTER\n; exit; # I couldn't just use the die, b/c it wouldn't format the $msg like I wanted } } hi jason after looking at your code, and not typing it in and trying it out, here are some of the problems i see with it: problem: what if a user passes a value of 0 in one of the required fields? let's say one of your required fields is 'number_of_kids'. some people may not have any, and therefore may enter '0'. your code checks to see if a required field is true/false. your code will not accept a value of 0 (it will think it's false, even though it's a valid answer). instead of checking to see if a field is true/false, check to see if it's defined, then check to see if it contains a minimum number of characters. problem: if there is an error, you're not sending the appropriate header command. if you just try to print HTML without calling $query-header, the result will be an internal server error. problem: what if your parameters are multivalued? assume for the moment your cgi is called like this: /cgi-bin/whatever.cgi?name=fliptoplang=perllang=english will your code handle these values the way you want? here are my recommendations: 1) put the parameters you're looking for into a list like this: (key1, value1, key2, value2, key2, value3, ...) 2) create a parameter hash from this list with values being either scalar or references to arrays: %parameters = ( key1 = value1, key2 = [ value2, value3] ); 3) check each key's value(s) (if it's required, ie.- not NULL) to see that they're defined and have a minimum length. if you haven't already seen it, i'd recommend reading the tutorial i'm working on which explains how to do all of these things. it can be found at http://www.peacecomputers.com/addressbook_toot-intro.html.
Re: Required Fields Module
Excellent points - Thanks for pointing them out! I'll check out your tutorial soon (took a quick glance earlier this afternoon and it looks very thorough, and a good read! Thanks! :)). I forgot the print $query-header part of the code. I also updated the code to accept '0' values by grepping within the keywords. I currently don't have to worry about multivalued parameters - I don't design my forms that way. Jason New subroutine: sub checkRequiredFields { my ($formHandle, %reqdFields) = @_; my ($incomplete) = 0; my (@incFields) = (); foreach $field (keys %reqdFields) { if ($field =~ /(.*)\|\|(.*)/) { $incomplete = 1 push (@incFields, $reqdFields{$field}) if ( (!grep(/$1\b/, $formHandle-keywords) || $formHandle-param($1) eq '') (!grep(/$2\b/, $formHandle-keywords) || $formHandle-param($2) eq '') ); } else { $incomplete = 1 push (@incFields, $reqdFields{$field}) if !grep(/$field\b/, $formHandle-keywords) || $formHandle-param($field) eq ''; } } if ($incomplete) { print H2Incomplete Form/H2\n; print You missed the required fields:BR\nUL\n; foreach $incField (@incFields) { print LI$incField\n; } print /UL\n; print CENTERIUse your browser's back button try again/I/CENTER\n; exit; # I couldn't just use the die, b/c it wouldn't format the $msg like I wanted } } - Original Message - From: fliptop [EMAIL PROTECTED] To: Jason Purdy [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Sunday, July 08, 2001 1:38 PM Subject: Re: Required Fields Module [snip] hi jason after looking at your code, and not typing it in and trying it out, here are some of the problems i see with it: problem: what if a user passes a value of 0 in one of the required fields? let's say one of your required fields is 'number_of_kids'. some people may not have any, and therefore may enter '0'. your code checks to see if a required field is true/false. your code will not accept a value of 0 (it will think it's false, even though it's a valid answer). instead of checking to see if a field is true/false, check to see if it's defined, then check to see if it contains a minimum number of characters. problem: if there is an error, you're not sending the appropriate header command. if you just try to print HTML without calling $query-header, the result will be an internal server error. problem: what if your parameters are multivalued? assume for the moment your cgi is called like this: /cgi-bin/whatever.cgi?name=fliptoplang=perllang=english will your code handle these values the way you want? here are my recommendations: 1) put the parameters you're looking for into a list like this: (key1, value1, key2, value2, key2, value3, ...) 2) create a parameter hash from this list with values being either scalar or references to arrays: %parameters = ( key1 = value1, key2 = [ value2, value3] ); 3) check each key's value(s) (if it's required, ie.- not NULL) to see that they're defined and have a minimum length. if you haven't already seen it, i'd recommend reading the tutorial i'm working on which explains how to do all of these things. it can be found at http://www.peacecomputers.com/addressbook_toot-intro.html.
Re: Required Fields Module
Oops - found another little tweak - it should be $formHandle-param instead of $formHandle-keywords (unless your form is using an ISINDEX search). Sorry 'bout that... Jason - Original Message - From: Jason Purdy [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Sunday, July 08, 2001 11:14 PM Subject: Re: Required Fields Module Excellent points - Thanks for pointing them out! I'll check out your tutorial soon (took a quick glance earlier this afternoon and it looks very thorough, and a good read! Thanks! :)). I forgot the print $query-header part of the code. I also updated the code to accept '0' values by grepping within the keywords. I currently don't have to worry about multivalued parameters - I don't design my forms that way. Jason New subroutine: sub checkRequiredFields { my ($formHandle, %reqdFields) = @_; my ($incomplete) = 0; my (@incFields) = (); foreach $field (keys %reqdFields) { if ($field =~ /(.*)\|\|(.*)/) { $incomplete = 1 push (@incFields, $reqdFields{$field}) if ( (!grep(/$1\b/, $formHandle-keywords) || $formHandle-param($1) eq '') (!grep(/$2\b/, $formHandle-keywords) || $formHandle-param($2) eq '') ); } else { $incomplete = 1 push (@incFields, $reqdFields{$field}) if !grep(/$field\b/, $formHandle-keywords) || $formHandle-param($field) eq ''; } } if ($incomplete) { print H2Incomplete Form/H2\n; print You missed the required fields:BR\nUL\n; foreach $incField (@incFields) { print LI$incField\n; } print /UL\n; print CENTERIUse your browser's back button try again/I/CENTER\n; exit; # I couldn't just use the die, b/c it wouldn't format the $msg like I wanted } } - Original Message - From: fliptop [EMAIL PROTECTED] To: Jason Purdy [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Sunday, July 08, 2001 1:38 PM Subject: Re: Required Fields Module [snip] hi jason after looking at your code, and not typing it in and trying it out, here are some of the problems i see with it: problem: what if a user passes a value of 0 in one of the required fields? let's say one of your required fields is 'number_of_kids'. some people may not have any, and therefore may enter '0'. your code checks to see if a required field is true/false. your code will not accept a value of 0 (it will think it's false, even though it's a valid answer). instead of checking to see if a field is true/false, check to see if it's defined, then check to see if it contains a minimum number of characters. problem: if there is an error, you're not sending the appropriate header command. if you just try to print HTML without calling $query-header, the result will be an internal server error. problem: what if your parameters are multivalued? assume for the moment your cgi is called like this: /cgi-bin/whatever.cgi?name=fliptoplang=perllang=english will your code handle these values the way you want? here are my recommendations: 1) put the parameters you're looking for into a list like this: (key1, value1, key2, value2, key2, value3, ...) 2) create a parameter hash from this list with values being either scalar or references to arrays: %parameters = ( key1 = value1, key2 = [ value2, value3] ); 3) check each key's value(s) (if it's required, ie.- not NULL) to see that they're defined and have a minimum length. if you haven't already seen it, i'd recommend reading the tutorial i'm working on which explains how to do all of these things. it can be found at http://www.peacecomputers.com/addressbook_toot-intro.html.
Re: SQL problem...
if you are trying to modify records that already exist you need to use UPDATE instead. insert is for adding new records, in which case the WHERE portion of the statement is not applicable. On Mon, 9 Jul 2001, Daniel Falkenberg wrote: List, Below is my sub where I want to INSERT the following values into a PostgreSQL database that contatins a row that needs some entries updated. Can any one see a problem with the following code? sub complete_final{ my $status = 'COMPLETE'; my $sth = $dbh -prepare( qq{ INSERT INTO vintek_support (date_complete,time_complete,status,administrator,solution) VALUES (?,?,?,?,?) WHERE unique_id = '$search_string1' } ) || die $dbh-errstr; $sth-execute($date_added,$time_added,$status,$admin,$solution); } Regards, df
Re: newbie question
Hi Thank you for your mail. the code is #testcgi.cgi print Content-type: text/html\n\n; print Hello World\n; This is WinCGI. should i have to give the Shebang operator? Should i have Perl installed in the server where the Webserver is configured? If so, how will i give the shebang operator The web server is Iplannet webserver. It would be appreciated if anyone help me to come out of this problem Thank you Regards Nila __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Re: foreach examples/usage
you might find the loops/block tutorial i wrote on www.sharemation.com/~perl/tut helpfull regards, Jos Boumans snip I am trying to learn the foreach loop. Is there a place on the web where there are examples for the foreach? Basically I have an array of X elements and I want to go from the first element (is it zero?) to the last. I have a variable containing the number of elements in the array. If the array has 22 elements does it go from 0 to 21 or 1 to 22? /snip
Re: Module to Parse MIME-encoded Email?
- Original Message - From: Mike Miller [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, July 07, 2001 6:08 PM Subject: Module to Parse MIME-encoded Email? Gurus: As a learning exercise I'm writing my own web-based POP3 client, and wish to be able to handle emails which are MIME-encoded. So I'm looking for perhaps a module which will take the full message, give me back headers I want, and parse the body and return it in a form that could be dumped straight to the browser. (At the very least, a module to which I could feed the MIME-encoded body would be nice, as I can parse the headers myself). Try Mime::Parser. That might do what you want. I think it can handle both Base64 and UUencoded messages (beware that outlook express has some different way in adding padding characters and things). Maarten.
Re: foreach examples/usage
link works.. but it's on a free server (sharemation) so sometimes the server is down... i should have my own up shortly, at japh.nu... just have to fiddle with the dns entry... =) Jos - Original Message - From: mcrawley [EMAIL PROTECTED] To: Evan Panagiotopoulos [EMAIL PROTECTED]; [EMAIL PROTECTED]; Jos I. Boumans [EMAIL PROTECTED] Sent: Sunday, July 08, 2001 4:39 PM Subject: Re: foreach examples/usage Sounds interesting. Please verify this link. -- Original Message -- From: Jos I. Boumans [EMAIL PROTECTED] Date: Sun, 8 Jul 2001 11:19:21 +0200 you might find the loops/block tutorial i wrote on www.sharemation.com/~perl/tut helpfull regards, Jos Boumans snip I am trying to learn the foreach loop. Is there a place on the web where there are examples for the foreach? Basically I have an array of X elements and I want to go from the first element (is it zero?) to the last. I have a variable containing the number of elements in the array. If the array has 22 elements does it go from 0 to 21 or 1 to 22? /snip -- Michael L. Crawley, CIO Business Strategy, E-Technology Specialist Jenai Communications P.O. Box 33 Wheeling, Illionis 60090 (847) 745 - 0940 http://www.jenaipower.net mailto:[EMAIL PROTECTED] --
Re: Executing Remote Script with parameters
I would investigate using rsh or (peferably) ssh to execute the remote script. if you had an account on machine 'foo', you can use RSA or DSA authentication to avoid needing a password to execute a script on foo, but this isn't an SSH group, so if you need more info, email me. there's also a Net::SSH module, if I'm not mistaken. On Sun, 8 Jul 2001, Suresh Babu.A [Support] wrote: Ladies and Gentlemen, I am executing a script from the client, which should internally call a script of a remote server and i have to pass argument from the client. Any help regarding this is much appreticated. Thank you very much for your time. SureshA [EMAIL PROTECTED]
Re: How to make a resource intensive script less intensive.
you might want to look at swatch, by Todd Atkins, to see how it is done there ... http://www.oit.ucsb.edu/~eta/swatch/ There is a File::Tail module which might work for you as well, or, at least show you another way to do it. -s- At 2:20 PM -0400 7/8/01, Jim Conner wrote: I am writing a script that is quite cool imo once I get it done. But already I am seeing that it takes a ton of system resources. Simply put, the script watches a log file (like tail -f) and then reacts to certain things that occur. I am thinking that the loop that it is in might be taking up all the resources but that doesn't quite jive with my knowledge of how this kind of thing works. Here is a snippet of the resource usage from top(3): Swap: 34236K av, 7268K used, 26968K free 35756K cached PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND 8400 qadmin17 0 3560 3560 1404 R 0 98.8 5.6 0:28 perl Here is a snippet of the part of the code that does the tail -f: if ( !chdir($qlogdir) ) { print Cannot read $qlogdir: $!\n; return(undef); } else { my $curpos; dmsg( __LINE__, Reading at end of Quake logfile: $qlogfile\n); open(QLOG,$qlogfile) or die(Unable to open $qlogfile: $!\n); while ( QLOG ) { $curpos++; } dmsg( __LINE__, Cursor Pos: $curpos\n); # Following tail -f code provided by http://www.PerlMonks.org # Monk unknown. for ( ; ; ) { my $vip = 0; # vote in progress my $input; my $timestart; # Leave this here # until I know I dont # need it. my $timestop; my $player_name; my $reqed_map; my $command; for ( $curpos = tell(QLOG) ; $input = QLOG ; $curpos = tell(QLOG) ) { chomp $input; if ( defined $input ) { dmsg( __LINE__,$input\n); } else { dmsg( __LINE__, basename($qlogfile) . : EMPTY SET!\n); } $_ = $input; ## START OUR SWITCH BLOCK! switch: { ## # This next block for map voting. ## /.*] (.*): \!$keyword_map/ do { $input =~ /] (.*): \!($keyword_map) ([a-zA-Z0-9].*)/; ($player_name, $command, $reqed_map )= ($1,$2,$3); my $current_map = current_map; if ( !defined $reqed_map $player_name ne /[Cc]onsole/ ) { usage(vote_assist); } else { # This is where we decide what kind of vote we are # in. See comments. if ( $vote_type == 0 ) { type_votemap($reqed_map) if ( $current_map eq $vote_map ); } elsif ( $vote_type == 2 ) { # check what map we are in here. # then if we are in votemap, react : # or if we are in regular map, react ( $current_map eq $vote_map ) ? type_votemap ($reqed_map): type_no_votemap($reqed_map); } sub type_votemap($) { my $funcName = (caller(0))[3]; my $reqed_map= shift; print STDERR Now in $funcName\n; # This section will work in votemap ONLY and # players can only vote during this map. map_vote($player_name,0,$reqed_map); } sub type_no_votemap($) { my $funcName = (caller(0))[3]; my $reqed_map= shift; print STDERR Now in $funcName\n; # This section will work in any map and # players can vote anytime during play. # Must use vote session. print STDERR Requested map is: $reqed_map from $funcName\n; $vip= map_vote($player_name,1, $reqed_map ); } } }; last switch; ## END OF SWITCH BLOCK! if ( $vip ) { # Set my timestop (time limit for an active vote)
Re: How to make a resource intensive script less intensive.
On Sun, Jul 08, 2001 at 02:20:40PM -0400, Jim Conner wrote: I am writing a script that is quite cool imo once I get it done. But already I am seeing that it takes a ton of system resources. Simply put, the script watches a log file (like tail -f) and then reacts to certain things that occur. I am thinking that the loop that it is in might be taking up all the resources but that doesn't quite jive with my knowledge of how this kind of thing works. Here is a snippet of the resource usage from top(3): You're using up all those resources because your program is sitting in a hard loop. Try inserting a sleep at the bottom of your outer for loop. You might also want to take a look at How do I do a 'tail -f in perl?' in perlfaq5. Walt
Re: How to make a resource intensive script less intensive.
Ok. So you are thinking it might be the loop then too? TIA - Jim At 11:48 AM 7/8/2001 -0700, Sandor W. Sklar wrote: you might want to look at swatch, by Todd Atkins, to see how it is done there ... http://www.oit.ucsb.edu/~eta/swatch/ There is a File::Tail module which might work for you as well, or, at least show you another way to do it. -s- At 2:20 PM -0400 7/8/01, Jim Conner wrote: I am writing a script that is quite cool imo once I get it done. But already I am seeing that it takes a ton of system resources. Simply put, the script watches a log file (like tail -f) and then reacts to certain things that occur. I am thinking that the loop that it is in might be taking up all the resources but that doesn't quite jive with my knowledge of how this kind of thing works. Here is a snippet of the resource usage from top(3): Swap: 34236K av, 7268K used, 26968K free 35756K cached PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND 8400 qadmin17 0 3560 3560 1404 R 0 98.8 5.6 0:28 perl Here is a snippet of the part of the code that does the tail -f: if ( !chdir($qlogdir) ) { print Cannot read $qlogdir: $!\n; return(undef); } else { my $curpos; dmsg( __LINE__, Reading at end of Quake logfile: $qlogfile\n); open(QLOG,$qlogfile) or die(Unable to open $qlogfile: $!\n); while ( QLOG ) { $curpos++; } dmsg( __LINE__, Cursor Pos: $curpos\n); # Following tail -f code provided by http://www.PerlMonks.org # Monk unknown. for ( ; ; ) { my $vip = 0; # vote in progress my $input; my $timestart; # Leave this here # until I know I dont # need it. my $timestop; my $player_name; my $reqed_map; my $command; for ( $curpos = tell(QLOG) ; $input = QLOG ; $curpos = tell(QLOG) ) { chomp $input; if ( defined $input ) { dmsg( __LINE__,$input\n); } else { dmsg( __LINE__, basename($qlogfile) . : EMPTY SET!\n); } $_ = $input; ## START OUR SWITCH BLOCK! switch: { ## # This next block for map voting. ## /.*] (.*): \!$keyword_map/ do { $input =~ /] (.*): \!($keyword_map) ([a-zA-Z0-9].*)/; ($player_name, $command, $reqed_map )= ($1,$2,$3); my $current_map = current_map; if ( !defined $reqed_map $player_name ne /[Cc]onsole/ ) { usage(vote_assist); } else { # This is where we decide what kind of vote we are # in. See comments. if ( $vote_type == 0 ) { type_votemap($reqed_map) if ( $current_map eq $vote_map ); } elsif ( $vote_type == 2 ) { # check what map we are in here. # then if we are in votemap, react : # or if we are in regular map, react ( $current_map eq $vote_map ) ? type_votemap ($reqed_map): type_no_votemap($reqed_map); } sub type_votemap($) { my $funcName = (caller(0))[3]; my $reqed_map= shift; print STDERR Now in $funcName\n; # This section will work in votemap ONLY and # players can only vote during this map. map_vote($player_name,0,$reqed_map); } sub type_no_votemap($) { my $funcName = (caller(0))[3]; my $reqed_map= shift; print STDERR Now in $funcName\n; # This section will work in any map and # players can vote anytime during play. # Must use vote session. print STDERR Requested map is: $reqed_map from $funcName\n; $vip= map_vote($player_name,1, $reqed_map ); } } }; last switch; ## END OF SWITCH
RADIUS
Is there anything out there to authenticate a user with a perl script from a radius server? Ryan
Re: How to make a resource intensive script less intensive.
Excellent! I will check that out! - Jim At 04:31 PM 7/8/2001 -0400, Walt Mankowski wrote: On Sun, Jul 08, 2001 at 02:20:40PM -0400, Jim Conner wrote: I am writing a script that is quite cool imo once I get it done. But already I am seeing that it takes a ton of system resources. Simply put, the script watches a log file (like tail -f) and then reacts to certain things that occur. I am thinking that the loop that it is in might be taking up all the resources but that doesn't quite jive with my knowledge of how this kind of thing works. Here is a snippet of the resource usage from top(3): You're using up all those resources because your program is sitting in a hard loop. Try inserting a sleep at the bottom of your outer for loop. You might also want to take a look at How do I do a 'tail -f in perl?' in perlfaq5. Walt - Jim -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- http://www.perlmonks.org/index.pl?node_id=67861lastnode_id=67861 -BEGIN PERL GEEK CODE BLOCK- --BEGIN GEEK CODE BLOCK-- Version: 0.01 Version: 3.12 P++*@$c?P6?R+++@$M GIT/CM/J d++(--) s++:++ a- $O!MA-E! PU--+++BDC(+) UB$L$S$ $C-@D!(-)$S@$X?WP+MO!+++ P++(+)+ L+++()+$ !E* +PP+++n-CO?PO!o G W++(+++) N+ o !K w--- PS---(-)@ PE *(!)$A--@$Ee---(-)Ev++uL++*@$uB+ Y PGP t+(+++)+++@ 5- X++ R@ *@$uS+*@$uH+uo+w-@$m! tv+ b? DI-(+++) D+++(++) G() --END PERL GEEK CODE BLOCK-- --END GEEK CODE BLOCK--
Re: foreach examples/usage
Sounds interesting. Please verify this link. -- Original Message -- From: Jos I. Boumans [EMAIL PROTECTED] Date: Sun, 8 Jul 2001 11:19:21 +0200 you might find the loops/block tutorial i wrote on www.sharemation.com/~perl/tut helpfull regards, Jos Boumans snip I am trying to learn the foreach loop. Is there a place on the web where there are examples for the foreach? Basically I have an array of X elements and I want to go from the first element (is it zero?) to the last. I have a variable containing the number of elements in the array. If the array has 22 elements does it go from 0 to 21 or 1 to 22? /snip -- Michael L. Crawley, CIO Business Strategy, E-Technology Specialist Jenai Communications P.O. Box 33 Wheeling, Illionis 60090 (847) 745 - 0940 http://www.jenaipower.net mailto:[EMAIL PROTECTED] --