Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Perhaps this is a newbie question, but please be kind. I'm a newbie.
Given the following code:
I get the following output:my @array = qw/zero one two three/; print @array, $/; print "@array\n"; print "${@array}\n";
Without resorting to something akin to the following:14:38:57 ~/perl/source $ perl -w array zeroonetwothree zero one two three 14:38:59 ~/perl/source $
...which upon output yields:my @array = qw/zero one two three/; my $n = scalar @array; print "$n\n";
How can I modify the interpolated string such that the element count of the list/array is substituted instead of the array contents?14:44:42 ~/perl/source $ perl -w array 4 14:44:49 ~/perl/source $
Thanks.
Janitored by Arunbear - replaced pre tags with code tags, as per Monastery guidelines
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: forcing array to scalar context in string interpolation?
by borisz (Canon) on Oct 20, 2004 at 21:57 UTC | |
|
Re: forcing array to scalar context in string interpolation?
by BrowserUk (Patriarch) on Oct 20, 2004 at 22:01 UTC | |
|
Re: forcing array to scalar context in string interpolation?
by kvale (Monsignor) on Oct 20, 2004 at 21:56 UTC | |
|
Re: forcing array to scalar context in string interpolation?
by qumsieh (Scribe) on Oct 20, 2004 at 23:16 UTC | |
|
Re: forcing array to scalar context in string interpolation?
by TedPride (Priest) on Oct 21, 2004 at 04:34 UTC |