Thank you, but I tried and tested substr and unpack functions. These are not working. Because our input data is not a fixed-column format. Some of columns have whitespace characters and substr and unpack functions ignore these whitespace characters and pick up next columns...

The pack and substr functions don't ignore white spaces. But given that they work with positions within the string, they may have trouble solving mixtures of whites spaces and tabulations (because a tab takes only one position in a string, but usually several on the printed line). This is at least my hypothesis # 1, by far the most likely in my eyes. But you could also have some other nasty invisible characters (backspace and what not), which we cannot guess with the copy and paste that you are providing so far.

We really need to know exactly and in detail what you raw file looks like (unformated). Either make the file available by some means so that we can download it and look at it, or possibly supply an hex dump of it (although this is less practical).

Meanwhile, you could also try to split your records on single tabs, rather than spaces, and see what you get. Changing your original code to something like this:

@fields = split /\t/, $line;

It might just be the solution.


In reply to Re: To split with spaces by Laurent_R
in thread To split with spaces by gorkemsarikaya

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.