Your code does not make sense.

Assuming, I don't know number of elements in @sss
The number of elements in @sss is just @sss in a scalar context: my $number_in_array_sss = @sss;

my $number_in_array_sss = @sss; print scalar(@sss). " ". $num\n";
UPDATE: more code below:
#!/usr/bin/perl -w use strict; use Data::Dumper; my @sss = ("1","3","4"); my $reee = []; foreach my $entry (@sss) { push (@$reee, $entry); } # this is to show various uses of scalar() and that # the dot (concatenation) operator forces scalar context print "\$ree has ",scalar(@$reee)," elements\n"; print "\$ree has ".@$reee." elements\n"; print ''.@$reee." elements\n"; print "each element is: @$reee \n"; print Dumper \$reee; #PRINTS: #$ree has 3 elements #$ree has 3 elements #3 elements #each element is: 1 3 4 #$VAR1 = \[ # '1', # '3', # '4' # ]; # To accomplish the above is only one Perl statement!! # No "foreach" or "for" loop is needed, 3 lines of code # becomes one line of code. I do not count blank lines # or lines with just braces "{}" as "lines of code". my @aaa = (1,5,7); # like @sss, repeated for clarity # and using different numbers. my $bbb = [@aaa]; # this means: # allocate some memory and assign its # reference to $bbb. # The array, @aaa is copied to that # memory referenced by $bbb. print Dumper \$bbb; #prints #$VAR1 = \[ # 1, # 5, # 7 # ];

In reply to Re: How to find number of elements of an array from array reference by Marshall
in thread How to find number of elements of an array from array reference by chakreey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.