mrwawa wrote:
Hi all,
Hello,
I am new to Perl and am trying to do the following. I have a dataset file with the following example structure. ACRU 12 34 QUAL 28 90 QURU 3345 . . . . . QUVE 29 88 As you can see, line 3 only contains on 2 columns. "3345" is missing a tab. I have written code to loop through the file and locate those spots. What I would like to do is edit the rows in the data file that have< 3 columns by using substr(). However, when I read each line in as an array, the numeric values are stored as numbers and I am unable to parse them. For example $temp = substr(dat[0],0,2) works for the first element in the array, but $temp = substr(dat[1],0,2) does not work for the numeric values. I receive the error message, "Use of uninitialized value $dat[2] in string". Is there a way around this?
Your substr example says $dat[1] but your error message says $dat[2] so it looks like you are using an array entry that doesn't contain any data because there are only two fields.
You should change: $temp = substr($dat[2],0,2) To: substr($dat[1],2,0,"\t") Which will put a tab character between the second and third digits. John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/