| Developer's Daily | Perl Q&A Center |
| main | java | perl | unix | dev directory | web log |
| Question: | How do I print the entire contents of an array with Perl? |
|
Answer: To answer this question, we first need a sample array. Let's assume that you have an array that contains the name of baseball teams, like this:
If you just want to print the array with the array members separated by blank spaces, you can just print the array like this:
But that's not usually the case. More often, you want each element printed on a separate line. To achieve this, you can use this code:
In many examples you'll see the variable
In the terrific book, Programming Perl, the authors recommend another way to print the entire contents of an array. I think it's a little more difficult to understand, but that's just *my* opinion - and the Perl motto is "There's More Than One Way To Do It" - so here it is:
If you run one of these last two examples, you'll get this result:
cubs reds yankees dodgers
|
Copyright © 1998 DevDaily Interactive, Inc.
All Rights Reserved.