CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Laurent_R] A file parsing and 2D array/matrix problem.: Edit Log



rushadrena
Novice

Sep 10, 2012, 2:42 PM


Views: 2224
Re: [Laurent_R] A file parsing and 2D array/matrix problem.

Hi Laurent and Chris I didnt see that coming. I have fixed that error by introducing this

Code
splice(@dirs, 0, 1);

Now I have this huge file matrix.txt(I have snipped the file so as to contain only 2x5 matrices for a concise view) which I have to further process : Simultaneously one by one splitting and processing

Code
Processing  
10011
01010
Processing
11110
01010
Processing
11100
00110
Processing
10010
11001
Processing
11110
00001
Processing
11010
00110
Processing
10101
01010
Processing
00111
11100
Processing
11010
11111


What I want is to go through this list in a selection of three.

1. After the first occurrence pattern "Processing" i have 2 lines.Save these 2 lines in a separate file.save the file size of this file in variable "a"

2. After 2nd occurrence of "Processing", I have 2 lines.Save these 2 lines in a separate file.save the file size of this file in variable "b"

3. After 3rd occurrence of "Processing", I have 2 lines.Save these 2 lines in a separate file.save the file size of this file in variable "c"
Now I'd perform an operation $a+$b/$c >> RESULT.txt.

Then select other triplet i.e. 4th,5th and 6th occurence of "Processing" save the calculation to RESULT.txt and so on.

[EDIT:] I did tried these two codes, but they dont cater to the triplet selection

Code
 perl -ne 'BEGIN{ $/="Processing"; } if(/^\s*(\S+)/){ open(F,">$1.out")||warn"$1 write failed:$!\n";chomp;print F "gi", $_ }'



Code
awk -vRS="Processing" '{ print $0 > "file"t++".out" }' matrix.txt



(This post was edited by rushadrena on Sep 10, 2012, 2:58 PM)


Edit Log:
Post edited by rushadrena (Novice) on Sep 10, 2012, 2:58 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives