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

when I am trying to print array on local machine with
$no_of_elements = @content,
I am getting the length of array.
But when I am trying same server, it does not work and I dont get any output. Why is that ?
  • Comment on printing array in scalar context does not work on server

Replies are listed 'Best First'.
Re: printing array in scalar context does not work on server
by cdarke (Prior) on Aug 08, 2011 at 12:23 UTC
    Either a local machine or a server should produce the same output, given the same code. The fact that an array in scalar context gives the number of elements does not vary. Like a law of mathematics it holds true for all places in time and space (assuming the same version of perl).

    Most likely the code is slightly different in each case, the following, for example, give different results:
    print 'Array:'.@content."\n"; print 'Array:',@content,"\n";
Re: printing array in scalar context does not work on server
by Khen1950fx (Canon) on Aug 08, 2011 at 05:46 UTC
    Using Array::PrintCols:
    #!/usr/bin/perl use strict; use warnings; use Array::PrintCols; my @content = qw( 123 456 789 012 345 678 901 ); my $size = scalar @content; print"Array size: $size\n"; print_cols \@content, -1, 0, 1;