Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

Perl range operator and printing of array

I was trying to populate an array with 100 elements having the values 1 through 100.  But I can not print out the contents of the array.  See the actual result I get below.  Am I using the correct sytax?  I am executing this with Strawberry Perl in Win 7.  Thank you for any insight.

@fred=[1..100];
print @fred;

The output:

C:\\perl_data>perl knit8.pl

ARRAY(0x39e6e8)
0
amigan_99
Asked:
amigan_99
  • 3
  • 2
1 Solution
 
ozoCommented:
@fred=(1..100);
print @fred;
#or
@fred=[1..100];
print @{$fred[0]};
0
 
amigan_99Network EngineerAuthor Commented:
Your method worked printing all the elements in a ray with no space in between the values.
I tried also print "@fred"; - but this did not work either.
0
 
ozoCommented:
@fred=(1..100);
print "@fred";
#or
@fred=[1..100];
print "@{$fred[0]}";
#or
@fred=(1..100);
print "$_\n" for @fred;
0
 
amigan_99Network EngineerAuthor Commented:
So that last one worked the best. And the central issue would appear to be using paren to contain the .. defined range as opposed to square brackets.  With the brackets I had the same weird ARRAY(hex) output.  When defined with parens even the simple print "@fred";
works and formats properly.  Thank you.


@fred=(1..100);
print "$_\n" for @fred;
0
 
ozoCommented:
print "$_\n" for @fred;  # or    $"="\n"; print "@fred\n";
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now