Solved

strip and keep the first five data inputs

Posted on 2007-03-26
5
234 Views
Last Modified: 2010-03-05
Hi all

I would like to strip and keep the first five data inputs. The array length may vary then sample.

array Input: |data1|data2|data3|data4|data5|data6|data7|data8|data9|data10|data11

Result: data1|data2|data3|data4|data5

0
Comment
Question by:blnukem
  • 3
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
perl -lpe 's/\|*(([^|]*\|){4}[^|]*).*/$1/'
0
 
LVL 1

Accepted Solution

by:
midrisi earned 250 total points
Comment Utility
Below code snippet will do what you like.This array can be expanded also.

@array=("data1","data2","data3","data4","data5","data6","data7","data8","data9","data10");

foreach $res (0..4)
{
        push(@result,$array[$res]);
}
print @result;
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 250 total points
Comment Utility
@result=@array[0..4];
0
 
LVL 1

Expert Comment

by:midrisi
Comment Utility
So modified code is

@array=("data1","data2","data3","data4","data5","data6","data7","data8","data9","data10");

@result=@array[0..4];

print @result;
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
I thought you wanted to print "data1|data2|data3|data4|data5" given input "|data1|data2|data3|data4|data5|data6|data7|data8|data9|data10|data11"
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now