[sf-perl] RE oddity

Rich Morin rdm at cfcl.com
Wed Feb 15 13:23:58 PST 2006


At 12:59 PM -0800 2/15/06, Quinn Weaver wrote:
>     # Punt weird characters.
>     $line =~ s|[\000-\010\012-\037\177-\377']||g;
>     #            ^^^^^^^  ^^^^^^^^ ^^^^^^^ ^
>     #            nul-      nl-      del-   ' (single quote)
>     #            backspace whatever ...,

I like the general approach.  Here's my variant:

  $line =~ s|[\000-\010\012-\037\177-\377']||g;  # Remove weird chars.
  #           <-------><-------><------->^
  #            nul-bs   nl-us    del-... ' (single quote)

> Finally, I would change "Punt" to "Ignore", since not everyone
> understands US football metaphors.

I agree about not using slang; that one slipped in.

> PS:  If you're interested in optimizing for maintainability,
> Damian's _Perl Best Practices_ is a great place to start.

Yes, excellent book.  I was amused to find that I had been using
an unnecessary construct for several years:

  while (defined($line=<FILE>)) {

Apparently, recent versions of Perl silently wrap a defined into
certain constructions such as:

  while ($line=<FILE>) {

-r
-- 
Technical editing and writing, programming, and web development:
  http://www.cfcl.com/rdm/resume

Contact information: rdm at cfcl.com, +1 650-873-7841


More information about the SanFrancisco-pm mailing list