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

  • Home
  • SEARCH
  • 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 504345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:29:14+00:00 2026-05-13T06:29:14+00:00

In the following example: my $info = ‘NARIKANRU’; my @first_one = split /,/, $info;

  • 0

In the following example:

my $info = 'NARIKANRU';
my @first_one = split /,/, $info;
print "$first_one[$#first_one]$first_one[$#first_one-1]\n";

The output is:

NARIKANRUNARIKANRU

I am not sure if this is correct because there is only one element in @first_one and $#first_one is the index of that element.

Given that $#first_one is not equal to $#first_one - 1, why is the single element in @first_one being printed twice?

  • 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-13T06:29:14+00:00Added an answer on May 13, 2026 at 6:29 am

    The output is correct. There are no commas in $info so split returns a list consisting of a single element.

    $#first_one is the index of the last (and in this case also first and only) element of @first_one. With a single element, $#first_one is 0. Therefore, $first_one[$#first_one] is $first_one[0].

    Also, $first_one[$#first_one-1] is $first_one[-1], i.e. the short hand way of referring to the last element of an array.

    Of course, things would not have worked out this way had $[ been set to some other value than the default. Apparently, things work unless $[ is negative.

    See also perldoc perldata.

    Finally, you ask if there is anything wrong in your code. From what I can see, you are not using strict and warnings. You should.

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

Sidebar

Related Questions

In the following example from wsgi.org is cur_named copied: def __call__(self, environ, start_response): script_name
I have a query like the following that returns the correct number of rows
Warning: Please treat me like the rookie I am. This is my first real
Edited:: Hi All, I have a XML file like this, <message> <c1> <rrcConnectionSetupComplete> <rrc-TransactionIdentifier>2</rrc-TransactionIdentifier>
I have the following hierarchy: Graduate.cpp (abstract) College.cpp (abstract) Ecollege.cpp University.cpp (abstract) Tuniversity.cpp Huniversity.cpp
I'm getting the following error when I attempt to compile my XCode project to
I have the following MySql Table: -------------------------------------------- Table 'category' -------------------------------------------- category_id name parent_id 1
Is it possible to create a popup without being based on a div. Example,
In C# 3.0 you can create anonymous class with the following syntax var o1
I'm using jQuery to parse XML which is retrieved via ajax, however I have

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.