Thanks - you are right that I want to open these files in order that I will under some logical conditions write a data line to them. One of my data items per line is indeed a $sector value and I will breakd down the data by $sector, outputting each line of input to the relevant output file per sector.
My thinking was to use the following but it looks like you are advising me to insert curly braces which I will try although I don't really understand why this would make a difference and why print would have a problem sending a string to a file handler without curly braces...
$mydata=<INPUT>;
while(<INPUT>){
#Handle data file line by line splitting it at every new line \n
my(@data)=split/\n/,$_;
#Now lets go through the whole input data file line by line
for($i=0;$i<@data;$i++){
$mydata=$data[$i];
if($mydata=~/^Blah$some_regex(\d+)$some_more_regex_perhaps/){
#Get the sector value which is listed in each matching line of data
$DataSector=$1;
#Output line of matching data to output file for the relevant sector
print $fh[$dataSector] "$mydata\n";
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.