Search this site

Metadata

Articles

Projects

Presentations

Array enumeration in perl

I got bored and thought this atleast marginally useful:

my @foo = qw(just another perl monkey);
my $x = 0;
print join("\n",map { $x++ . ": $_" } @foo);

The output is:

0: just
1: another
2: perl
3: monkey
If you don't know how to use map() then learn, it makes doing large operations on hashes or arrays brutally simple.

0 responses to 'Array enumeration in perl'

Showing last 0 comments... (Click here to view all comments)


Leave a reply

You need javascript enabled to use this form. Anti-spam efforts ongoing. Also, if the comment doesn't show up, it's because the form expired. Go back and copy your comment, reload the form, and resubmit. Apologies if this is a hassle, I'm just playing with antispam methods right now. If this insists on not working, please email me about it.

Name (required)
E-mail (optional, if you want me to be able to email you back)
URL (also optional)
Comment: