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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:32:45+00:00 2026-06-17T04:32:45+00:00

If I want to extract only the 4th, 5th, and 7th elements (say) of

  • 0

If I want to extract only the 4th, 5th, and 7th elements (say) of tab-separated record, I can do something like:

my @f = (split(/\t/, $_, -1))[3, 4, 6];

But what if I want the 4th element and the “tail slice” consisting of all elements from the 7th one to the end of the array? I don’t know how to do this in a single line. The best I can do is this:

my @f = split(/\t/, $_, -1);
@f = @f[3, 6..$#f];

The only reason for doing this operation in two lines is so that I can specify $#f in the second line, but this entails a greater degree of specificity than is inherent in the task; the task does not really care how many elements are in the value returned by split. It’d be nice to be able to specify something like “everything available from the 7th element onwards”… This is what I mean by a “tail slice”: a slice where only the starting point is specified, while the end point is left implicit.

(This sort of specification is commonplace in uses of the cut utility in Unix; e.g.:

... | cut -f 4,7-

)

Is there some subscripting expression that I can apply directly to the (split(...)) subexpression to produce in one line the same effect as is achieved by the last two lines of code above?

EDIT: To be clear, what I’m trying to avoid is the $#ARRAY construction. I know that I can always do something like

my @f = do { my @t = split(/\t/, $_, -1); @t[3, 6..$#t] };
  • 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-17T04:32:47+00:00Added an answer on June 17, 2026 at 4:32 am

    The expression in the brackets of a list slice must return a list of zero or more indexes. So you’d have to know the number of items in the list being sliced before it’s even produced. So no, it can’t be done using a list slice.

    The most direct way of accessing a list on the stack is via @_. This does require a sub call, but it does give you an easy mechanism for leaving the list on the stack.

    my @f = sub { @_[6..$#_] }->( split(/\t/, $_, -1) );
    

    Note that this solution does not create an array and copy the values into that array like the code in you’ve since added to your question.

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

Sidebar

Related Questions

For a simple division like 1/3, if I want to extract only the first
Let's say I have a string : {id:123,xCoord:01.234567,yCoord:89.012345,etc.:etcetc} I want to extract only the
If I want to extract only 7.20 from $ 7.20, how can I do??
I have string like the following 'TextBoxKunde85_3_0', and i want to extract only the
I want to extract only the leaf nodes from an XML document (i.e., only
I have some html files and want to extract only lines with containing these
I want to extract attribute1 and attribute3 values only. I don't understand why charset
I want to extract only the exact character in a CharSequence when I know
I want to extract only the files inside a folder of a tar file
I have a html file with three tables. But I want to extract only

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.