in reply to Re: Bogus variable to avoid 'split' warning
in thread Bogus variable to avoid 'split' warning
...and don't forget that you're counting something slightly different.
tabcount( "a\tb\tc", 'three fields' ); tabcount( "a\tb\t", 'two fields, trailing tab' ); tabcount( "\tb\tc", 'two fields, leading tab' ); sub tabcount { my ( $tabby, $descr ) = @_; print "*** $descr ***\n"; printf "scalar split %d\n", scalar split( /\t/, $tabby); printf "tr/\\t/: %d\n", $tabby =~ tr/\t//; }
Output:
*** three fields *** scalar split 3 tr/\t/: 2 *** two fields, trailing tab *** scalar split 2 tr/\t/: 2 *** two fields, leading tab *** scalar split 3 tr/\t/: 2
|
|---|