Serving up a pdf file
All, I have a page with a link Quiz1. When the user clicks on the the link, a perl script will be summoned that will populate forms of a pdf document. Now, I could create a new page at this point with a link to the newly created pdf, but could someone suggest a technique where I simply send the pdf to the user after the pdf forms have been populated? Does that sound like a redirect or does someone have a better suggestion? Thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Serving up a pdf file
Phillip, Thanks, but this is not quite what I was looking for. When the user clicks on Quiz1 a perl script will be called to generate and compile a tex file using pdflatex. Once that is complete, I will have a file Quiz1.pdf which I want to send back to the user. Thanks. At 10:09 PM 7/21/04 +, Philipp Traeder wrote: On Wednesday 21 July 2004 HH:53:19, David Arnold wrote: All, Hi David, I have a page with a link Quiz1. When the user clicks on the the link, a perl script will be summoned that will populate forms of a pdf document. Now, I could create a new page at this point with a link to the newly created pdf, but could someone suggest a technique where I simply send the pdf to the user after the pdf forms have been populated? Does that sound like a redirect or does someone have a better suggestion? if I understand your problem correctly, you want to generate a pdf file when the user clicks a link, and when the pdf is generated completely, you want to send it back to him? If yes, just create the pdf file on the fly and send it back - I don't know how to generate pdf files in perl, therefore I'll just give you an example that creates a text file (untested, for demonstration only): #!/usr/bin/perl -w use strict; use CGI; my $query = new CGI(); # print the header (you need to modify this to the correct content-type for pdfs) print $query - header(-type = 'text/plain'); for (my $loop = 1; $loop = 10; $loop++) { print line $loop\n; } If you execute this as CGI script, the user will receive a text file that he can save. I think you should be able to do the same for PDFs. HTH, Philipp -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Perl and XML::Simple
All I tried to run this: #! /usr/local/bin/perl -w # File: Responses.pl use strict; use warnings; # Import the SML::Simple module use XML::Simple; use Data::Dumper; # Turn the file into a has reference, using XML::Simples' XMLin # subroutine. We'll also turn on the 'forcearray' option, so that all # elements contain arrayrefs. my $resp_xml=XMLin('./Responses.xml',forcearray=1); print Dumper $resp_xml; On this file: [EMAIL PROTECTED] perlxml]# cat -A Responses.xml results id=Quiz1 file=Quiz1.pdf n=3question n=1 type=mc ptype=2.1 points=1 credit=0 correct=0valuea/value/questionquestion n=2 type=mc ptype=5.4 points=1 credit=0 correct=0valuea/value/questionquestion n=3 type=mc ptype=3.6 points=1 credit=0 correct=1valuea/value/question/results$ [EMAIL PROTECTED] perlxml]# And I got this error message: [EMAIL PROTECTED] perlxml]# ./Responses.pl Not a quote character [Ln: 1, Col: 38] Can anyone help? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Order of evaluation
All, If I have: my $state={}; $state-{WORD}='affection'; $state-{GAMENO}=3; $state-{GUESSES}=3; Then, the following line puzzles me: my @[EMAIL PROTECTED](WORD GAMENO)}; How does the order of evaluation go here in order to populate @ary? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Order of evaluation
Charles et al, Certainly good advice, and I did print it out, so I do know what happens. %perl junk.pl affection3 Compilation finished at Fri Jul 16 20:02:43 It's just that I don't know why this happens. At 09:52 PM 7/16/04 -0500, Charles K. Clarkson wrote: David Arnold [EMAIL PROTECTED] wrote: : If I have: : : my $state={}; : $state-{WORD}='affection'; : $state-{GAMENO}=3; : $state-{GUESSES}=3; : : Then, the following line puzzles me: : : my @[EMAIL PROTECTED](WORD GAMENO)}; : : How does the order of evaluation go here in order to : populate @ary? Why not just print @ary and find out for yourself? Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
!$state
All, If: $state={}; Then, what is: !$state -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Tie::DBI
Bob, A good tip. Thanks. :-) At 08:31 AM 7/2/04 -0400, Bob Showalter wrote: David Arnold wrote: All, Never mind. It was a permissions problem. I downloaded the gz file, unzipped and untarred and read the installation directions and found the problem. For future reference, you can issue the look command from the CPAN shell: $ perl -MCPAN -e shell cpan look Tie::DBI This will download the tarball, untar it into a working directory and drop you into a shell in that directory. If you just want to look at the README file, you can use cpan readme Tie::DBI -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Tie::DBI
All, Tried to install Tie::DBI from CPAN but it failed to install. I got: cpan install Tie::DBI ... ... ... ... t/DBI.t 32 15 46.88% 9-11 13 15 17 21 23-27 30-32 t/RDBM.t 255 6528020 36 180.00% 3-20 Failed 2/2 test scripts, 0.00% okay. 33/52 subtests failed, 36.54% okay. make: *** [test_dynamic] Error 2 /usr/bin/make test -- NOT OK Running make install make test had returned bad status, won't install without force cpan I am using: [EMAIL PROTECTED] Apache]$perl -v This is perl, v5.8.4 built for i686-linux-thread-multi Anybody have an idea of how I can implement a successful install? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Tie::DBI
All, Never mind. It was a permissions problem. I downloaded the gz file, unzipped and untarred and read the installation directions and found the problem. Thanks, anyway. At 04:10 PM 7/1/04 -0700, David Arnold wrote: All, Tried to install Tie::DBI from CPAN but it failed to install. I got: cpan install Tie::DBI ... ... ... ... t/DBI.t 32 15 46.88% 9-11 13 15 17 21 23-27 30-32 t/RDBM.t 255 6528020 36 180.00% 3-20 Failed 2/2 test scripts, 0.00% okay. 33/52 subtests failed, 36.54% okay. make: *** [test_dynamic] Error 2 /usr/bin/make test -- NOT OK Running make install make test had returned bad status, won't install without force cpan I am using: [EMAIL PROTECTED] Apache]$perl -v This is perl, v5.8.4 built for i686-linux-thread-multi Anybody have an idea of how I can implement a successful install? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Here construct not working
All, For this: #! /usr/bin/perl -w # file: stein_test_DBI_table.pl use strict; use Tie::DBI (); my $DB_NAME = 'test_www'; my $DB_HOST = 'localhost'; my %test_users = ( 'root'= [qw(user,authors,admin 5 superman)], 'george' = [qw(users 3 jetson)], 'winnie' = [qw(user,authors,devel 3 thepooh)], 'andrew' = [qw(users 2 llama23)], 'fred'= [qw(users,devel 2 bisquet)], 'morgana' = [qw(users 1 lafey)] ); # Sometimes it's easier to invoke a subshell for simple things than to # use the DBI interface. open MYSQL, |mysql -h $DB_HOST -f $DB_NAME or die $!; print MYSQL END DROP TABLE user_info; CREATE TABLE user_info ( user_name char(20) primary key, passwd char(13) not null, level tinyint not null, groups char(100) ); END close MYSQL; I get this: [EMAIL PROTECTED] Apache]$perl -wc stein_test_DBI_table.pl Possible attempt to separate words with commas at stein_test_DBI_table.pl line 11. Possible attempt to separate words with commas at stein_test_DBI_table.pl line 11. Possible attempt to separate words with commas at stein_test_DBI_table.pl line 13. Possible attempt to separate words with commas at stein_test_DBI_table.pl line 13. Possible attempt to separate words with commas at stein_test_DBI_table.pl line 15. syntax error at stein_test_DBI_table.pl line 31, near close (Might be a runaway multi-line string starting on line 22) stein_test_DBI_table.pl had compilation errors. Can anyone see my error? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Here construct not working
John, Thanks. That's it. At 07:27 PM 7/1/04 -0700, John W. Krahn wrote: On Thursday 01 July 2004 18:59, David Arnold wrote: All, Hello, For this: #! /usr/bin/perl -w # file: stein_test_DBI_table.pl use strict; use Tie::DBI (); my $DB_NAME = 'test_www'; my $DB_HOST = 'localhost'; my %test_users = ( 'root'= [qw(user,authors,admin 5 superman)], 'george' = [qw(users 3 jetson)], 'winnie' = [qw(user,authors,devel 3 thepooh)], 'andrew' = [qw(users 2 llama23)], 'fred'= [qw(users,devel 2 bisquet)], 'morgana' = [qw(users 1 lafey)] ); # Sometimes it's easier to invoke a subshell for simple things than to # use the DBI interface. open MYSQL, |mysql -h $DB_HOST -f $DB_NAME or die $!; print MYSQL END ^ You forgot the semicolon at the end of the line. print MYSQL END; DROP TABLE user_info; CREATE TABLE user_info ( user_name char(20) primary key, passwd char(13) not null, level tinyint not null, groups char(100) ); END close MYSQL; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Nested {}
Japhy, Thanks. These suggestions worked great! At 01:18 AM 6/30/04 -0400, you wrote: On Jun 29, David Arnold said: \backans{If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can substitute to find a solution.} I'd like to scan the file and replace all of these with this format: \begin{answer} If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can substitute to find a solution. \end{answer} To match nested things, you probably want to use Regexp::Common, which allows you to do that very easily: use Regexp::Common; $text =~ s \\ backans { ( $RE{balanced}{-parens='{}'} ) } \\begin{answer}\n$1\n\\end{answer}xg; The /x modifier is so that I can have extra whitespace, and the /g modifier means do it globally. The %RE hash is quite magical -- see the Regexp::Common docs for an explanation. The module isn't standard, though, so you'd have to download it from CPAN yourself. If you want a stand-alone solution, you can have one if you make use of some of Perl's special regex constructs: my $rx; # must be declared first... $rx = qr[ (?: (? [^{}\\]+ | \\. ) | { (??{ $rx }) } )* ]xs; $text =~ s/\\backans{($rx)}/\\begin{answer}\n$1\n\\end{answer}/g; Its primary trick is the (??{ ... }) assertion, which evaluates its contents as PART of the regex to match. Since its contents are $rx itself, it basically creates an automatically deeply-enough nested regex for you on the fly. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN[Need a programmer? If you like my work, let me know.] stu what does y/// stand for? tenderpuss why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Searching ahead in a file
All, I have a file that is filled with exercises that was written in a brand of lamstex that I need to convert to latex. Exercises begin like this: \ex If $f(x)=x^2$, blah ... That is, I can count on each exercise beginning with the \ex macro. Now there are at times instructions for groups of exercises. They look like this: \begin{instructions} Blah, blah, blah, ... \end{instructions} As I begin reading in lines from the file, I just print them until I hit a line that has an opening \ex in it. At that point I want to accumulate lines in one long string until I hit either \begin{instructions} or another \ex. $line.=IN #unless the current line coming in from IN is the start #of a new \ex or a \begin{instructions} The difficulty is now I've read one line too many. I'd like to put this last line back for the next round of reading while I process the accumulated exercise lines. Is there a standard way of handling this difficulty? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Searching ahead in a file
Japhy et al, This worked perfectly for what I want to do. Thanks to all of you, I am learning at a greater rate than by working alone. Many thanks. At 04:32 PM 6/30/04 -0400, Jeff 'japhy' Pinyan wrote: On Jun 30, David Arnold said: As I begin reading in lines from the file, I just print them until I hit a line that has an opening \ex in it. At that point I want to accumulate lines in one long string until I hit either \begin{instructions} or another \ex. $line.=IN #unless the current line coming in from IN is the start #of a new \ex or a \begin{instructions} The difficulty is now I've read one line too many. I'd like to put this last line back for the next round of reading while I process the accumulated exercise lines. I would suggest the following approach: # some bigger loop while (...) { my $line = ; while (IN) { if (/\\ex|\\begin{instructions}/) { seek IN, -length, 1; last; } $line .= $_; } } This uses the seek() function to go to a position in the file. The last argument, 1, means we're moving relative to where we are now. The middle argument, -length, is the number of bytes to move. So if the line is 20 characters long, we're going 20 characters back from where we are now, essentially to the start of the line. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN[Need a programmer? If you like my work, let me know.] stu what does y/// stand for? tenderpuss why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Need suggestions
All, Being only moderately comfortable with Perl, I find myself in need of some direction on a more complex task. I have a tex file containing a large number of exercises shaped as follows: \ex This is the text of the exercise as it appears in the book. The exercise may have several parts. \pt This is the first part. \ans This is the solution to the first part. \endans \backans{This is the answer to the first part that goes in the back of the book. These are present only for the odd-numbered exercises.} \pt This is the second part. \ans This is the solution to the second part. \endans \backans{This is the answer to the second part that goes in the back of the book.} I need to change each of these into the following form: \begin{exer} \begin{exertext} This is the text of the exercise as it appears in the book. The exercise may have several parts. \begin{subenumerate} \item This is the first part. \item This is the second part. \end{subenumerate} \end{exertext} \begin{soln} \begin{subsoln} \item This is the solution to the first part. \item This is the solution to the second part. \end{subsoln} \end{soln} \begin{answer} \begin{subanswer} \item This is the answer to the first part that goes in the back of the book. These are present only for the odd-numbered exercises. \item This is the answer to the second part that goes in the back of the book. \end{subanswer} \end{answer} \end{exer} I am looking for suggestions on how to attack this assignment. Perhaps there are modules on CPAN that would help me of which I am not aware. Or, perhaps a kind soul will suggest an attack. Thanks. Any help appreciated. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Nested {}
All, Suppose I have a number of lines in a latex file like this: \backans{If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can substitute to find a solution.} I'd like to scan the file and replace all of these with this format: \begin{answer} If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can substitute to find a solution. \end{answer} I'm looking for suggestions as to how to make this change with my perl script. I am puzzled by the use of nested braces and how I can be sure I've got everything between the opening and closing brace. Thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Nested {}
Charles, Very nice indeed. I learned a lot with your example. Unfortunately, there are a lot of situations where the lines wrap. For example, \backans{Now is the time for all good men to come to the aid of their country. The domain of $f(x)=\sqrt{2x+3}$ is $\{x:\,x\ge -3/2\}$.} Do you have similar good advice for the wrapping situation? At 09:18 PM 6/29/04 -0500, Charles K. Clarkson wrote: David Arnold [EMAIL PROTECTED] wrote: : Suppose I have a number of lines in a latex file like this: : : \backans{If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can : substitute to find a solution.} : : I'd like to scan the file and replace all of these with : this format: : : \begin{answer} : If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can substitute : to find a solution. : \end{answer} : : I'm looking for suggestions as to how to make this change : with my perl script. I am puzzled by the use of nested : braces and how I can be sure I've got everything between : the opening and closing brace. As long as the lines do not wrap, you don't need to worry about the nesting. Perl regexes are greedy by default. So '.+' will try to suck in the longest match possible. Which is just what you want. while ( DATA ) { printf \\begin{answer}\n%s\n\\end{answer}\n, $1 if /^\\backans{(.+)}/; } __END__ \backans{If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can ...} \backans{If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can ...} \backans{If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can ...} \backans{If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can ...} HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response