What is the difference between:

a.                                      while(defined(my $line = <>)) ...

and

b.                                      while(<>)
                                


On Apr 6, 2007, at 7:52 AM, Rob Dixon wrote:


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

s/(\S+)/\u\L$1/g;

Rob


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




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


Reply via email to