Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6768639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:05:54+00:00 2026-05-26T15:05:54+00:00

I am starting to learn Perl and this is just a basic little for

  • 0

I am starting to learn Perl and this is just a basic little for loop for which I get a strange output and was hoping for some clarity on this.

@numbers = {1,4,5,6,7,8,9};
for(my$i = 0; $i<=$#numbers; $i++)
{
    print ("$numbers[$i}\n");
}

the output is HASH(0x23a09c).

What does this actually mean and why do I get this result.

regards
Arian

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:05:54+00:00Added an answer on May 26, 2026 at 3:05 pm

    You want this:

    @numbers = (1,4,5,6,7,8,9);
    foreach my $number (@numbers)
    {
        print ("$number\n");
    }
    

    With {1,4,5,6,7,8,9} you’re actually creating a reference to an anonymous hash containing the key value pairs (1 => 4, 5 => 6, 7 => 8, 9 => undef). When you write @numbers = {1,4,5,6,7,8,9}; that reference becomes the sole scalar stored in the @numbers array.

    Furthermore, if you just want to iterate over the elements, no need to use the “classic” style with a counter.

    You can do:

    for my $number (1 .. 9) {
        print "$number\n";
    }
    

    Make sure you have use strict; and use warnings; at the beginning of every Perl script you write. Those directives enable perl to catch errors and warn about certain possibly erroneous code. As a beginner, you might want to couple those with warnings with diagnostics to get more detailed information.

    These are very handy, especially when starting out with Perl as they help you prevent shooting yourself in the foot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For those just starting to learn WCF , what are the major/basic things I
I am just starting to learn Python, but I have already run into some
I am just starting to learn scala, and perhaps I am a little ambitious.
Hi just starting to learn this language, more of a javascript/PHP guy... I can't
Just starting to learn the Java side of things, sorry if this is obvious.
Just starting to learn ASP.NET (C#) and I am using Visual Studio 2008. I
I am just starting to learn javascript, so I don't have the skills to
im just starting to learn flex and im trying to understand how Flex does
I'm starting to learn ASP.Net MVC (the release candidate), and I'm having a little
I'm starting to learn perl, using the Wrox Beginning Perl available on perl.org and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.