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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:16:24+00:00 2026-05-15T16:16:24+00:00

What is a good way in Perl to split a line into pieces of

  • 0

What is a good way in Perl to split a line into pieces of varying length, when there is no delimiter I can use. My data is organized by column length, so the first variable is in positions 1-4, the second variable is positions 5-15, etc. There are many variables each with different lengths.

Put another way, is there some way to use the split function based on the position in the string, not a matched expression?

Thanks.

  • 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-15T16:16:25+00:00Added an answer on May 15, 2026 at 4:16 pm

    Yes there is. The unpack function is well-suited to dealing with fixed-width records.

    Example

    my $record = "1234ABCDEFGHIJK";
    my @fields = unpack 'A4A11', $record;  # 1st field is 4 chars long, 2nd is 11
    
    print "@fields";                       # Prints '1234 ABCDEFGHIJK'
    

    The first argument is the template, which tells unpack where the fields begin and end. The second argument tells it which string to unpack.

    unpack can also be told to ignore character positions in a string by specifying null bytes, x. The template 'A4x2A9' could be used to ignore the "AB" in the example above.

    See perldoc -f pack and perldoc perlpacktut for in-depth details and examples.

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

Sidebar

Related Questions

Anyone knows a good way to use http live streaming tools on non-Mac platforms?
What is a good way of writing something like this in one line. The
Is there a good way to keep keys from conflicting when using the Microsoft
Is there a good way to start at a given index and move BACKWARDS
perl -E '$i=@{[`zypper lr`]}-2;map{`zypper rr $_`}1..$i' What would be a good way to write
What is a good way to create and read an OpenOffice spreadsheet in Perl?
In Perl, what is a good way to perform a replacement on a string
In perl debugger I can use DB::get_fork_TTY() to debug both parent and child process
In Perl, is there any way to tell which .pl script has initialized this
I'm using PHP from the command line and I'm trying to embed data into

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.