Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Data extraction with specific keywords

by johngg (Canon)
on Jan 19, 2018 at 11:58 UTC ( [id://1207513]=note: print w/replies, xml ) Need Help??


in reply to Data extraction with specific keywords

When initialising your @arr1 array you could save a yourself a heap of fiddly and error-prone typing by using a map with the qw{ ... } quote words operator. E.g.

johngg@shiraz ~ $ perl -Mstrict -Mwarnings -MData::Dumper -E ' my @arr1 = map qq{$_:}, qw{ 91 86 184 430 }; print Data::Dumper->Dumpxs( [ \ @arr1 ], [ qw{ *arr1 } ] );' @arr1 = ( '91:', '86:', '184:', '430:' );

You might also make things easier for yourself (and any others maintaining your code) by using meaningful variable names rather than $c, $i or $j.

It is not clear from your description and your code exactly what you are trying to achieve. The "few" lines of data you posted seem to be in two sections headed "0" and "1" each having many lines of data in the form:-

0 2:-0.5795 3:0.33582025 4:55.8255 5:65.316997 ...

Please correct me if that is wrong. Your @arr1 appears to be a selection of the initial parts of the data lines in an apparently random order. Is this order to be preserved in your output file and do you want a separate output file for each section? Depending on the answers to these questions you might be better off using hashes rather than arrays.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found