Dear Monks,

I need you wisdom once again. Although that I have found an answer to my question, I need your skills to help me understand why the output is formatted like this.

I want to split a user input based on the length of characters.

Update

I modified the title, to actually describe better my question and to avoid confusion for future readers. The observation came from ww and thank you for the suggestion.

Sample of a working example is given bellow with the output as expected:

#! /usr/local/bin/perl use strict; use warnings; use Data::Dumper; my $input = "1234567890abcdefghij0987654321ABCDEFGHIJlmnop"; chomp $input; # A "A text (ASCII) string, will be space padded." my @chunks = unpack("(A10)*", $input); print Dumper(\@chunks); __END__ $VAR1 = [ '1234567890', 'abcdefghij', '0987654321', 'ABCDEFGHIJ', 'lmnop' ];

While I was trying different solutions in order to reach to the solution I thought about using split and regex. The program seems to be working correctly but I do get blank lines, why? I can not understand where I am going wrong. I tried to use chomp but as it looks like there are no trailing "new line" characters. Does anyone understands why this is happening?

Sample of working code provided under:

#! /usr/local/bin/perl use strict; use warnings; use Data::Dumper; my $input = "1234567890abcdefghij0987654321ABCDEFGHIJlmnop"; chomp $input; my @chunks = split(/(.{10})/,$input); print Dumper(\@chunks); __END__ $VAR1 = [ '', '1234567890', '', 'abcdefghij', '', '0987654321', '', 'ABCDEFGHIJ', 'lmnop' ];

Thank you all for your time and effort reading and replying to my question.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to How to split a string based on the length of a sequence of characters within the string by thanos1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.