Re: [regexp] Multi-level pattern matching

2006-04-21 Thread Adam W
Chad Perrin wrote: Y'know, I was playing around with this to see if I could come up with a reasonably elegant solution, and I noticed a problem: Your code doesn't seem to actually work. Am I missing something? I went back to check, and it seems to only be working in very specific cases. For

[regexp] Multi-level pattern matching

2006-04-21 Thread Adam W
Hello List, I'm writing a little script that will turn some webpages I have from HTML to XHTML. This requires several substitutions. So far, I have been able to write regexps that properly close link, meta, br, and hr tags and either put in or replace an existing tag. Finally, I want it t

Re: [Subroutine Optimization] Shift vs. @_

2006-04-10 Thread Adam W
Thanks, everyone, for the thoughtful replies. I do have a followup question (see below). Jay Savage wrote: ($str1, $str2, $str3) = (shift, shift, shift); @d = [EMAIL PROTECTED]; On the other hand resizes @_. Now you only have one copy of each value in memory. For a large list, this ma

[Subroutine Optimization] Shift vs. @_

2006-04-09 Thread Adam W
Hello List, I was wondering when it is appropriate to do multiple shifts on parameters passed to a subroutine and when it is appropriate to just feed it @_. For example, you have: &fancy_sub($a, $b, $c, @d); Is it better (I'm leaving this term vague on purpose) to write: sub fancy_sub {

Does anyone have "coconet.dat"?

2006-03-09 Thread Adam W
Hello All, I'm going through Schwartz's _Learning Perl Objects, References, and Modules_. One of the exercises at the end of chapter 5 (I think), requires a file called "coconet.dat" which is just a bunch of made up data to practice autovivification, anonymous referencing, etc. The file is

Re: [regexp] Speaking of the /s modifier...

2006-03-07 Thread Adam W
Hans Meier (John Doe) wrote: Adam W am Mittwoch, 8. März 2006 00.49: Sorry, I'm relatively new to programming in general (perl is my first programming language), so I'm not sure what you mean by "sanitizing." Could also be "sanitising", saw both :-) I&#x

Re: [regexp] Speaking of the /s modifier...

2006-03-07 Thread Adam W
Hans Meier (John Doe) wrote: Adam W am Dienstag, 7. März 2006 23.16: Hans Meier (John Doe) wrote: just to sum up: $test =~ s{ (.*?) \( (.*?) \) } {$1}xsg; - "\(" instead of "[(]": more readable - no /m modifier : unnecessary with

Re: [regexp] Speaking of the /s modifier...

2006-03-07 Thread Adam W
Hans Meier (John Doe) wrote: Adam, just to sum up: $test =~ s{ (.*?) \( (.*?) \) } {$1}xsg; - "\(" instead of "[(]": more readable - no /m modifier : unnecessary without ^/$-anchors - /s : may be appropriate for your html source text :-) Hans The contex

Re: [regexp] Warnings on Backreferences

2006-03-06 Thread Adam W
JupiterHost.Net wrote: $text =~ s!(.*?)\((.*?)\)!$1!g; Thanks for the help and the more streamlined regexp. An even better way (see O'reilley's "Perl Best Practices" by Damian Conway - buy this book you will write better code) Is to make it extremely readable with xms :) Same exact

Re: [regexp] Warnings on Backreferences

2006-03-06 Thread Adam W
John W. Krahn wrote: Adam W wrote: Here is an example of one of my regexps that produces this warning: $text =~ s!(.*?)(\()(.*?)(\))!\1<\/a>!g; BTW, why capture $2 and $4 if you are not using them and why is everything backslashed? Since I'm relatively new to the language,

[regexp] Warnings on Backreferences

2006-03-06 Thread Adam W
Hello All, I'm using '-w' like any good hacker, but every time I try to use backreferences in my regexps, I get a warning "\1 better written as $1 at" I'm confused because, according to perlretut: "Although $1 and \1 represent the same thing, care should be taken to use matched variable