in reply to Bogus variable to avoid 'split' warning

Use tr/\t// to count tabs, instead of split. Then you won't have the warning.

update: yes, this miscounts trailing tabs. But the original spec was a bit fuzzy. {grin}

Replies are listed 'Best First'.
Re^2: Bogus variable to avoid 'split' warning
by kyle (Abbot) on Feb 16, 2007 at 20:18 UTC

    ...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