On 4/5/07, Glenn Booth <[EMAIL PROTECTED]> wrote:
snip
My failed approach so far:
"While" loop to read file line by line
"Split" each line using delimiter (pipe in this case)
Put the text fields into an array
"Shift" each element out of the array
Run a regex to upper case the first character
Shift element back into array
Why shift and unshift? Just use a for loop:
#!/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"
}
We don't even really need the for loop; it is just there if we want to
avoid processing a field later. That means we can make a really short
one liner:
perl -pe 's/\b(.)(.*?)\b/\u$1\L$2/g' file
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/