Hi,

Chas Owens wrote:

Why shift and unshift?  Just use a for loop:

I was trying to constrain any replacements to just the
two text fields, and to actively ignore all others -
I should have made that clearer in the original post.

In other words, if the line of text was this:

0097138 | BOOK TITLE | A book about dogs | 4.99 |

I was trying to operate on the fields containing
"BOOK TITLE" and "A book about dogs" while ensuring
the first and last fields remain unchanged. In the
case I cited, those are numerical fields, but I
didn't want to take that for granted, just in case.

#!/usr/bin/perl
use strict;
use warnings;

while (defined (my $line = <>)) {
       chomp $line;
       my $record;
       for my $field (split /\|/, $line) {
               $field =~ s/\b(.)(.*?)\b/\u$1\L$2/g;
               $record .= "$field|";
       }
       print "$record\n"
}

That works a treat, by the way - thanks.

perl -pe 's/\b(.)(.*?)\b/\u$1\L$2/g' file

... and so does that!

Best regards,

Glenn.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to