in reply to Re^2: Perl 'grammar'
in thread Perl 'grammar'

Nice catch. A better version of the regex would be s/^\s*(\S+),\s+(\S).*$/${2}${1}/; - you don't want to assume too much about the item. That's why the ^\s*(\S+) instead of just ^(\S+).

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^4: Perl 'grammar'
by ysth (Canon) on Jan 09, 2008 at 08:35 UTC
      Assuming they don't also contain commas and always start and end with a non-space ... s/^\s*(\S(?:[^,]*\S)?)\s*,\s+(\S).*$/${2}${1}/; Update: Fix for ysth's objections.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?