Stripping HTML code from emails
Hi Guys, I'm writing some code that basically checks a pop mailbox and puts the information into a mysql database, however if the person sends an email in HTML format it looks messy, I am looking for a perl module that will convert it to plain text or just strip the HTML. Does anyone have any ideas on a module to-do this? Thanks, Richard
Using DBI in a web context
I have a couple forms for an in-house application. The user fills out the fields and then submits which update a back end Oracle database. I have looked for examples but can't really find anything. How is it best to catch errors when doing DBI stuff in web applications? Wrap the insert code in an eval statement? Croak or die statements? I am thinking eval because I can set autocommit to off and then do rollbacks if $@ has an error. Suggestions? Robert -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Round to mult. of 5?
Does anyone have a routine that will round an integer to a multiple of 5? For example: if number ends in 0 or 5, no rounding is done. If number ends in 1,2 the ones place rounds down to 0. If number ends in 3,4 the ones place rounds up to 5. If number ends in 6,7 the ones place rounds down to 5. If number ends in 8,9 the ones places rounds up to 0 and tens places goes up by 1. Examples: Number Rounded 1628 1630 1625 1625 1621 1620 1610 1610 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: Best book to update XML via Perl?
In article [EMAIL PROTECTED], [EMAIL PROTECTED] says... Hi, I have Perl 5.6.0 on Solaris, and on DOS. We have an XML document that has many prices in it that need to be changed. They are keyed by part number, and each part has a price grade, each grade has a price. I know there are many tools that Perl can use to update XML. Which one is the most straight forward? Let me rephrase. I now have Perl 5.8.7 on Windows/DOS. I have been using Perl to manipulate text files for 5+ years. But I don't get into anything too complicated. I do use arrays and hashes when needed but I usually don't need hash files or use references. I know basic XML but have not programmed any language to manipulate XML files. I'm looking for a book to use Perl and one of it's XML modules to change data in an XML file. I have been reading the included docs for XML::XPath (I managed to install XML::XPath after upgrading my ActivePerl for Windows) and they are not suited for a beginner. They provide abstract syntax examples but no concrete real-world examples. Thus I don't know if a parameter is a scalar, hash, or array, or reference to hashed arrays, or an array of referenced hashes... It also does not explain what a nodeset is in the context of Perl. Which book would get right to the point and clearly illustrate how to search for and change data in an XML document? I hope I'm clear I'm no Perl guru as I'm not familiar with Perl references and the XML::XPath seems to use a lot of them. Thank you. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Round to mult. of 5?
C.R. wrote: Does anyone have a routine that will round an integer to a multiple of 5? For example: if number ends in 0 or 5, no rounding is done. If number ends in 1,2 the ones place rounds down to 0. If number ends in 3,4 the ones place rounds up to 5. If number ends in 6,7 the ones place rounds down to 5. If number ends in 8,9 the ones places rounds up to 0 and tens places goes up by 1. $ perl -le' for my $num ( 1600 .. 1630 ) { print $num, \t, int( ( $num + 2 ) / 5 ) * 5 } ' 16001600 16011600 16021600 16031605 16041605 16051605 16061605 16071605 16081610 16091610 16101610 16111610 16121610 16131615 16141615 16151615 16161615 16171615 16181620 16191620 16201620 16211620 16221620 16231625 16241625 16251625 16261625 16271625 16281630 16291630 16301630 John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Round to mult. of 5?
C.R. wrote: Does anyone have a routine that will round an integer to a multiple of 5? For example: if number ends in 0 or 5, no rounding is done. If number ends in 1,2 the ones place rounds down to 0. If number ends in 3,4 the ones place rounds up to 5. If number ends in 6,7 the ones place rounds down to 5. If number ends in 8,9 the ones places rounds up to 0 and tens places goes up by 1. Examples: Number Rounded 1628 1630 1625 1625 1621 1620 1610 1610 Hi Chuck How about this: use strict; use warnings; for my $n ( qw/1628 1625 1621 1610/ ) { print $n, ' ', round5($n), \n; } sub round5 { my $n = shift() + 2; $n - $n % 5; } **OUTPUT** 1628 1630 1625 1625 1621 1620 1610 1610 HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
code issue
All, I have been working on this script to extract information based on group selection, being E0, GE, E5. This works fine however I am testing the selection to see if E$ is entered and it so escape the $ in the process. Am I missing something because it never finds E$ in any of the files I'm parsing and I know its in there. On a side note my opt's never error out to tell the use the correct usage, I could swear that the code is correct. Thanks for the help! Tim use strict; use Getopt::Std; use vars qw($opt_s $opt_d $opt_g $opt_t); my $source; my $dest; my $grp; my $typ; if (! getopts('s:d:g:t:')) { die Usage: cmeparser -s -d -g -t\n; } if ($opt_s) { $source = $opt_s; } if ($opt_d) { $dest = $opt_d; } if ($opt_g) { $grp = $opt_g; } if ($opt_t) { $typ = $opt_t; } open (CME, $source) or die Can't open file: $!\n; open (CAT, $dest) or die Can't open file: $!\n; while (CME) { if ( $grp =~ /E\$/) { $grp = E\$; } else { next; } if ( substr($_, 69,2) =~ /($grp)/) { if ( substr($_, 91, 2) =~ /($typ)/) { print CATUS; } } }
Re: Round to mult. of 5?
C.R. wrote: Does anyone have a routine that will round an integer to a multiple of 5? Didn't find anything on CPAN? Odd... A search for Round - http://search.cpan.org/search?query=Roundmode=all Yeilded Math::Round, nearest() looks promising. For example: if number ends in 0 or 5, no rounding is done. If number ends in 1,2 the ones place rounds down to 0. If number ends in 3,4 the ones place rounds up to 5. If number ends in 6,7 the ones place rounds down to 5. If number ends in 8,9 the ones places rounds up to 0 and tens places goes up by 1. Examples: Number Rounded 1628 1630 1625 1625 1621 1620 1610 1610 Thanks! You've already written the logic :) Now just change it from english to Perl, say in a nice fast easy to follow and maintain ternary table like so: sub round_to_nearest_five { my $integer = int(shift); my $last = substr($integer, length($integer) - 1, 1); $integer += $last == 1 || $last == 6 ? -1 : $last == 2 || $last == 7 ? -2 : $last == 3 || $last == 8 ? 2 : $last == 4 || $last == 9 ? 1 :0 ; return $integer; } But use the module, its more flexible, reusable, consistent, in depth, etc etc :) HTH! -- Dan Muey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: code issue
On 11/8/06, Tim Wolak [EMAIL PROTECTED] wrote: $grp = E\$; if ( substr($_, 69,2) =~ /($grp)/) { Despite appearances, the string from the first statement doesn't contain a backslash. (Maybe you wanted to use qr// instead of double quotes? Or you could write the string with three backslashes: The first two make a real backslash, while the third escapes the dollar sign within the double quotes.) Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Round to mult. of 5?
On 11/7/06, C. R. [EMAIL PROTECTED] wrote: Does anyone have a routine that will round an integer to a multiple of 5? 1. Divide by five. 2. Round to the nearest integer. 3. Multiply by five. 4. Profit! Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Trying to understand this forking open stuff...
Hello all! I've come to a point where I really need to start understanding forking, threaded, select, and all that stuff. I created a test script to play around with and it's doing what I'd expect, except for one bit. My test script: use strict; use warnings; print First Trial:\n\n; if (open(CHILD, |-)) { print parent starts: , (scalar localtime),\n; sleep 5; print parent ends: , (scalar localtime),\n; } else { my $time = scalar localtime; print child starts: $time\n; exit; } print \nSecond Trial:\n\n; if (open(CHILD, |-)) { print parent starts: , (scalar localtime),\n; print CHILD printing to child\n; sleep 5; print parent ends: , (scalar localtime),\n; } else { my $time = scalar localtime; my $input = STDIN; print child starts: $time\n; exit; } __END__ My output looks like this: First Trial: parent starts: Wed Nov 8 13:45:14 2006 child starts: Wed Nov 8 13:45:14 2006 parent ends: Wed Nov 8 13:45:19 2006 Second Trial: parent starts: Wed Nov 8 13:45:19 2006 parent ends: Wed Nov 8 13:45:24 2006 child starts: Wed Nov 8 13:45:19 2006 I expected the first trial print statements to execute in the same order as the second trial print statements, but the child print statements don't do execute until after the parent process is over. It seems that the line (in the child process, second trial) my $input = STDIN; is blocking, but why? I would understand if I had a while () loop or something because that would be just sitting there waiting for input from the parent process. But STDIN is a one-shot deal that just looks for the input line delimiter, right? Once it hits \n shouldn't it just move on? Thanks to anyone who can offer any insight or point me in the right direction, Jen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Trying to understand this forking open stuff...
Jen Spinney wrote: Hello all! Hello, print \nSecond Trial:\n\n; if (open(CHILD, |-)) { print parent starts: , (scalar localtime),\n; print CHILD printing to child\n; sleep 5; print parent ends: , (scalar localtime),\n; } else { my $time = scalar localtime; my $input = STDIN; print child starts: $time\n; exit; } __END__ My output looks like this: First Trial: parent starts: Wed Nov 8 13:45:14 2006 child starts: Wed Nov 8 13:45:14 2006 parent ends: Wed Nov 8 13:45:19 2006 Second Trial: parent starts: Wed Nov 8 13:45:19 2006 parent ends: Wed Nov 8 13:45:24 2006 child starts: Wed Nov 8 13:45:19 2006 I expected the first trial print statements to execute in the same order as the second trial print statements, but the child print statements don't do execute until after the parent process is over. Order of execution is determined by the OS, not by your program. It seems that the line (in the child process, second trial) my $input = STDIN; is blocking, but why? Look carefully at the times displayed, it is not blocking. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Trying to understand this forking open stuff...
On 11/8/06, John W. Krahn [EMAIL PROTECTED] wrote: Jen Spinney wrote: Hello all! Hello, print \nSecond Trial:\n\n; if (open(CHILD, |-)) { print parent starts: , (scalar localtime),\n; print CHILD printing to child\n; sleep 5; print parent ends: , (scalar localtime),\n; } else { my $time = scalar localtime; my $input = STDIN; print child starts: $time\n; exit; } __END__ My output looks like this: First Trial: parent starts: Wed Nov 8 13:45:14 2006 child starts: Wed Nov 8 13:45:14 2006 parent ends: Wed Nov 8 13:45:19 2006 Second Trial: parent starts: Wed Nov 8 13:45:19 2006 parent ends: Wed Nov 8 13:45:24 2006 child starts: Wed Nov 8 13:45:19 2006 I expected the first trial print statements to execute in the same order as the second trial print statements, but the child print statements don't do execute until after the parent process is over. Order of execution is determined by the OS, not by your program. It seems that the line (in the child process, second trial) my $input = STDIN; is blocking, but why? Look carefully at the times displayed, it is not blocking. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall John, Thanks for your reply. The times that were printed show that the two processes are definately starting in parallel -- it's not that I think one is finishing before the other one starts. Perhaps a better demonstration would be this code: use strict; use warnings; print First Trial:\n\n; if (open(CHILD, |-)) { print parent starts: , (scalar localtime),\n; sleep 5; print parent ends: , (scalar localtime),\n; } else { print child starts: , (scalar localtime),\n; print child ends: , (scalar localtime),\n; exit; } print \nSecond Trial:\n\n; if (open(CHILD, |-)) { print parent starts: , (scalar localtime),\n; print CHILD printing to child\n; sleep 5; print parent ends: , (scalar localtime),\n; } else { print child starts: , (scalar localtime),\n; my $input = STDIN; print child ends: , (scalar localtime),\n; exit; } __END__ Order of execution is determined by the OS, not by your program. I know that the OS determines which one of two processes that are happening at virtually the same time will be executed. But, there is a five second pause in my first example before it would print 'child starts'. This more recent code should demonstrate this more clearly. Or maybe I've misunderstood you? Here is the output from the newer script: First Trial: parent starts: Wed Nov 8 14:58:26 2006 child starts: Wed Nov 8 14:58:26 2006 child ends: Wed Nov 8 14:58:26 2006 parent ends: Wed Nov 8 14:58:31 2006 Second Trial: parent starts: Wed Nov 8 14:58:31 2006 child starts: Wed Nov 8 14:58:31 2006 parent ends: Wed Nov 8 14:58:36 2006 child ends: Wed Nov 8 14:58:36 2006 (the child ends 5 seconds later... it waits for the parent to end... why?) - Jen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Trying to understand this forking open stuff...
On 11/8/06, Jen Spinney [EMAIL PROTECTED] wrote: use strict; use warnings; print First Trial:\n\n; if (open(CHILD, |-)) { print parent starts: , (scalar localtime),\n; sleep 5; print parent ends: , (scalar localtime),\n; } else { print child starts: , (scalar localtime),\n; print child ends: , (scalar localtime),\n; exit; } print \nSecond Trial:\n\n; if (open(CHILD, |-)) { print parent starts: , (scalar localtime),\n; print CHILD printing to child\n; sleep 5; print parent ends: , (scalar localtime),\n; } else { print child starts: , (scalar localtime),\n; my $input = STDIN; print child ends: , (scalar localtime),\n; exit; } __END__ I know that the OS determines which one of two processes that are happening at virtually the same time will be executed. But, there is a five second pause in my first example before it would print 'child starts'. This more recent code should demonstrate this more clearly. Or maybe I've misunderstood you? There are a couple of things going on here. First, the issue of what prints when is driven by buffering. Since you haven't turned on autofulsh on any of your file handles, the buffer is flushed whenever it's convenient for the the system. The results may be more what you expect if you print to STDERR instead of STDOUT. This also looks to be the culprit in your second example. You print to the child, but you never do anything to guarantee the buffer is flushed, so the child doesn't see the \n on STDIN until Perl automatically reaps the filehandle and flushes the buffer when the parent tries to exit. In this case, turn on autoflush on CHILD and see if you don't get something more like your expected result. HTH, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!
Re: Trying to understand this forking open stuff...
On 11/8/06, Jen Spinney [EMAIL PROTECTED] wrote: print CHILD printing to child\n; sleep 5; Concurrent processes can be counterintuitive at times. Because the CHILD filehandle is buffered, that line won't necessarily be sent to the child process right away. In your program, I'd expect it to be sent only once the filehandle is closed (i.e., when the parent process exits). If you use the $| variable, or otherwise flush the output buffer before sleep, I think you'll get results more to your liking. Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Hi everyone, who can tell me how to extract five texts on each side of an URI? Thanks
Hello, everyone, Recently, when I want to implement Chakrabarti's algorithm using Perl, I found it difficult for me to extract five texts on each side of an URL. I can make my program do its job at last, but it runs slowly. Can anybody tell me how to improve the running speed of this program? Thanks. Below is the Chakrabarti's article: http://www.cs.berkeley.edu/~soumen/doc/www2002m/p336-chakrabarti.pdf Good luck! Hui Wang - Mp3疯狂搜-新歌热歌高速下
Re: Trying to understand this forking open stuff...
On 11/8/06, Jay Savage [EMAIL PROTECTED] wrote: There are a couple of things going on here. First, the issue of what prints when is driven by buffering. Since you haven't turned on autofulsh on any of your file handles, the buffer is flushed whenever it's convenient for the the system. The results may be more what you expect if you print to STDERR instead of STDOUT. This also looks to be the culprit in your second example. You print to the child, but you never do anything to guarantee the buffer is flushed, so the child doesn't see the \n on STDIN until Perl automatically reaps the filehandle and flushes the buffer when the parent tries to exit. In this case, turn on autoflush on CHILD and see if you don't get something more like your expected result. HTH, -- jay On 11/8/06, Tom Phoenix [EMAIL PROTECTED] wrote: On 11/8/06, Jen Spinney [EMAIL PROTECTED] wrote: print CHILD printing to child\n; sleep 5; Concurrent processes can be counterintuitive at times. Because the CHILD filehandle is buffered, that line won't necessarily be sent to the child process right away. In your program, I'd expect it to be sent only once the filehandle is closed (i.e., when the parent process exits). If you use the $| variable, or otherwise flush the output buffer before sleep, I think you'll get results more to your liking. Cheers! --Tom Phoenix Stonehenge Perl Training Thanks Jay and Tom! I added this little bit to my script: select (CHILD); $| = 1; select (STDOUT); and it worked just as I expected it to. It's interesting, though, that I've been working with sockets a bunch through IO::Socket and my print statements seem to print to the socket stream immediately. Is a good practice to set the autoflush to one for socket filehandles as well? Thanks again, Jen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Re: Trying to understand this forking open stuff...
On 11/8/06, Jen Spinney [EMAIL PROTECTED] wrote: Thanks Jay and Tom! I added this little bit to my script: select (CHILD); $| = 1; select (STDOUT); and it worked just as I expected it to. It's interesting, though, that I've been working with sockets a bunch through IO::Socket and my print statements seem to print to the socket stream immediately. Is a good practice to set the autoflush to one for socket filehandles as well? Thanks again, Jen That depends; try 'perldoc IO::Socket' and see what pops up. The version I currently have installed says in big letters: NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE As of VERSION 1.18 all IO::Socket objects have autoflush turned on by default. This was not the case with earlier releases. NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE Yours may say something different. It's usually a good idea to read the perldoc for any module you use. HTH, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!
Re: Round to mult. of 5?
In article 31086b240611080714m228f0808hfb07ccff550f33d6 @mail.gmail.com, [EMAIL PROTECTED] says... 1. Divide by five. 2. Round to the nearest integer. 3. Multiply by five. 4. Profit! Now that's very clear, with no obscure Perlese code. 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: Hi everyone, who can tell me how to extract five texts on each side of an URI? Thanks
Recently, when I want to implement Chakrabarti's algorithm using Perl, I found it difficult for me to extract five texts on each side of an URL. No one can give helps unless he also know this special algorithm. -- Books below translated by me to Chinese. Practical mod_perl: http://home.earthlink.net/~pangj/mod_perl/ Squid the Definitive Guide: http://home.earthlink.net/~pangj/squid/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Trying to understand this forking open stuff...
Thanks Jay and Tom! I added this little bit to my script: select (CHILD); $| = 1; select (STDOUT); and it worked just as I expected it to. It's interesting, though, that I've been working with sockets a bunch through IO::Socket and my print statements seem to print to the socket stream immediately. Is a good practice to set the autoflush to one for socket filehandles as well? Currently the IO::Socket is auto-flushed,so you maybe don't need to flush it again. When you write to/read from a pipe,you can always use syswrite/sysread instead,since syswrite/sysread avoid the IO buffer in Perl (it's in C's stdio indeed). -- Books below translated by me to Chinese. Practical mod_perl: http://home.earthlink.net/~pangj/mod_perl/ Squid the Definitive Guide: http://home.earthlink.net/~pangj/squid/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Hi everyone, who can tell me how to extract five texts on each side of an URI? Thanks
On Thursday 09 November 2006 01:33, 辉 王 wrote: Hello, everyone, Recently, when I want to implement Chakrabarti's algorithm using Perl, I found it difficult for me to extract five texts on each side of an URL. I can make my program do its job at last, but it runs slowly. Can anybody tell me how to improve the running speed of this program? Thanks. Below is the Chakrabarti's article: http://www.cs.berkeley.edu/~soumen/doc/www2002m/p336-chakrabarti.pdf If you give an example input url, the desired output of that url, and your slow but working code people might be able to help you. -- Bjørge Solli - Office:+47 55205847 Mohn-Sverdrupsenteret, Nansensenteret, Høyteknologisenteret T47 Thormöhlensgate 47, 5006 Bergen, Norway - www.nersc.no Google Earth: www.nersc.no/GE - TOPAZ: topaz.nersc.no -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response