Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: To split with spaces

by Cristoforo (Curate)
on Aug 04, 2013 at 20:13 UTC ( [id://1047823]=note: print w/replies, xml ) Need Help??


in reply to To split with spaces

If it looks like:
1234 2321 0 45 1st 2122 sdsa 0 0 34 2313 dsad 43 2nd 1232 ffff 0 0 1st 3213 sadf 0 34 2133 dada 0 2nd
with fixed width columns, you could use unpack or substr to parse it. If the columns are tab separated, you could split on tab.

Chris

Replies are listed 'Best First'.
Re^2: To split with spaces
by gorkemsarikaya (Novice) on Aug 05, 2013 at 01:13 UTC
    Firstly, thank you for your kind and smart answer.

    You are right data is not obvious, sorry for this, I am not familiar with html codes. My input data is exactly as you predicted:

    1234 2321 0 45 1st 2122 sdsa 0 0 34 2313 dsad 43 2nd 1232 ffff 0 0 1st 3213 sadf 0 34 2133 dada 0 2nd

    As it is seen, there is different number of spaces between columns. So /\s/ is not working as well as /\s+/ is not working, because some columns have whitespace characters. Also substr function does not work due to same reason. Substr does not see whitespace character and passes to next column. I hope told my problem clearly:)

      To answer your question, it is necessary to know more about your data. There are 6 columns and in your sample the third and fourth columns are 0 or blank. Is it possible that they could be a 2 or 3 digit number, like 33 or 123? Is the fifth column always a 2 digit number like 45, 34, 43... or could it be 1 digit (or 3 digits)? Its hard to tell with this data whether fields fill in from the left or right.

      And I'm guessing that the leading whitespace before the 1st column isn't really there, but is just the way you pasted it in.

        This is a small piece example data of our real data which is a telecommunication company parameters. So yes, third and fourth columns can also be between 0-100; and fifth column can be 0-300. Sequenly, from third column to last column, there can be blanks. Finally, leading whitespace before the 1st column isn't really there. Please help me, I should split those columns exactly. Problem I cannot pick up blanks, instead of that I can pick up next columns' values. That s the point. Substr or solutions that given from are not working.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1047823]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-28 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found