Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-24 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found