http://qs1969.pair.com?node_id=313223

Rudif has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I wanted get the number of fields found by split into a scalar, and I got it, but with a warning thrown in

#!/usr/bin/perl -w use strict; my $str = "a,b,c,d,e"; my $n = split ',', $str; print "$n\n"; Use of implicit split to @_ is deprecated at H:\dev\perl\perlmonks\spl +it-it.pl line 4. 5
perlfunc says this

In scalar context, returns the number of fields found and splits into the @_ array. Use of split in scalar context is deprecated, however, because it clobbers your subroutine arguments.

OK, that's helpful.

But what is the best way to get rid of this warning? I came up with these two so far

my @n = split ',', $str; $n = @n; print "$n\n"; $n = @{[ split ',', $str ]}; print "$n\n";
Any other ideas?

Rudif