Krambambuli has asked for the wisdom of the Perl Monks concerning the following question:
I expected to print out the same field count - 8 - regardless of applying or not the 'chomp'. Instead, I see 8 and 4. Can someone shed some lite on it ? Why do the two field counts differ ..?!!#!/usr/bin/perl use strict; use warnings; my $line ="A\tB\tC\tD\t\t\t\t\n"; print "Test string line: $line"; print "Split without chomp: "; count_fields( $line ); print "Split _after_ chomp: "; chomp $line; count_fields( $line ); exit; sub count_fields { my ($line) = @_; my @x = split( /\t/, $line); my $count = @x; print "$count fields.\n"; }
|
|---|