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 7996801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:47:46+00:00 2026-06-04T14:47:46+00:00

Instead of writing: @holder = split /\./,hello.world; print @holder[0]; is it possible to just

  • 0

Instead of writing:

@holder = split /\./,"hello.world"; 
print @holder[0];

is it possible to just do a one-liner to just get the first element of the split? Something like:

print (split /\./,"hello.world")[0]

I get the following error when I try the second example:

print (...) interpreted as function at test.pl line 3.
syntax error at test.pl line 3, near ")["
  • 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-06-04T14:47:48+00:00Added an answer on June 4, 2026 at 2:47 pm

    You should have tried your hunch. That’s how to do it.

    my $first = (split /\./, "hello.world")[0];
    

    You could use a list-context assignment that grabs the first field only.

    my($first) = split /\./, "hello.world";
    

    To print it, use

    print +(split /\./, "hello.world")[0], "\n";
    

    or

    print ((split(/\./, "hello.world"))[0], "\n");
    

    The plus sign is there because of a syntactic ambiguity. It signals that everything following are arguments to print. The perlfunc documentation on print explains.

    Be careful not to follow the print keyword with a left parenthesis unless you want the corresponding right parenthesis to terminate the arguments to the print; put parentheses around all arguments (or interpose a +, but that doesn’t look as good).

    In the case above, I find the case with + much easier to write and read. YMMV.

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

Sidebar

Related Questions

Instead of writing too many sql statements in each servlet I just want to
People keep telling me instead of writing shift 1 bit to the left, just
I'm just getting started on writing functions instead of writing everything inline. Is this
instead of writing code in the standard way: $.get('test.xml',function(){ //manipulate the code here })
Instead of writing the SQL query, is there any lazy way to get the
Instead of writing int i = new int(); i = 7; One can write
Is it possible to write a code segment and call it, instead of writing
Possible Duplicate: Why C# is not allowing non-member functions like C++ Instead of writing
For example, instead of writing the following: element * .../my_branch_01/LATEST element * .../base_branch/LATEST -mkbranch
Instead of writing one of these for every file I want to serve could

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.