in reply to Misprocessed Read From Files?
Currently I am trying to get PERL to read all of the lines in the first file, split them, and print one column. I also am trying to do the same using globbing for the other 250+ files. When I do either of these in isolation I can do this perfectly and generate exactly the results I need. However, when I combine the code...
I don't know what sort of output you really want to get when you "combine the code". I gather it has something to do with combining the two sets of data, and "complex searching", but... how would you describe/define that, exactly?
Writing a reduced output version of every input file is an okay thing to do, I guess, but how does it help in moving you toward to your real goal (whatever that is)? If you could reach that goal without writing all those output files, wouldn't that be better?
Apart from the very good advice given in the earlier replies, I would encourage you to pay attention to the visual appearance of your code: things like proper indentation and strategic use of an occasional blank line (to delimit logical chunks like loops and conditional blocks) can do wonders for making the code easier to manage and maintain. It does make a difference.
Also, this part of your code looks wrong -- maybe it works for you now, but I would not trust it:
Please look again at the docs for split. You can split to an array (much easier and less brittle that a long list of scalars), and/or you can limit the number of elements returned by split. Examples:($stamp,$extra,$orth,$a,...$z) = split(/ <|>;|\t/, $line1); #splitting all of the information after the first ";" into 2 scalars; $split = "$a ... $z"; ($canon,$spoke) = split(/; /, $split);
Bear in mind that something like the following would be a mistake, since the first array will take up all the results from split, and any subsequent variable(s) will be empty (undef):# split into two scalars and an array: ( $field1, $field2, @rest ) = split( /$separators/, $input_string ); # or split into three scalars, put everything after "$field2" into $re +st: ( $field1, $field2, $rest ) = split( /$separators/, $input_string, 3 + );
# wrong: ( @fields, $comment ) = split( /[\t#]/, $input_string );
|
|---|