Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing parts of a string

Status
Not open for further replies.

jerehart

Programmer
Jun 10, 1999
61
US
Hey I need help parsing data, here is what it looks like (this is a single line from the input file):

1189: 4m56.5 23.55us ..00C904 ....6010 WORD WRI OK .......---- --- ....

to split up the data I am using:

@data = split (/[\ \t\n\-]+/,$_);

which returns:

{1189:,4m56.5,23.55us,..00C904,....6010,WORD,WRI,OK,......,.....};

I want to remove even more I do not want all of the ....+ strings and I don't want the ".." infront of valid data. This is what I would like:

{1189:,4m56.5,23.55us,00C904,6010,WORD,WRI,OK}

I have tried adding in [\.\.]*, (\.(\.)) into the split but this does not work.
I use a next if to get rid of 1189: and WORD, WRI, OK.

Any ideas on how ro remove the extra .. from my data?
 
Add this somewhere after the split.
Code:
@data = map { s/(?<!\d)\.//g; $_ } @data;
It will remove every '.' that is not preceeded by a digit.

jaa
 
Code:
@data = split(/[\s-][\s-.]*/, $_);

The separator are 'space' or '-' characters followed by any number of 'space', '-' or '.' characters.
A separator can not start with a '.' so the '.' not preceded by a 'space' or '-' are not removed.

The following:
Code:
perl -e 'print &quot;{&quot;.join(&quot;,&quot;, split(/[\s-][\s-.]*/, &quot;1189: 4m56.5 23.55us ..00C904 ...6010 WORD WRI OK .......---- --- ....&quot;)) . &quot;}\n&quot;;'
gives me:
Code:
{1189:,4m56.5,23.55us,00C904,6010,WORD,WRI,OK}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top