RE: running interactively
Adriano Allora wrote: ha to all, Ha back! I need to use a a shell-program but I cannot pass all the arguments to this program via system() function. In other words: the program doesn't accept all the arguments via command line: I need to open it and write interactively some instructions. If you just need to feed input via stdin, you can to a pipe open: open F, |/path/to/some_program or die $!; print F command\n; ... close F or die $!; If the program expects to work with a terminal (tty), you can use the Expect module to set up a pseudo-tty (pty) and interact with the program that way. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: XML [AntiVir checked]
Naji, Khalid wrote: Hi, Which Module could you recommend for the use of the XML (XML::Simple, XML::Parser and XML::Writer, XML::DOM, XML::PATH...) ? To add to what Wiggins said, I would also take a look at the XML::LibXML family of modules, and look at SAX parsing. These are newer than some of the modules you listed. Also, be sure to go to http://perl-xml.sourceforge.net/ and read the FAQ there. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Forcing a save as' dialogue box to come up on left click
Tony Frasketi wrote: Hello Listers I'm trying to find a way to force a download dialogue box to come up when the user clicks on a link on a web page (the link will primarily be for htm, .txt files on the server). Short answer is that you cannot *force* the client to do anything. The HTTP standard addresses this in sec. 19.5.1 of RFC 2616, so you should read that over. Unfortunately, not all clients follow the standard here. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: cookies as hidden files
Denzil Kruse wrote: Well, this is what I witnessed. I'm using a windows computer at home. It is configured to display hidden files. I have a red hat linux server off who knows where that hosts my site. I set up a perl script to set and fetch cookies, and it does so correctly on my computer. But, I went over to a friend's windows computer, and when it tried to bring up the site, the browser(IE) hung. Part of the web site is a flash presentation with music, but the flash was hanging as well, and there was no music. Whatever problem this is, it isn't a Perl problem. Your CGI script neither reads nor writes files on the client PC; the browser handles all that. Sounds like your friend's browser is broken? Or perhaps he has cookies disabled, in which case any cookies sent by your script are simply discarded and you won't see them come back. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Yet another package problem
Luinrandir wrote: ### Inn.pl # ## package Inn; Buy {} Sell {} Talk {} Sleep {} Delivery {} Work { # GameTime(.1); # SendOff(); print qq|Well afraid I do all my own work Try another business|; } ... Did you forget sub keywords on each of these? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Perl DBI / SQL Question
Vance M. Allen wrote: I need to know how to retrieve through Perl DBI a listing of possible ENUM elements from a field for processing under a CGI script. Need to know what database you're talking about. This will probably involve querying data dictionary views or tables. Some DBI drivers also have specific methods for this kind of thing. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Force a file download for link
Denzil Kruse wrote: Hi, I want my users to download a csv file. When they left click on the link, it brings the file up within the browswer. They can of course do a right click and Save Target As depending on the browser. But I don't want to fuss with instructions and confused users. I would just like the same thing to happen as a Save Target As on a left click. Very difficult to force the browser to do anything. The best you can do is suggest. The most foolproof way is to use Content-Type: application/octet-stream (cf RFC 2616, sec. 7.2.1). But that seems distasteful to me. Why lie about the content type just because users are morons? Anyway... Content-disposition is not part of the HTTP standard, so you'll get inconsistent results. Also, IE can think it's smarter than you are and inspect the URL for file extensions instead of respecting your Content-Type header. Ain't life fun? So I made something up, but it isn't working. I get an internal server error from the browser. When I run it at a command prompt, it seems to work fine. Here is the code: print content-type: multipart/mixed\n; print content-disposition: attachment; filename=SampleListingUpload.csv\n; open (FILE, $ABS_PATH/httpdocs/SampleListingUpload.csv) or die Unable to load the sample listing template. Reason: $!; my $text = join , FILE; close FILE; print $text; And here is the output from a prompt: -bash-2.05b$ ./sample_listing.cgi content-type: multipart/mixed content-disposition: attachment; filename=SampleListingUpload.csv Keywords,Bid Amount,Title,Url,Description home mortgage,0.10,ABC Home Mortage,http://www.ABCHomeMortgage.com,Instant Quotes tax attorney,0.75,ACME Tax Attorneys,http://www.acmetaxattorneys.com,Let us represent you -bash-2.05b$ multipart/mixed is incorrect. text/csv is the proper MIME type for your response. Also, your MIME header lines techincally need to end with \r\n, and you must have emit blank line after the header. This is why we always recommend using the CGI module. It gets this stuff right. use CGI qw(:standard); open FILE, ...blah blah... print header('application/octet-stream'); print while FILE; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Easy question
Neville Hodder wrote: The following code creates two Input types - a file select and a text input. The text input data is returned as expected whilst the file select data is ignored. I have not found any references for a CGI file select form tag in my documentation so I guess it is not a recognised tag. It is a recognised tag. See http://www.w3.org/TR/html4/interact/forms.html#file-select How can I achieve a returned selected filename within a simple CGI script? Your form encoding type must be multipart/form-data I recommend you use the CGI module. Look in the document under the section 'CREATING A FILE UPLOAD FIELD'. There are several things you need to do to get file uploading working. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: quote problem and mysql
Andrew Kennard wrote: Hi all Done lots of googling but this simple thing still has me stumped The perl code to insert stuff into an mysql table is this my $Vals; for ( my $i=1;$i=32;$i++ ) { $Vals.='?,'; } Hmm, that seems like it would give you an extra comma at the end. BTW, you could shorten that loop to: $Vals .= '?,' for 1..32; I would use something like this to get placeholders for each value in @TheRecord: my $Vals = join ',', ('?') x @TheRecord; (obviously that would need to go after the line that populates @TheRecord). chop $Vals; Oh, I see where the extra comma is being removed. Clunky code, use my cool stuff instead :~) my @TheRecord=GenMainRecData(); my $sth = $dbh-prepare(INSERT INTO mytable VALUES($Vals)); $sth-execute(@TheRecord); This works fine until I have single quores (') in the data eg O'Connor etc The data saved in the field ends up being OConnor I've tried putting \\\' in the string but this gives me O\Connor What you're doing should be working. The execute method should properly quote your parameters. You might try setting DBI-trace(2) prior to the call to execute() to get some debugging output. Maybe that will help to pinpoint the problem. I've also tried foreach $fld (@TheRecord){ push (@Processed,$dbh-quote($fld)); } No, you shouldn't have to do that. Your first approach is correct, so we need to find out what's going wrong there... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: CGI.pm internals question
Scott R. Godin wrote: [snip] So if I were to say, override it thusly: package CGI; sub STORE { my $self = shift; my $tag = shift; my $vals = shift; #my @vals = index($vals,\0)!=-1 ? split(\0,$vals) : $vals; my @vals = @{$vals}; $self-param(-name=$tag,-value=[EMAIL PROTECTED]); } It wouldn't affect the webserver's ability to insert params from the query, correct? If I understand the question correctly, the answer is no, this method has no effect on parsing the query parameters. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: CGI.pm internals question
Scott R. Godin wrote: under what circumstances is the CGI.pm's STORE autoloaded method called? is it used only when you assign values to the object, or is it only used when receiving values (or multi-values) from the webserver query? It is part of the tied hash interface returned by the $q-Vars method. It is only invoked if you assign parameters through the tied hash. All it does is call $q-param to assign the parameter value. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: A scope question
Andrew Kennard wrote: Hi all I've got the basic hang of scope of vars in Perl which is a bit different to other languages I've used. Having split a large program into packages I would like to use a global var across multiple packages. Perl does not seem to have a 'C' type 'extern' command to say a var is declared in another package. Perhaps it does not need one ? Would I be correct in thinking that the %DataFromHTMLPage in the following example would always be pointing to the same bit of memory across the packages ? Yes, because you've used the Export module, which works in conjunction with use to provide sharing of global variables. All package (aka global, or symbol table) variables have a fully-qualified name, of the format PackageName::SymbolName. So the full name of your hash is: %myglob::DataFromHTMLPage You can unambiguously reference that hash from any package by using its fully qualified name. If you leave off the package name and just write %DataFromHTMLPage, then the *current* package is used. Because of the 3 lines beginning with require Exporter, when you use myglob from another package, Exporter creates an alias to the variable back in package myglob. So, if you have the following: package Foo; use strict; use myglob; print keys %DataFromHTMLPage; The last line is referencing the hash %Foo::DataFromHTMLPage. However, because of the Exporter stuff within myglob.pm, %Foo::DataFromHTMLPage is actually an alias to %myglob::DataFromHTMLPage. So the two packages are now sharing the same hash. myglob.pm package myglob; use strict; use CGI::Carp qw(fatalsToBrowser); requireExporter; our @ISA = qw(Exporter); our @EXPORT = qw(%DataFromHTMLPage); our %DataFromHTMLPage; - myscript.pl use strict; use CGI::Carp qw(fatalsToBrowser); use myglob; use mypkg1; use mypkg2; # load data into %DataFromHTMLPage and do stuff with it -- mypkg1.pm package mypkg1; use strict; use CGI::Carp qw(fatalsToBrowser); use myglob; #Do stuff here with %DataFromHTMLPage using functions etc - mypkg2.pm package mypkg2; use strict; use CGI::Carp qw(fatalsToBrowser); use myglob; #Do stuff here with %DataFromHTMLPage using functions etc If I don't use myglob in the package files then strict causes an error to say that %DataFromHTMLPage is undefined. Yes, because variables imported (via Exporter) get a free pass from use strict. My main question is if you define a var with 'our' if there is a 2nd/3rd occurance of the definition of it what happens ? Nothing really. our is just a declaration that says let me use this variable name without the full package qualifier from here to the end of the enclosing block or file. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Active Perl Script to delete 4 hours old files on Windows
Asad wrote: All: I need to write a script to delete 4 hours old files and directories on Windows. I am planning to use Perl to accomplish this. I understand the -M would delete at least a day old files, but is there a way to delete 4 hours old files and directories. Thank you. The -M operator returns a floating point value, so you can compute 4 hours as: $hours = (-M $somefile) * 24; if ($hours 4) { ...file is more than 4 hours old } You need to be careful using -M in a daemon because the age is base on the script start time and not the current time. If that's a concern, you can make -M use current time by doing this: $hours = do { local $^T = time; (-M $somefile) * 24 }; or you can use stat() insteamd of -M like this: $hours = (time - (stat $somefile)[9]) / 3600; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: How to output in HTML?
Roger Grosswiler wrote: Hi, i just wrote a very small perl-file, which opens a file, reads the content, adds a 1 and closes it. It's a veery simple hitcounter. (counter.pl, code see below) I would like now to print this in an existing html-sheet, say, when opening index.html, this program should be executed and the content of my counter-file (counter.cnt) should be printed in a visitors browser. Index.html is already existing. Can you please help me? Generally, you would do this using a technique called Server Side Includes. If you're using Apache, you can find a good explanation at: http://httpd.apache.org/docs/howto/ssi.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: cgi form generates a cronjob
FRANK DELATORRE wrote: Hello, I hope this is the right forum to ask this question: Is it possible to generate a crontab file from a perl driven CGI script? If so, what are the key steps? I've been thinking about how to develop this but for some reason I cannot rectify, in my head, how to edit a crontab file as www when www is not really a user in the /home dir... Typically you would use the crontab(1) program to submit a new crontab. If you need to get the current crontab first, use crontab -l. Obviously you can't use crontab -e from a script. So, # read current crontab my @lines = `crontab -l`; ... change @lines as necessary ... # submit updated crontab open F, |crontab or die $!; print F @lines; close F; HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: removing dupes from fetchrow_array()?
Sara wrote: Following is the code used in my CGI script. my $query = $dbh - prepare(SELECT * FROM invoices WHERE ID = '$ID'); $query - execute(); while (my @row = $query - fetchrow_array()){ print $row[1] - $row[2] - $row[3]br; } What If I want to remove dupes from @row? like if $row[2] is similar in multiple records, only one entry should be showed, the duplicates should not appear in the print. Like Chris said, typically you want to use SELECT DISTINT or GROUP BY in your query. The rule of thumb is to avoid sending unecessary data from the server to the client. But the general Perl construct I would use to filter dups is something like: my %found; while (...more data...) { $key = ...some expression... next if $found{$key}++; ...process the data for the first occurence... } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Premature end of script headers
vishwas bhakit wrote: hello, I am getting following error. Premature end of script headers Can anybody plz tell me what is the cause of this. When the webserver runs your CGI script, it parses the output, looking for the MIME headers, followed by a blank line, followed by the response body. It will then add some headers of its own and send the complete response back to the client. This error occurs when your script terminates before the end of the headers is seen. Either your script isn't outputting headers correctly, or it's dying for some reason before the headers have been fully output. Here's a more detailed treatment: http://www.htmlhelp.org/faq/cgifaq.4.html#3 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Addendum: Content_Length.
Sara wrote: Why the length is not coming out? Any ideas? # my @aho = (fgfgfgf, fgfgfgfgf, fgfgfgfg); my $length += length($_) for @aho; A perl gotcha. The 'for' modifier creates a loop, and the 'my' is scoped to the body of that loop (I think; I may not be exactly correct here). You need to write it like this: my $length; $length += length($_) for @aho; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: embedding dynamic images in html output
Chad Gard wrote: and I really don't want to write images to files on disk. I think you should reconsider. This is really your best bet. Web clients and servers are really optimized for this kind of thing. You should write all the images out to disk files accessible through URL's and then emit IMG tags with those URL's. The server will keep the connection open so the client can pull down the data. You do have to manage cleaning up the leftover disk files after some period of time. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Browser times out
Denzil Kruse wrote: Hi all, I think I'm having a problem with my browser timing out because my cgi script is taking too long. The script processes some database records. When it does 250 of them, it takes about a minute or so, and the browser has no problem. But when I do more, the script takes about 2 or 3 minutes, and the browser gets an incomplete response. It's probably the server timing out and not the browser. Is there a way to tell the browser to hang around a bit longer to wait for a response? Or is there another way to keep the browser's attention so it knows it has a live connection and to wait? One way is to have the CGI script output some data periodically. For a more sophisticated approach, see http://www.stonehenge.com/merlyn/WebTechniques/col20.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Setting a Cookie...
Bill Stephenson wrote: How can I set a cookie when someone visits my home page? I've tried using a server side include like so # code # #!/usr/bin/perl -w # This is in my html page: # !--#exec cgi=/cgi-bin/ezInvoice2/ssi.cgi-- [snip cgi ] Your code to set the cookie is OK, but I don't think you can do this from SSI; only the body of the response is used, not the headers (where the cookie is set). Googling for set cookie from ssi turns up lots of discussion of this topic. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: How to avoid accidental re-sending of POST data
Ingo Weiss wrote: Hi, this must be a common problem and I was wondering what commonly used strategies to solve it are: How can I avoid that a user re-sends a POST form when hitting the reload button on a result page? You can't. If the transaction is not repeatable, you need to have some way on the server side to detect that the transaction has been previously submitted and reject it on subsequent submissions. Assigning a unique transaction ID number to each transaction is one way of doing it. The browser typically warns you when you want to do that but I was wondering whether there is an easy way to make it impossible. Nope. You have to deal with it on the server side. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Killing a Process
Kevin Bass wrote: I have a slight problem that I am attemping to solve. I am using CGI/Perl (DBD Oracle) on Linux AS 2.1 to access to the database. When users encounter problems on the web, they cancel (or press stop) in their browsers. This will stop there browser interaction and also cause the database connection to not disconnect which causes a runaway process. Is there an article that I can read or a procedure/module or process that someone has written within CGI or DBI (or sometimes else) that will allow me to kill my database connection when a users stops an execute within his/her browser? Thanks! When the user presses the Stop button on their browser, the only thing that happens is the connection back to the server is closed. The only way for your script to detect this is to try to send data back to the client. If the connection is closed, you'll receive SIGPIPE (which by default will terminate your process). You can catch the SIGPIPE and do a graceful shutdown on the db connection. If you're in the middle of a query, you won't be able to detect the connection being closed until the DBI call returns. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: question about doing it right in CGI
Lewick, Taylor wrote: Hi all, I have been using perl for sometime for CGI scripts, but have always used the print content-type:html version of doing things. I would like to learn a better way with the CGI module, but when I read the docs I find it pretty easy to get confused as to whether I should use the object oriented method, or the functional method. Either is fine IMO. The function method requires you to import the correct symbols, which can be a bit tricky. Also, because my script is a cgi form that gets some of the select fields from a mysql database, I am not sure how to convert that over. I don't know how I would make the select field work the same. I am not asking for someone to rewrite my project, merely provide me with some examples of how they would write the same code using the cgi module so I can figure this out a bit better... On my form, I am querying a database for a list of names and loading them into a select box. But I found out people want to enter more than one name at a time, so I loop through 15 times, and they can select up to 15 names... They select a name, but I store the name's id, so it acts as a lookup field... Here is how I do this now.. #Connect to database print table\n; for (1..15) { print td nowrap\n; $query_teams=(select id, name from teams); $sth = $dbh-prepare($query_teams); $sth-execute(); $sth-bind_columns(\$id, \$name); print select name='away_team$_'; #$_ traps which pass of the loop we are in i.e., 3rd pass, 4th pass, etc print option value='0'/option\n; while($sth-fetch()) { print option value='$id'$name/option\n; } print /select\n; $sth-finish(); print /td\n; } #end for loop print /table\n; #disconnect from database How would I start to convert this with the CGI module. My problems thus far are on a popup menu, how do I specify the field variable that I grab is the ID, while the displayed value is another, and how can I say the first value should be 0, in case they do not enter anything? You're querying the database 15 times; I definitely wouldn't do that. I ususally grab all the rows into an arrayref using something like this: my $rows = $dbh-selectall_arrayref('select id, name from teams'); This handles all the DBI calls one one swoop. For the CGI module's popup_menu, you need two things: 1) a list of values for the option elements, and 2) a hash of value = description pairs for the labels Here's how to get the labels hash from the rows fetched above: my %labels = ( 0 = '', map @$_, @$rows ); You can extract the value list from the hash keys: my @values = sort { $a = $b } keys %labels; Now you can generate the table by using CGI's routines like this (OO style): print $q-start_table, $q-start_Tr, $q-td({ -nowrap = 'nowrap' }, [ map $q-popup_menu( -name = away_team$_, -labels = \%labels, -values = [EMAIL PROTECTED], -default = '0', ), 1 .. 15 ]), $q-end_Tr, $q-end_table; CGI let's you use start_xxx and end_xxx methods to generate just a start or end tag. If you pass an arrayref to a method like td(), CGI will generate multiple elements, one for each entry in the array. This lets us generate all 15 td elements in one call. Look in the CGI docs under THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS The map() function generates a list of select objects. HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: untainting data
Sara wrote: bad guys can always create their own form I can't say how others do it but almost my every script starts with: if ($ENV{'HTTP_REFREER'} !~ /yourdomain.com/) { exit; } it helps eliminating of Bad Guys forms shoving of data (no remote postings allowed). You do know that the Referer header can be trivially spoofed? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Address bar redirects
Jonathan Mangin wrote: Why doesn't my IE address bar reflect successful redirects? Perhaps an internal redirect is being used? Show us the script that's issuing the redirect. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: how to auto expire session when not active for 10 mins?
Jim Goh wrote: Hi, If I have web site and all the pages are under directory called www.mysite.com/test. Assume this directory test is access by username and password. After user enter the directory and view all the pages. However if user not touch the pages under this directory for more than 10 mins, then I want auto expire the session, then ask user to log in again from begin. If there any way to set this up with PERL? Thanks for your help. If you're using Basic Authentication (i.e. .htaccess file), you can't do it. If you're managing the sessions yourself, you have to keep track of the last request time per session. When a new request comes in, if it's been longer than 10 minutes, you need to clear the session and redirect them to the login page. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Capturing PID of Shell Calls
Jamie Bridges wrote: I am attempting to collect the PIDs of system/backtick calls ( up to 40 of them ) and revisit them to ensure that they completed. Both system() and backticks call wait() internally, so they don't return until the child process terminates. If you want to start a process and let it run without waiting for it, you need to use fork() and exec(). fork() returns the PID of the created process. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: undefined value error
Xiangli Zhang wrote: Here is my updated code with errorHTTP 500 that did not happened for the old code, and the modules I am using. n.b. that Error 500 is just a catch-all error from the web server. If other error messages from your script were output, you will find them in the web server's error log. So go look there. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Apache vs Boa error LFLF
Shawn Sharp wrote: I am working on some perl cgi code that works on an apache webserver but I get the following error when I run it on a boa webserver [08/Sep/2004:23:41:09 +] cgi_header: unable to find LFLF. I have tried the following change From: print content-type: text/html\n\n; changed to: print content-type: text/html\r\n\r\n; any ideas. I don't know what Boa is, but the controlling standard is RFC2616 (http://www.faqs.org/rfcs/rfc2616.html), which calls for CRLF as the line terminator in the message header section. But see also section 19.3, Tolerant Applications. Apache follows the tolerant applications recommendations. This kind of thing is why we recommend you use the CGI module instead of rolling your own code. use CGI ':standard'; print header; For kicks, have a look at the CGI.pm source code (perldoc -m CGI) and search for the string Define the CRLF sequence. It may be possible that Boa is not RFC-compliant. If you use the CGI module's header() method and it still doesn't work, I would take it up with the Boa folks... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: table with variables
Sean Davis wrote: Just print 'table' and '/table' separately. Note that CGI has start_table and end_table methods. If you use function style, you need to import them: use CGI qw(:standard start_table); print start_table; ... print end_table; Actually, you can do this with any tag, not just table. Also note that importing start_sometag also imports the corresponding end_sometag. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: table with variables
Ing. Branislav Gerzo wrote: print table( {-border=undef}, caption('Choose your favourite brand:'), Tr({-align=CENTER,-valign=TOP},), td($items[0], $items[1], $items[2]), td($items[3], $items[4], $items[5]) ); I want print all items into table, table should have 3 columns. I don't know how to do it. What you have prints one row with two columns. It looks like perhaps you want two rows with three columns in each row. To simplify, here's what you have: print Tr(td(0, 1, 2), td(3, 4, 5)) Which emits: trtd0 1 2/td td3 4 5/td/tr What you should do is pass an array reference to both Tr() and td(), which causes them to emit separate elements for each entry in the array: print Tr([ td([ 0, 1, 2 ]), td([ 3, 4, 5 ]) ]) Which emits: trtd0/td td1/td td2/td/tr trtd3/td td4/td td5/td/tr Note how each element is now inside it's own cell. Now, if the number of entries in @items is variable, you need to print enough rows of three elements each in order to display the entire array. Here's a little script to illustrate: #!/usr/bin/perl use strict; use CGI ':standard'; my @items = map value $_, 1..10; my $ncol = 3; print Tr([ map td([ @items[ $ncol * $_ .. $ncol * $_ + $ncol - 1 ] ]), 0 .. @items / $ncol]); That last line is a bit complex, so let me break it down: print Tr([ ...some rows... ]); The square brackets indicates an array reference. This causes CGI to output a tr element for each entry in some stuff. So some rows is a list of rows in the table. The rows are formed by: map ...a row... , 0 .. @items / $ncol Perl's map() function returns a list, by iterating over the list 0 .. @items / $ncol and evaluating a row for each value in that list. @items / $ncol is 10 / 3, which is 3., so the range is 0 .. 3., which perl treats as 0 .. 3, or 0, 1, 2, 3. These are basically the row numbers in the table. Since we have ten elements to display in three columns, it will take four rows to display them (0 .. 3). The map() call then needs to output a string of HTML representing the contents of a single row (whose row number is in $_). That's what a row needs to do. The code to output the HTML for a single row is: td([ @items[ $ncol * $_ .. $ncol * $_ + $ncol - 1 ] ]) Again, the outermost set of square brackets supplies an anonymous array to td(), which causes CGI to output a separate td element for each entry in the array. The array is a slice from @items consisting of the elements for the row number in $_. If the row number is 0, we want elements 0, 1, and 2. If the row number is 2, we want elements 6, 7, and 8. The starting element is always $ncol * $_, and the ending element is ($ncol - 1) beyond that. If you can get all the maths down right, this kind of thing is extremely powerful for generating dynamic tables, forms, etc. Take a look at perldoc CGI under the heading THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Month-Year Links....
Greg Schiedler wrote: Perl v5.6.1 Trying to easily create some variable based on the current month and links to the two previous months. The filename(s) are based on two digit months MM--Filename. I have the filename part working but I need some guidancd on creating the MM-. I have seen many perl modules that I could install to implement a solution but I think that is an overkill just to make create a current month, previous month and two months ago variables. Modules? We don't need no stinking modules! :~) my ($m, $y) = (localtime)[4, 5]; for (0 .. 2) { printf %02d-%04d\n, $m + 1, $y + 1900; $m--; $m = 11, $y-- if $m 0; } Output: 09-2004 08-2004 07-2004 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Partial interpolation over pattern sustitution
J. Alejandro Ceballos Z. wrote: How may I avoid partial interpolation over a pattern sustitution? My code looks like: # searching for all matches for later use @matches = $htmlpage =~ m/pre(.*?)\/pre/gs; for ($i=0; $i$#matches; $i++) { $htmlpage =~ s/pre$matches[$i]\/pre/predefined:$i\//; } The problem comes when the matches contains regex characters, and they try to be evaluated (ex. '|+--..' must be interpeted like '\|\+--\.\.'). You can use the following prior to entering the for loop. $_ = quotemeta($_) for @matches; You could also combine the capturing and substitution something like this: my @matches; $htmlpage =~ s/pre(.*?)\/pre/push(@matches, $1) predefined:$#matches/geis; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: stuck at TRUE/FALSE, pls help
[EMAIL PROTECTED] wrote: Hi I am very very new to perl. And after lots of work I did script a perl file to handle a online form (products order form). However, I am stuck at a point. I tried my best but could not get thru. The form is located at: http://www.kevincoffey.com/order.htm When I select a different shipping adrress, it DOESNOT work! Please define DOESNOT work. This is a common beginner mistake. It's obvious to you what you expect to happen and what is actually happening, but you've failed to communicate that to us, so we have to guess. I gave a RADIO button for : Shipping_Address: TRUE=SAME AS ABOVE (i.e. send to adove address) Shipping ADdress: FALSE = send to Floowing address [ snip ] if ($query - param (Shipping_Preference) == TRUE){ Is it Shipping_Address or Shipping_Preference? This is a numeric comparison, not a string comparison. A very common beginner mistake, so don't feel bad. To test strings for equality use eq, not == Enabling warnings would catch this. So get in the habit of enabling warnings... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: BACK button in CGI
[redirected to beginners-cgi list] Shah, Urmil wrote: This is a very basic question but still confusing me and so trying to get help. I have 3 CGI FORMS that display HTML output. One form leads to second and second leads to third. On 3rd page If I want to redirect the user to page 1 how do I do that. To redirect to another page, you need to generate an HTTP redirect response. This is easily done with the CGI module's redirect() method. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Filtering CGI Variables
Bill Stephenson wrote: Hi all, I need some help. I have name/value parameters coming in from a web form that look something like this (blank lines added for clarity): firstname=bill lastname=stephenson q1=1 t1=y d1=something 1 p1=3.45 q2= t2=y d2=something 2 p2=1.90 q3= t3=y d3= p3= q4=1 t4=y d4=something 3 p4=12 q5= t5=y d5= p5= q6=3 t6=y d6=something 4 p6=1.22 id_number=1259 action=none I want to remove the groups of data that look like q3-p3 and q5-p5 (where q,d, and p are all empty, t will always have data) then re-number the groups that contain data in in at least one of the q,d, or p variables, then save them to a file that looks something like this: firstname=bill lastname=stephenson q1=1 t1=y d1=something 1 p1=3.45 q2= t2=y d2=something 2 p2=1.90 q3=1 t3=y d3=something 3 p3=12 q4=3 t4=y d4=something 4 p4=1.22 id_number=1259 action=none I'm having trouble with the logic that will accomplish this. It doesn't seem like it should be very hard to do, but I just can't seem to say it in perl. [snip code] Here's the approach I would take (not tested!) my %data; for (param()) { # loop through all parameters if (/^([qtdp])(\d+)$/) { my $prefix = $1; my $num = $2; $data{$num}{prefix} = param($_); } } Basically, this inverts the data so you have a hash like: ( '1' = { q = 1, t = 1, d = 'something 1', p = 3.45 }, '2' = { q = '', t = 2, d = 'something 2', p = 1.90 }, ... and so on } Now, let's find the groups that have something in q, d, or p: my @groups = grep @data{$_}{qw/q d p/} =~ /\S/, sort { $a = $b } keys %data; Now you can write those groups out, renumbering as you go: my $n = 0; for my $g (@groups) { $n++; print $_$n $g-{$_}\n for qw/q t d p/; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Help needed in extracting html over HTTTPS protocol.
Anas Perwez wrote: Hi All, My requirement is to extract html from any site ( HTTPS) and then parse it for selective contents I am able to connect to HTTP sites but when it comes to HTTPS , it is throwing errors. [ snip LWP code ] Have you read http://search.cpan.org/src/GAAS/libwww-perl-5.800/README.SSL ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: using HTTP authentication
Andrew Gaffney wrote: I want to use HTTP authentication with Apache 2.x for a project I'm working on. I only need 1 user to be able to access the whole site (similar to a consumer router's web interface). Okay. What do I need to do to setup it up in Apache This is found in the Apache documentation. See e.g., http://httpd.apache.org/docs-2.0/howto/auth.html and how do I access the login information from my Perl scripts? This is explained in the LWP::UserAgent documentation. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: File upload question
Sean Davis wrote: I am trying to write a toy script that will ask for an upload file and then echo that file back to the user on the browser. However, if I do this all in one script like the following, I get no echoed file. However, if I instead use a separate HTML form and submit to my script, it works fine. Here is the script and the HTML submission form. I would like to use just the script. Can anyone tell me why the script does not work by itself? ... print $q-start_form(); This needs to be $q-start_multipart_form, as per the CGI docs. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: why do i get a file download prompt?
Gary Jennings wrote: Hi; I get a file download prompt when I run the following script. Can anyone let me know why? I am simply trying to print the contents of a file. Thanks. Displaying a download box is behavior of your browser. Your Content-Type header is botched, so maybe that has something to do with it. Or, your server may not be running the CGI script at all. Do you know that your server is properly configured? ... print content type: text/html\n\n; Missing a dash, and not RFC-compliant. print Content-Type: text/html\r\n\r\n; or, better: use CGI ':standard'; print header; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Reading a file
Octavian Rasnita wrote: Hi all, Does anyone know how can I read a file from a UNC path? Is perl able to read files this way? Just pass the UNC to open(). The underlying OS takes care of it; it's not a Perl issue. open(F, '\\server\share\dir\file.ext') or die $!; Or am I misunderstanding the question? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: How to host CGI scripts ?
Sunil Kumar wrote: Hi, I am new to CGI, i just wanted to know if I can host CGi scripts on my machine. OS Details : Win2k Professional with IIS installed, ActivePerl installed. Yes, you can. You need to configure IIS appropriately, which I can't help you with. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Checkbox_group
Werner Otto wrote: What I'm trying to do: print checkbox_group(-name='hdel',-values=[$hostname,$hostip]),; But I don't want $hostip's value to appear on the form, it should be available when I request the param though. Are to trying to show a check box with only the name, but be able to retrieve the name and IP when the check box is marked? I would suggest joining the hostname and ip together using some character to make a single value; then split the value retrieved from param() back into two parts. Use the -labels option of checkbox_group() to control the label displayed on the form. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Can't INSERT INTO for one column
Chris Charley wrote: Hi The error messages I'm getting from the attempted insert are: C:\perlpperl t.pl DBD::SQLite::db do failed: no such column: cash at t.pl line 17, DATA line 1. DBD::SQLite::db do failed: no such column: cash at t.pl line 17, DATA line 2. DBD::SQLite::db do failed: no such column: credit at t.pl line 17, DATA line 3 DBD::SQLite::db do failed: no such column: cash at t.pl line 17, DATA line 4. DBD::SQLite::db do failed: no such column: credit at t.pl line 17, DATA line 5 DBD::SQLite::db do failed: no such column: credit at t.pl line 17, DATA line 6 The code and the input data are: #!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI-connect(dbi:SQLite:dbname=mydb.txt,,); die $! unless $dbh; # customer vendor transType productCode appNumber resultCode $dbh-do(qq{ CREATE TABLE sales (customer int, vendor int, type char(10), product int, app int, result int) }); my $sql_fmt = INSERT INTO sales VALUES(%d, %d, %s, %d, %d, %d); You need to put single quotes aroung the %s, like this: my $sql_fmt = INSERT INTO sales VALUES(%d, %d, '%s', %d, %d, %d); while(DATA) { my $sql = sprintf $sql_fmt, split; $dbh-do($sql); } __DATA__ 10112 6768 cash 01020 00780 1 10112 6768 cash 01020 00780 0 10112 6768 credit 00040 01010 1 10112 3650 cash 01840 01200 0 14100 2410 credit 02840 00910 0 14100 5220 credit 01020 00780 1 I don't know why I can't insert for the type field. Without the quotes the sql statement looks like: INSERT INTO sales VALUES(10112, 6768, cash, 01020, 00780, 1) which looks like you want to use the value of the column named cash as the 3rd value, instead of the literal string 'cash'. Does the DBD::SQLite driver support placeholders? That's really the preferred way to do this kind of thing... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: POST method with perl module
Tobias Fink wrote: Good morning, im trying to set up a tools module for my modperl environment. My function get_vars should get all passed variables with the following snipplet: if($ENV{'REQUEST_METHOD'} eq GET){ $my_data = $ENV{'QUERY_STRING'}; } else { $data_length = $ENV{'CONTENT_LENGTH'}; $bytes_read = read(STDIN, $my_data, $data_length); (*) } This works great in a function of a script. If i put the code into a seperate module (which i use in my script), only the GET method works, so i think there is a problem in the (*) line. So, my question: How do i capture the POST variables from within a module. Short answer: use the CGI module. Or at the very least use the Apache request object methods for this. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: foreach problem
Ron B wrote: My problem is how to print the next line after the line that includes BLAH. So I want to print lines including BLAH keyword and when BLAH is found the next line after it. #!/usr/bin/perl # print lines wich include BLAH keyword print Content-type: text/html\n\n; print html\n; print head\n; print titleav/title/headBODY\n; open(HTMLOLD, /.../.../pohja.html); @lines=HTMLOLD; close(HTMLOLD); $count = 0; foreach $line (@lines) { if ($line =~ /BLAH */) { print $line; $count++; } if ($count eq 50){ last; } } print /body\n; print /html\n; You could solve this by setting some kind of indicator when you find a BLAH, so the next pass through the loop would print the following line. But don't do that. Instead of reading the lines into an array, process the lines directly in a while loop like this: while (HTMLOLD) { if (/BLAH */) { print; # print this line $_ = HTMLOLD; # read following line print; # and print it } last if $. = 50; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Deleting a dir
Octavian Rasnita wrote: Hi all, If the user Apache which runs the cgi scripts on my server want to delete a file that has restrictive priviledges and is owned by another user, how can I make a cgi program to be able to delete those files? Deleting a file requires write privilege in the *directory* containing the file; your permissions with respect to the file itself don't matter. If the apache user doesn't have write privilege in the directory, you can create a setuid script that can delete the files. There are several issues with this; please read the information in perldoc perlsec carefully. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Running a Perl module
Octavian Rasnita wrote: Hi all I want to run a certain perl module by getting the name of the perl module from a scalar variable like: $module =Test; require $module; I have read in the POD documentation that I need to use: eval {require $module}; or eval require $module; You need to use the latter. The former won't do what you want. And you need to check for errors. But the problem is that I cannot get a value returned by that module. The Test module returns a value named $value. If I use: require Test; print $value; The var $value is printed without problems, but if I call require for the $module, the var $value is not exported and I cannot use it. require() does not do exporting, so I'm not sure what you're saying here. The following are equivalent: require MyModule; $mod = MyModule; eval require $mod; Is Perl able to run a certain module if getting the name of the module from a variable, and able to access a value returned by that module? Not sure what you mean by returned by that module. Modules are required to return a true value to indicate that they were successfully initialized. If you want that specific value, just assign the results of the require() or eval. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Hash Assignment
stuart meacham wrote: If I have 2 arrays that I want to assign to the keys and values of a hash respectively, what would be easiest way to do that? @[EMAIL PROTECTED] = @valuesarray -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: running CGI locally??
Freimuth,Robert wrote: Hello, ... I would like to build a simple browser-based UI ... That's good. You'll need a web server of some sort, since that's what browsers talk to. Since I'm trying to generate dynamic HTML pages, I thought CGI would be the way to go. However, from what I understand of CGI, it requires a web server and can't be run locally. Since all of my code is in perl, I would prefer to stick with it, if possible. Your CGI scripts need to be run by the web server; however, the web server can be run on your local PC. Your browser would just talk to http://localhost You can construct a poor-man's web server without too much trouble with the HTTP::Daemon module available on CPAN. Or, you can run a more full-featured web server like Apache or thttpd locally. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: running CGI locally??
Freimuth,Robert wrote: ... I would like to build a simple browser-based UI ... That's good. You'll need a web server of some sort, since that's what browsers talk to. Since I'm trying to generate dynamic HTML pages, I thought CGI would be the way to go. However, from what I understand of CGI, it requires a web server and can't be run locally. Since all of my code is in perl, I would prefer to stick with it, if possible. Your CGI scripts need to be run by the web server; however, the web server can be run on your local PC. Your browser would just talk to http://localhost You can construct a poor-man's web server without too much trouble with the HTTP::Daemon module available on CPAN. Or, you can run a more full-featured web server like Apache or thttpd locally. This sounds promising. Could you please direct me to a resource that explains how to set this up? I took a look at the docs for HTTP::Daemon but I couldn't understand how to use it. http://www.webtechniques.com/archives/2000/03/junk/ looks interesting. But if you don't want to fool with HTTP::Daemon, give thttpd a look: http://www.acme.com/software/thttpd/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Execute an external script
[EMAIL PROTECTED] wrote: Hi! I've written a perl cgi script to create a web page. Now what I'd like to do is to execute an Octave script from the Perl one and get its output inside my perl script. I'm working on a Windows XP machine. I tried $result = `C:/Program\ Files/GNU\ Octave\ 2.1.50/bin -q my_script.m`; but $result is still null. Is bin really the name of the execuatble, or is it a directory name? Something seems to be missing. Also, those backslashes aren't doing anything for you, AFAIK. You might want to write that as: `C:/Program Files/GNU/Octave 2.1.50/bin/ -q my_script.m` program name here -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Newbie question
Shalabh wrote: hi all, Hi. Use a better subject line. i am searching from a tab delimited text file and it is returning the line with tabs which contains the search string into an array named @found_array, now i want to display it on an html page in a predefined format and for that i have to split it with tab as the delimiting character. any idea for doing this as i have tried split function but i think it doesnt work on arrays. any help is appreciated. Thanks in advance the code is as follows #!/usr/bin/perl -w Always 'use strict;' use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); $query = new CGI; print Content-type: text/html\r\n\r\n; print $query-start_html(-title= new, -bgcolor='#DFD2B3', ); $keyword=$query-param('s1'); chomp($keyword); Why? $keyword =~ s/([~;\*\|`\$!#\(\)\[\]\{\}:'\.\/])//g; Don't need the capturing parens. Also, lots of those chars don't need to be escaped inside a character class. open (IN, pdata) or die (Cannot open database!); @found_array = (); while ($parray=IN) { @found_array = (@found_array,grep (/$keyword/i , $parray)); grep is unecessary here, since you're only operating on one line at a time. This can be simplified to: push @found_array, $parray if $parray =~ /$keyword/oi; (/o can be added since keyword doesn't change once it's been assigned) } print font size=4 color=bluebYou Queried for $keyword/b/font\n; print @found_array; If you want to output the @found_array as an HTML table, you can do something like this: print $query-table( $query-Tr([ map $query-td([split /\t/]), @found_array ]), ); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: What are you really trying to do? - document type = applicat ion/vnd.ms-excel
Moon, John wrote: What I'm trying to do is make my new boss happy! They like everything in Excel. I have a BUNCH of CGI scripts on a SUN Unix generating tons of very nice HTML pages from data in an Oracle database I need to alternately be able to generate the same pages in an Excel spreadsheet... Any thoughts would be greatly appreciated... Here's an extract from a CGI script of mine that produces an Excel file from some database info. Before the sub is called, @data is filled with rows of data. $q is my CGI object. I'm using the CGI, Spreadsheet::WriteExcel and File::Temp modules. Basically, I'm writing the Excel worksheet to a temp file and then sending the contents of that file back to the client (you can also write directly to the client; see the Spreadsheet::WriteExcel docs; I use the temp file so I can send a Content-length header.) (I use multiple write_xxx methods because some of my data looks like numbers, but I want it treated as text strings.) sub do_current_stock_status_excel { # open the worksheet my ($fh, $fname) = tempfile(undef, UNLINK = 1); my $xls = new Spreadsheet::WriteExcel($fname); my $wks = $xls-addworksheet; # create formats my $ftext = $xls-addformat(num_format = '@'); my $fdate = $xls-addformat(num_format = 'mm/dd/yy'); my $fquan = $xls-addformat(num_format = '#,##0_);(#,##0)'); my $fcost = $xls-addformat(num_format = '#,##0._);(#,##0.)'); my $famnt = $xls-addformat(num_format = '#,##0.00_);(#,##0.00)'); # set column info # each aref contains: # [0] = Heading # [1] = Column width # [2] = format # [3] = method to use to write the cell # [4] = data source (coderef, $_ = current row) my @col = ( [ 'Account', 12, $ftext, 'string', sub { $_-[10] } ], [ 'Item Group', 6, $ftext, 'string', sub { $_-[6] } ], [ 'Whse', 5, $ftext, 'string', sub { $_-[0] } ], [ 'Item Code', 16, $ftext, 'string', sub { $_-[1] } ], [ 'Description', 40, $ftext, 'string', sub { $_-[4] } ], [ 'Comm Code', 8, $ftext, 'string', sub { $_-[7] } ], [ 'Std Matl', 16, $fcost, 'number', sub { $_-[8] } ], [ 'Std Oper', 16, $fcost, 'number', sub { $_-[9] } ], [ 'On Hand', 16, $fquan, 'number', sub { $_-[3] } ], [ 'Ext Matl', 16, $famnt, 'number', sub { $_-[8] * $_-[3] } ], [ 'Ext Oper', 16, $famnt, 'number', sub { $_-[9] * $_-[3] } ], [ 'Total', 16, $famnt, 'number', sub { ($_-[8] + $_-[9]) * $_-[3] } ], ); my $row = 0; my $col = 0; # set worksheet headings $wks-write_string($row++, 0, Current Stock Status); $wks-write_string($row++, 0, Company: $p{comp} $compname); $wks-write_string($row++, 0, As of Date: . $mcscgi-format_date($p{date}, '%b %d, %Y')); $row++; # set column headings, width, and format for (@col) { $wks-set_column($col, $col, $_-[1], $_-[2]); $wks-write_string($row, $col, $_-[0]); $col++; } # add the raw data $row++; for (@rows) { $col = 0; for my $c (@col) { my ($method, $data) = @{$c}[3, 4]; $method = write_$method; $wks-$method($row, $col, $data); $col++; } $row++; } $xls-close; # emit the response print $q-header( -type = 'application/vnd.ms-excel', -Content_length = -s $fh); print $_ while $fh; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: CGI.pm unsecure / dangerous ?
David Gilden wrote: I just had blow up with a sys. adm. who said my script (see below) is potentialy unsecure and dangerous and therefor unacceptable. ... Is there away some could hijack my script, if so how, or is this sys. adm. not living in the real world? You are passing form parameters directly to sendmail without examining them at all. Not good. I could stuff a Cc: line and my own message body into one of the name paramters for instance, and thus use your script to send any email to anyone. Your subject is misleading. There's nothing particularly insecure or dangerous about CGI.pm. It's your implementation that's problematic. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Email text encoding
Camilo Gonzalez wrote: Eek! I've been told by my ISP that my Perl script to email myself and the user of my form the contents on my contact form has been hijacked by a spammer. My ISP has been deluged by recipients with complaints. Where have I gone wrong? Please be kind, this is a beginners' list after all. ... my $email = $cgiobj-param('email'); ... print SENDMAIL To: $email, $reply\n; Hint: $email could contain more than just an email address. Think about it... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: LWP get with no cache
J. Alejandro Ceballos Z. wrote: I created a cron job that gets a page using LWP::Simple, but everytime it runs via cron, it sends me the results generated when I called directly; like if the page was called from memory or from a cache, not from the actual one. Is there any way to specify not to store the page results in a cache? Like a pragma no-cache or similar? LWP doesn't do any caching, AFAIK. I think something else is going on. Can you post your code? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Storing Form Data without submitting it.
Andrew Gaffney wrote: I believe there is an HTTP status code that tells the browser that the form was successfully submitted, but not to go anywhere. I don't know what it is off the top of my head, but I think it would work in this case. Would that be 204 No Content? http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.5 I've never used that before. I wonder if the various browsers behave properly when they get that? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: REMOTE_USER
Colin Johnstone wrote: Gidday All, We are running AIX on an IBM HTTP server with IHS. We are serving static HTML pages. Some of these pages are to be protected. OK. That's the job of the web server, so you need to configure it to protect those pages. With Apache, you use .htaccess files and/or entries in httpd.conf. I assume IHS has something similar. I assume I place the restricted pages in a particular directory and then protect that directory. Once authenticated a user should be able to view protected pages without logging in again for the duration of the session. Right. Under basic authentication, the browser caches the credentials and supplies them automatically for any 401 responses. What does this have to do with Perl? I understand that once a user is authenticated their (userId) email address will be stored in the environment variable REMOTE_USER for access by cgi-scripts. The environment variables are set by the web server prior to invoking the CGI script. Now what I don't understand is how from a static HTML page can I check this REMOTE_USER variable automatically. Of course the first time they visit a page in the protected directory they will be prompted for their username and password, but then what? You don't check it from static pages. The web server checks the authentication credentials (from the HTTP request, not the environment), and either serves or doesn't serve the static page. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SQL question // date_format
David Gilden wrote: Good evening, The following mySQL query works fine, but the server is in California. I would like add 2 hours to %l, because the client is in Texas. I could just go to time in GMT and forget about it :) But I'm wondering if there is a simple solution here. SELECT id, DATE_FORMAT(datecreated, '%c/%e/%y at: %l:%i %p'), email, name, comments FROM $table_name order by id limit $offset,10; I don't use MySQL, but PostgreSQL has a SET TIME ZONE statement you can issue to define the local time zone for a session. Perhaps MySQL has a similar thing? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: remote host name
Alexander Blüm wrote: hello, as my subject indicates, I'm looking for a way of resolving the remote hostname. any system command will do too... perldoc -f gethostbyaddr I'm planning to write a small script that simply tells the connecting user, which DNS name he has, since my localnet is equipped with a dhcp server the clients usually get a new address each time.. their new address usually looks like this dhcp184.bluemix (bluemix is the domain)... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: allow CGI to write on my HDD
Jean-Baptiste.Claude wrote: Hi, My cgi script has been written in order to collect some parameters (with the POST method) but actually if I want to record them, I can just put them in a pre-existent file. I am unable to create a new file, even with a 'chmod 777' on my directory... I would have a result like this: #test.cgi## $name=$$.$var; if ( ! -f ./$name){ open (OUT,$name); } foreach $i (@DATA){ ... print OUT $i\n; ... } close OUT; 1. You should not make any assumptions about the current working directory in a script like this. Always specify a full path to files. 2. You say the file is preexisting, but you're using $$ in the filename, which is your process ID number. How is the file preexisting? 3. You need to open the file whether or not it exists. If you want to append to the existing contents, then open in append mode. 4. Always check the return value from open(). 5. Where is $var coming from? If it's coming from the client's request, you need to be careful. Be sure to use taint mode in your script and read the perldoc perlsec page for issues related to using tainted data. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: accessing a hash map...
Hanson, Rob wrote: You have it slightly wrong... print $hashref{'disks'}-{'io'}; Nope. That references a member of the %hashref hash. He wants print $hashref-{disks}{io}; ...And the quotes are optional (usually)... print $hashref{disks}-{io}; Is there a more generic mailing list for the different perl modules? Thare are other lists/newsgroups, but most are geared to specific port (ActiveState), or modules (Tk). This is a good list for any beginner(ish) question, no matter the subject... just as long as it is a Perl question. Rob -Original Message- From: Li, Kit-Wing [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 09, 2003 2:40 PM To: cgi cgi-list Subject: accessing a hash map... This may not be the right thread but I'd like to see if someone could point me to the right direction. I'm writing a CGI script to show current performance of the Apache server and I'm using Linux::stat to get the disk IO for example. I can seem to access the value of the hash reference(see below). Does anybody have any thoughts? Is there a more generic mailing list for the different perl modules? I know there's the mod_perl thread but its more for Apache. Any help will be greatly appreciated. Thanks! use Data::VarPrint; use Linux::stat; my $stat = Linux::stat-new( [ stat = path to /proc/stat ] ); my $hashref = $stat-stat(); print $hashref{'disks'}={'io'}; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Perl on the web?
Dawn Bradshaw wrote: Hi! Does anyone have experience with making a perl script run on the web? Specifically, I'm having trouble collecting the answers the users give on the web page and incorporating them into the script. The script itself runs fine on the web server. Any suggestions, advice or help would be greatly appreciated! 1. Use the beginners-cgi list for this. 2. Supply more details. What environment are you running in? What is the trouble you're having. Error messages, unexpected behavior, don't know how to configure the web server to run your script? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: perl script as binary
Sven Bentlage wrote: Hi everyone! I`m looking for a way to compile a perl script into an executable binary for a WIN2000 system (no(!) perl installed). Is there a way to get this working? I use ActiveState's PerlApp for this. It's really very nice. It bundles everything into a single self-contained .exe file you can deploy to PC's. No need for Perl to be installed on them. http://www.activestate.com/Products/Perl_Dev_Kit/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Urgent Question (Deployed code gone wrong!)
Greenhalgh David wrote: A quick question about a while loop. I have a simple code that searches database for all entries and puts one of the fields into a select box on the output page. However, due to a mistake in my untaint routine (which I've fixed) if a visitor entered their name in Japanese characters, the entry into the data base is blank. That means that my simple while loop: while ($name=$sth-fetchrow_array()) { You have a subtle bug here. It should be: while (($name)=$sth-fetchrow_array()) { This forces the assignment to be in list context. That way, the while() condtion will be true if fetchrow_array returned any values, or false if it returned an empty list. That would make the blank value not terminate your loop. print option$name/option; } stops when it hits the blank name. I can also select the ID number.. while (($name, $ID)=$sth-fetchrow_array()) { print .option$name/option; } Since this is deployed code, I would like to know if this will work before I try it. Will the loop stop when $name is blank, or will it keep running because $ID is NOT blank and stop only when both are blank? The loop will keep running as long as fetchrow_array returns a row, even if both columns are blank. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flock and Sleep
Sara wrote: (sub get_number { open(NUMBER,data.txt); flock (NUMBER, 2); Use the constants from the Fcntl module. Do blah blah blah close (NUMBER); closing a file automatically removes the lock?? Yes. or should I have to unlock it by placing flock (NUMBER, 8); close (NUMBER); No, you don't need to do that. In fact, it used to be dangerous, because of buffering. If you unlocked the file, buffered data could be written after the lock was released. Perl now automatically flushes the file before unlocking to avoid this. Bottom line: if you're going to close the file, don't worry about explicitly unlocking. You only need to unlock if you want to allow another process to gain the lock while you still hold the file open (i.e. coordinating changes to the file among multiple processes). My second question is how I can delay the execution of a script (If two users trying to execute the same script) for 30 sec by using sleep function? and If I implement sleep function in my script . Do I really need to use 'flock' in my script or there is no need then. If you want to make sure the two programs aren't changing the file simultaneously, you should use flock. If you dont' want to block forever if another process has the file locked, you need to use the LOCK_NB parameter and then sleep() or whatever until you want to retry the lock. Note that if multiple processes need to append to the file and each writes its data with individual calls to syswrite(), you don't need to use locking (although it doesn't really hurt anything). The kernel will perform individual writes atomically. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: New to list...needing help
Bruce Whealton, Jr. wrote: Hi all, I've been frustrated with my initial efforts to run perl scripts on my server, or rather the server I use. I have tried a few simple form mailers, each of them failing with internal 500 error. 1. Post these issues to [EMAIL PROTECTED] 2. Whenever you get the 500 repsonse code, go look at the server's error log file for additional error messages. There can be any number of problems that cause the 500 error. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: cookie expiration time problem
Sawsan Sarandah wrote: Greetings, I have a small problem. When I create a cookie using cgi.pm, the expiration date is always three hours behind the actual time. In other words, the following code snipet: # Time on my local machine: 10:00 pm # Rhat Linux server using date command: Fri Jul 11 21:59:44 IDT 2003 # hwclock command: Fri 11 Jul 2003 09:59:48 PM IDT 0.611152 seconds $cookie = $cgi-cookie -name= $cookiename, -value= $uname, -expires= +4h, -path='/' ); The above code produced a cookie with an expiration time as follows: Expires: Fri, Jul 11 2003 22:58:33 Notice that the cookie expires in one hour, not in four hours (+4h). What could possibly be the problem? Where is PERL reading the incorrect time from? It should say Fri, Jul-11-2003 22:58:33 GMT, per the cookie specification http://wp.netscape.com/newsref/std/cookie_spec.html The time must be in GMT. Try this: $ perl -MCGI -le print CGI::cookie(-name='foo',-value='foo',-expires='now'); print scalar gmtime) foo=foo; path=/; expires=Fri, 11-Jul-2003 19:36:23 GMT Fri Jul 11 19:36:23 2003 The two dates should match. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Working with DBI
Greenhalgh David wrote: On Tuesday, July 8, 2003, at 01:19 pm, Bob Showalter wrote: Greenhalgh David wrote: ... In other words, my SELECT block is returning the value of available as it was before the UPDATE, even though I have AutoCommit set to 1, the UPDATE is called before the SELECT and manual investigation of the table clearly shows that the UPDATE was successful. This suggests to me that even though AutoCommit is on, the commit does not actually happen until the $dbh is released and the connection to the database cut. The setting of AutoCommit shouldn't matter. Your session should see all updates immediately. Commits only affect the visisbility of updates to other sessions. Something else is going on. Start by constructing a very simple, stripped down example that updates a row and then selects that row again so we can make sure the database is behaving properly. Verify that that example works regardless of the AutoCommit setting. I suspect something is amiss in the logic of your program that you just aren't seeing. Try stripping it down to the minimum code that still exhibits the problem and post the complete code. OK, as requested, I have stripped out most of the script and produced the bare minimum. The effect is the same, $before gives today's date, not a date 8 days in the future. However, when the DB is interogated after the script has run the available field is correct and really does give a date 8 days in the future. (Note - the available column is set to todays date in another script that is called before this one runs. In the full version of the code, the first script is re-called after this one runs and correctly displays the expected result. It is only when calling the SELECT inside the same script as the update that i get problems.) #!/usr/local/bin/perl -wT use strict; use CGI ':standard'; use DBI; use CGI::Carp qw(fatalsToBrowser); # Simulate a param call in CGI my $player=HarryPotter; # Connect to the database my $dbh = DBI-connect(DBI:mysql:ladderDB, , xx); # Make an update that is representative of the full script my $offset=8; my $updatehandle1 = $dbh-do(UPDATE league SET status = 1, available = DATE_ADD(NOW(), INTERVAL '$offset' DAY) WHERE user_name = '$player'); # Try to select the new value of available my $availquery = SELECT available FROM league WHERE user_name=$player; The fact that you don't have single quotes around $player is highly suspicious. I don't see any error checking. Make sure you have RaiseError turned on. I strongly suggest you use placeholders rather than interpolating values directly into the query. Have you done what I suggested and constructed a minimal example to make sure the database is working correctly? my $availhandle=$dbh-prepare($availquery); $availhandle-execute; my($before) = $availhandle-fetchrow_array; # Full version selects email addresses etc in this block $availhandle-finish; # See what came out into $before print Content-Type: text/html\n\n; print Query return is $before;# Always prints todays date. Expected return is today + 8 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Working with DBI
Bob Showalter wrote: ... Make sure you have RaiseError turned on. and PrintError -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: question on global variable / scope
David Granas wrote: Hi, Im just learning Perl and was a little confused with why I couldnt prevent my subroutines from reading variables from the main program. Here is an example: use strict; my $var = 1; test(); sub test { print $var; } I had thought that a my variable would not be able to be read by the subroutine, but it can still see it. So my question is how can I prevent subroutines from having access to variables in the main program. Perl's behavior here is not different from that of other languages like C. If you want, you can create a sub main (a la C) and put your main program and its variables there. You need a call to main() to start off the program: use strict; main(); sub main { my $var = 1; test(); } sub test { print $var; # doesn't see the $var from above } Since my variables are visible only from the point of declaration to the end of the enclosing block or file, you can acheive the same result by putting your main program and it's variable declarations at the bottom of the file: use strict; sub test { print $var; # doesn't see the $var from below } my $var = 1; # only visible from here to end of file test(); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Using # in the url string
michael watson (IAH-C) wrote: Hi guys Hope someone can help. My file is called lame#19.gpr I am trying to send this to my cgi script, so my url looks like: cgi?filename=lame#19.gpr But of course # is a special character for a URL, so my filename parameter gets cut short to lame Does anyone know of a nice, elegant or simply workable way of getting round this, saving renaming the file? You should *always* properly escape parameter values. You can use URI::Escape module for escaping parameter values individually, or you can use the URI module to construct a properly escaped URI. URI module example: use URI; my $uri = URI-new('http://myhost.com/cgi/myscript.cgi'); $uri-query_form(filename = 'lame#19.gpr'); print $uri\n; prints: http://myhost.com/cgi/myscript.cgi?filename=lame%2319.gpr If you're using the CGI module and constructing a self-referencing URL, the url() method automatically escapes the parameter values (which you set with param()). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Premature end of Script header
Kristofer Hoch wrote: David, print Content-Type: text/html\n\n; # Inaccurate print Content-type: text/html\n\n; # Accurate The difference is in case sensitivity. Notice the word '-type:' Actually, Content-Type is correct per the RFC (see RFC 2616, sec. 14.17). But these fields are not case-sensitive, so either form will work. The OP's problem lies elsewhere. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: DBI indexing question
Greenhalgh David wrote: ... Second question. If I use the following: my $query=CURDATE(); my $sth-prepare($query); $sth-execute; I understand that $sth now just contains the reference to the result of the query. Where is the value of the query (which should be today's date.) It doesn't seem to be in $_. I don't know MySQL, but that doesn't appear to be a valid query. Queries start with SELECT. Anyway, on a query that returns rows, you fetch the rows with one of the fetch methods of the statement handle. Something like: my ($result) = $sth-fetchrow_array; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Calling a perl script from another perl script
Paul Kraus wrote: List correct me if I am wrong but you can use single quotes here because your not using any variables. You are passing exactly what you see. In fact this is the preferred way to write strings that do not contain variables or special characters. Correct? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of zentara Sent: Monday, June 02, 2003 3:20 PM To: [EMAIL PROTECTED] Subject: Re: Calling a perl script from another perl script On Mon, 2 Jun 2003 14:21:37 +0100 (WEST), [EMAIL PROTECTED] (João luís bonina) wrote: Well, I've tried the system function, but it isn't executing the script which is located in the same directory... I'm using it this way : system('sendfile.pl ons4jlb'); If you havn't found an answer yet, it looks to me like you have an error with single quotes around 'sendfile.pl ons4jlb' It should be like this: system('sendfile.pl' , 'ons4jlb') the (command , @args) The two are equivalent given the data supplied. from perldoc -f system: system LIST system PROGRAM LIST Does exactly the same thing as exec LIST, except that a fork is done first, and the parent process waits for the child pro- cess to complete. Note that argument processing varies depend- ing on the number of arguments. If there is more than one argument in LIST, or if LIST is an array with more than one value, starts the program given by the first element of the list with arguments given by the rest of the list. If there is only one scalar argument, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing (this is /bin/sh -c on Unix platforms, but varies on other platforms). If there are no shell metacharacters in the argument, it is split into words and passed directly to execvp, which is more efficient. Since system('sendfile.pl ons4jlb') has only one scalar argument, it is checked for shell metacharacters. There aren't any, so the argument is split on words and passed to execvp. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need your help regarding CGI
Soumyadeep nandi wrote: Hi Everybody, As a naive cgi programmer, I want to get rid of a problem, for that, I am keen, awaiting your suggestions. I doubt, I could not present my case in front of you properly. Anyway, my problem spins around the following. I am running a CGI script in which I am running a system command. The scripts is as follows: #!/usr/bin/perl -w use strict; use CGI; open(FH_seq1,/var/www/cgi-bin/emboss/water1.seq); open(FH_seq2,/var/www/cgi-bin/emboss/water2.seq); print Content-type:text/html\n\n; my $query = new CGI; my $seq1 = $query-param(seq1); my $seq2 = $query-param(seq2); print FH_seq1 $seq1\n; print FH_seq2 $seq2\n; `/var/www/cgi-bin/emboss/water /var/www/cgi-bin/emboss/water1.seq /var/www/cgi-bin/emboss/water2.seq -gapopen 10 -gapextend 5 -outfile /var/www/cgi-bin/emboss/water.out`; In addition to what zentara said, I would suggest you close the FH_seq1 and FH_seq2 handles before calling the external script. This will make sure any buffered data is written to disk. Above I am using the system command to run the program water which should write the output into file water.out, which is not writing anything to this file. I've given all permission to these files as: -rwxr-xr-x 1 soumya soumya 2978221 Jun 15 10:26 blastall -rwxr-xr-x 1 soumya soumya 4912 Jun 13 08:25 water -rwxrwxrwx 1 apache apache 36 Jun 16 05:18 water1.seq -rwxrwxrwx 1 apache apache 36 Jun 16 05:03 water2.seq -rwxrwxrwx 1 soumya soumya 48 Jun 16 05:18 water.out But if I use the first file in the directory i.e. blastall in the script as my $out = `./blastall`; print $out; I get the proper output. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Forcing a refresh from within a CGI script
Rob Dixon wrote: Hi all. I'm in the process of modifying an existing CGI script. There is a page of HTML which has an anchor to the script which, when run, modifies the HTML file which linked to it and redisplays it. At present this is done by returning just the header line Location: http://www.domain.com/referrer.htm to the client after modifying the file. Firstly, I'm not at all sure if this is the preferred way to force a refresh, and secondly it doesn't always work as the client browser believes it has a valid cached copy of the page and refuses to reload it. Can someone help me towards a better solution? To prevent the client from using its cached copy, you'll need to have the server send an Expires header with the .html page. This can be accomplished by adding meta http-equiv=Expires content=0 in the head section of the .html file. (RFC 2616 specifies that clients must treat an expires value of 0 as already expired.) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: self refreshing web page question
Luinrandir Hernsen wrote: I want to create a web page that calls on another web page and automatically refresh the other webpage every minute. can I do this in JS alone? Perl alone? or do I have to use both? Thanks for the help, I just need to be pointed in a direction... You can have a page refresh itself by emitting a Refresh response header. To have one page refreshing another you'll need to have the pages in separate frames or windows and use JavaScript to trigger the refreshing. I find the following site helpful for little JavaScript snippets for this kind of thing: http://developer.irt.org/script/script.htm -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: safe system()?
drieux wrote: ... think about the case of $file = '/path/to/file ; ( find / -print | xargs rm -r -f )'; system(md5 $file); DO NOT TRY THAT ONE AT HOME KIDDIES Wouldn't system('md5', $file); Be safer, since the list form of system() bypasses the shell? Consider: $ perl -e system('md5 /etc/passwd; echo Hello') MD5 (/etc/passwd) = 232522a1340d0956071c7b8b005a627b Hello versus: $ perl -e system('md5','/etc/passwd; echo Hello') md5: /etc/passwd; echo Hello: No such file or directory -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Replacing/deleting text in a text file, part deux
Scot Robnett wrote: Anything I can do to make this an easier question? No responses...maybe I didn't ask the question the right way or made it confusing as to what I am trying to do? Would it help to split it up? Thanks for any advice... ... foreach $record(sort(@records)) { chomp($record); ($comp,$addr) = split(/\|/, $record); @emails = split /:/, $addr; # Right here, I want to see if any of the addresses # in @addresses match an address in @emails for this # particular $record. Turn @addresses into a hash (do this ouside the loop of course): my %addresses = map ($_, 1), @addresses; Then, to remove entries in @emails that exist in @addresses: @emails = grep !exists($addresses{$_}), @emails; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Replacing/deleting line in a text file
Scot Robnett wrote: I have a delimited file that is formatted like this: Altech|[EMAIL PROTECTED]:[EMAIL PROTECTED] Specialties Steel Corp. |[EMAIL PROTECTED] Specialty Steel Corp. [EMAIL PROTECTED]|[EMAIL PROTECTED]:[EMAIL PROTECTED] burton.com* Starwood|[EMAIL PROTECTED] foods|[EMAIL PROTECTED]:[EMAIL PROTECTED] starwood|[EMAIL PROTECTED]:[EMAIL PROTECTED] Authentic Fitness Corp.|[EMAIL PROTECTED] Basically that's one continuous line; there are no line breaks. Don't ask me, I just inherited the file. The records are delimited by * and then each individual record is split as company/email by a pipe | character. If more than one person wants to track a particular company, their e-mail address is appended to the first with a colon and split on same for processing. Here's a simple example that splits each record out, removes an address, and spits the file back out #!/usr/bin/perl use strict; $/='*'; # input lines delimited by '*' while () { chomp; # strip the trailing '*' my ($comp, $addr) = split /\|/; my @addr = split /:/, $addr; # now you can adjust the @addr list to add or remove addresses # for example, remove addresses containing 'mrbill.com' @addr = grep !/mrbill\.com/, @addr; # put everything back together and print it out print join('|', $comp, join(':', @addr)), $/; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: CGI.pm htmlTAGS
David Gilden wrote: Good afternoon, a few quick questions pertaining to CGI.pm: How can I get CGI.pm to return lower case html tags. print end_html; # prints Upper Case /BODY/HTML probably need to upgrade CGI.pm. I get lower case: $ perl -MCGI=:standard -le 'print $CGI::VERSION; print end_html' 2.752 /body/html is there something I can add locally to my script or do I have to send a request to my ISP? How would tell what version I have running at my account? output $CGI::VERSION in one of your scripts. This is what I am using at top of my scripts: #!/usr/bin/perl -w use CGI qw/:standard/; Can the param() method take strings with spaces in them like: param('my name') # is this bad practice or inefficient? This is legal. Don't know if it's considered bad practice. and is calling: param('my name') param('My Name') going to look for different form fields-- i.e. is param() case sensitive? Yes, parameter names are case-sensitive. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Help using %Hashes
Horace Franklin Jr. wrote: Help! I need help using %hashes to receive input from the form below. What changes would I make to the syntax of the commented lines below to do this?. Well, none. That code creates the form, which is a different matter from receiving input from the form. When the form is submitted, the inputs will be encoded within the request body. It's up to your script to parse those into whatever data structures you see fit. If you're using the CGI module (and you should), you can suck all the parameters into an array with the Vars method: use CGI; my $q = new CGI; my %params = $q-Vars; Now you can access individual params as: $params{name} $params{email} $params{message} and the like. Is that what you want? Read the CGI docs for additional info on using Vars (you can get a tied hash for instance that lets you change parameters). my $form = E_FORM; h3Hello!/h3 form action=$url method=post # pbMy name is/b: input type=text name=name//p # pbMy E-mail is/b: input type=text name=email//p pbMessage/b:/p # ptextarea cols=30 rows=6 wrap=virtual name=message/p pType your message here. /textarea input type=submit/p /form E_FORM $form; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: simple query
mark sony wrote: Hi Can anyone tell me what does $. in perl mean ? And also anyplace I will get references about these in quick time ie. a handbook type ? All the special variables are documented in perldoc perlvar $. keeps track of the input line number, similar to awk's NR -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: html table limit
Rob Benton wrote: Is there a limit to how many rows you can put in an html table? I can't find anything wrong with my script but when I get over 1000 rows or so in my tables they start drawing weird borders. That would be a function of the browser, so see if your browser has any limits. Try viewing the page with different browsers. Also, make sure your all your tags are balanced (tr with /tr, td with /td, etc.) You can run your HTML through a validator such as http://validator.w3.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: html table limit
Rob Benton wrote: Mozilla, Konqueror, Opera, and IE all act the same way. Check out this page to see what I mean. The top, bottom, and right side of the table borders act funky: http://www.geocities.com/emperorrob/test.html Hmm, this page displays fine for me in IE6. I tried the validator but it keeps timing out. :) I guess the file is too big. I was able to run the validator. The only problem is you're missing a head/head section and some complaints about the junk yahoo adds on. No problem with the table. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: cgi security aspects
Skorpion wrote: can you give me a pice of advice of security aspects creating cgi scripts working with apache server on linux running 2.2.19 kernel - any backdoors i should be aware of ? See the security resources on the CGI Meta-FAQ: http://www.perl.org/CGI_MetaFAQ.html is there any chance to get a root password via badly writen cgi script - i used mysql and psql dbd pure perl modules with dbi 1.16 while somebody hack my machine - maybe it wasn't via cgi but i am not so sure thanks for help or any links greg -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Database connection trouble
Van Andel, Robbert wrote: A coworker and I have been working on connecting to a MySQL database running on the webserver. We are using the following command to connect: my $dsn = 'DBI:$driver:database=$database;host=$hostname'; my $dsn = DBI:$driver:database=$database;host=$hostname'; my $dbh = DBI=connect($dsn, $user, $password) or die errstr my $dbh = DBI-connect($dsn, $user, $password) or die $DBI::errstr; This works when run from an ordinary shell based perl program but when we try to put it on the website into the cgi-bin it will not connect. What are we doing wrong? Does MySQL need one or more environment variables set? If it connects via a UNIX domain socket, is that socket writeable by the web server user? These are just guesses; the $DBI::errstr should give you more info on the specific problem. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Database connection trouble
Bob Showalter wrote: my $dsn = DBI:$driver:database=$database;host=$hostname'; Oy vey! One more try: my $dsn = DBI:$driver:database=$database;host=$hostname; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Perl question
Stephen Spalding wrote: Hello all, I have a question about perl. I'm trying to pass an array into a subroutine, but I don't know what the proper way to receive it in the subroutine is. Below is an example of what I'm trying to do. The ??? represents what I do not know what to put in. @sample_array = ('hi', 'there', 'steve'); use strict; my @sample_array = qw(hi there steve); PRINT_CONTENTS(@sample_array); Don't use the quotes. Those interpolate the array into a single long string. Also, lose the ampersand: PRINT_CONTENTS(@sample_array); exit 0; sub PRINT_CONTENTS { @local_array = ??? Perl passes all arguments in a single array, @_ my @local_array = @_; foreach $string (@local_array) { print string = $string\n; } } You could also just use @_ directly and simplify the sub to sub PRINT_CONTENTS { print string = $_\n for @_; } It's also common to shift elements one at a time off of @_: sub PRINT_CONTENTS { print string = , shift, \n while @_; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Data Validation Issues
Will wrote: Greets Folks, I am developing a registration area for a members site that will interface with a MySQL DB users table, and I ran into a problem or two. Note that I am using DBI as my DB Driver. ... Second, suppose they try a username that has already been taken. I need a way to kick back an error message to them. I tried setting the username field in the usrs table to UNIQUE, so that might help if someone tried to insert something already taken... I was thinking that if MySQL kicks back an error message, then DBI might be able to recongize it in such a way that I could use the return value... I dont know if that is completely feasible though... there may be other, better ways anyway... so I'm all ears... $DBI::err will have the database engine error code from the last call. You'll have to figure out which value MySQL uses for unique constraint violation. You can then test for that in your script. $dbh-{RaiseError} = 0; # don't die on error $dbh-do('insert into user (name) values ?', undef, $username); if ($DBI::err == 999) { # replace 999 with the correct error code! print Duplicate user\n; elsif ($DBI::err) { print Unexpected error: $DBI::errstr\n; } See perldoc DBI under the heading METHODS COMMON TO ALL HANDLES -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Premature end of script headers
[redirected to beginners-cgi list] zegdatwel wrote: hi, Premature end of script headers what can this mean...it's in the error log. When does this happen? I got error 500 when executing script. It means your script ended (normally or abnormally) before emitting a proper MIME header. The web server needs to find your response headers so it can add some of its own before sending the full response back to the client. For some reason, the server isn't finding the headers. This can be caused by: 1. Your script died for some reason. If an error message was output by perl or by your script, it should be in the web server's error log, so look there. 2. Your script is not emitting a proper MIME header. Lots of good information can be found at http://www.perl.org/CGI_MetaFAQ.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Date Range
Melissa Stranzl wrote: Hi all, This is part of a perl program I wrote that doesn't compile. I am trying to get my database to search by date- to have current and past events come up. Anyway, based on the following code, I get an error message that reads: can't locate object method new via package Date::Range package Date::Range; This should be use Date::Range. (I'm assuming you've also installed Date::Range from CPAN. If you haven't, do that too). The package statement is used when you're creating a module, not when you're using a prewritten one. my $range = Date::Range - new ($date1, $date2); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: add new piece of html code in perl not success:internal serve r error
-Original Message- From: eric [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 12, 2002 4:04 AM To: [EMAIL PROTECTED] Subject: add new piece of html code in perl not success:internal server error Dear perl users: I want to copy a piece of html code to my site, src=https://www.paypal.com/images/x-click-but6.gif; border=0 name=submit alt=Make payments with PayPal - it's fast, free and secure! /form tthen it just show nothing( a piece of white) then I tried to put \ before every then it have errror, Internal Server ERror Internal Server Error means: go check your web server error log. That's where the real error message will be. Also, make sure your script compiles: $ perl -c yourscript.cgi -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: including perl in html
(reply redirected to [EMAIL PROTECTED]) -Original Message- From: Adam Wilson [mailto:[EMAIL PROTECTED]] Sent: Tuesday, December 10, 2002 11:30 AM To: [EMAIL PROTECTED] Subject: including perl in html Hi, can anyone help me, i want to include the ouput of a perl file within an html file, without using a seperate frame. I am familiar with php, is there a way to include like there is in php? Or do i have to output the HTML from the perl script? You can use Apache's mod_ssi for a rudimentary capability: http://httpd.apache.org/docs/howto/ssi.html For more powerful solutions comparable to PHP, see HTML::Mason http://www.masonhq.com Embperl http://www.ecos.de/embperl/ Apache::ASP http://www.apache-asp.org/ Of these, I have personally used only HTML::Mason. Very slick. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Writeing a HTTP server with perl
[reply redirected to [EMAIL PROTECTED]] -Original Message- From: LRMK [mailto:[EMAIL PROTECTED]] Sent: Monday, December 02, 2002 11:57 AM To: [EMAIL PROTECTED] Subject: Writeing a HTTP server with perl I wrote a http server in perl to handle GET request from browser but browsers only send GET folder\filename HTTP X.Y request to the server how do i find which domain name that the user typed in the Address field. to implement hosts. The host name is sent as a Host: request header by HTTP 1.1 browsers You might also look at the HTTP::Daemon module, part of the libwww-perl distribution, which implements an HTTP server. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: fetchrow_hashref
-Original Message- From: T. Murlidharan Nair [mailto:nair;sdsc.edu] Sent: Thursday, November 14, 2002 2:22 PM To: [EMAIL PROTECTED] Subject: fetchrow_hashref Hi!! I am retriving data in a while loop using fetchrow_hashref How do I assign it to another hash. I am trying the following while (my %hashRef =$sth-fetchrow_hashref()){ fetchrow_hasref returns a hash reference, which is a scalar. You need to assign it to a scalar and dereference it. Using -w would have generated a warning about this. foreach $keys (keys %hashRef){ print $keys; print $hashRef{$keys}\t; } print \n; } Its does not return me anything. Please let me know if there is a better way to handle it. Try something like this: while (my $h = $sth-fetchrow_hashref) { for my $key (keys %$h) { print $key, '=', $h-{$key}, \n; } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: DBI / loop
-Original Message- From: Sven Bentlage [mailto:root;svenbentlage.de] Sent: Thursday, November 14, 2002 2:43 PM To: [EMAIL PROTECTED] Subject: DBI / loop Hi everyone! I have a small problem which should be very easy to solve, but right now I just do not understand where the mistake is: I`m using a small loop to fetch several hundred ids from a MySQL database, all of the ids are pushed into @id. After that the script fetches 1-3 email addresses for each id from another table. Directly after fetching the address it should send an email to each id (using only one of the max. 3 email addresses. The script works not completely. It fetches all ids, but sends only 50% of the mails... and I do not understand why.(The code is posted below.) If anyone could give me a tip what to change in ma script, I would be really grateful. Cheers, Sven @Wiggins: Thank you very much for your fast help! As soon as I have a working DBI Version i`ll post it. ### foreach $id(@id) { $k++; my $dbh2 = DBI-connect( $dsn, $db_user, $db_pass ) || die danger $DBI::errstr\n ; my $sth2 = $dbh2-prepare( select etpa_cont_e, cemail, pemail from memberscopy where id='$id' ); $sth2-execute(); while ( ($cont_e, $cemail, $pemail) = $sth2-fetchrow_array) { unless ($ETPA_cont_e eq ) { $recipient = $ETPA_cont_e } else { if ($pemail ne ) { $recipient = $pemail } elsif ($cemail ne ) { $recipient = $cemail } elsif (($pemail eq ) and ($cemail eq )) {$recipient = root\@svenbentlage.de} my $smtp = Net::SMTP-new($SMTP_Server); die could not connect to $SMTP_Server using $smtp\n unless $smtp; MIME::Lite-send('smtp', SMTP_Server, ^ This looks suspicious. Perhaps that should be $SMTP_Server? Also, why are you creating a Net::SMTP object that never gets used? Timeout=90); my $msg = MIME::Lite-new( #To = $recipient, To ='[EMAIL PROTECTED]', #change to recipient From ='$sender, ReplyTo = $reply_to, Subject = $subject, Type='multipart/related', Encoding = '8bit' ); $msg-attach(Type = 'text/html', Data = qq{ $mailtext } ); $msg-send(); $smtp-dataend(); $smtp-quit(); if ($k == 828) {die();} } $sth2-finish(); $dbh2-disconnect(); } thx(); -- 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]