Which should return a number for myarray[1], but it returns the number I want, followed by a newline, followed by either a one or a zero. The above code works for pulling all other numbers from my textfile, so I don't have any reason to believe it wouldn't work for this particular situation, although my newness to Perl could explain why I don't know what's going on. The line of text I am reading looks something like:

The #s stand for a sequence of nine numbers, I thought that would be clear. Is it possible that there is some hidden numbers? This is a data file generated by a program, and I am not sure how the file is generated, but it looks like just a plain text file. However, when I run the code I posted (which appears to be the same as your post), I get (again, #s represent numbers):

######### 1 (or 0)

for myarray[1]

This is on two lines, and when I try:

Code

$time = $myarray[1]

I get $time = 1 (or 0), which is not what I want. I tried treating myarray as a multidimensional array:

We need to see a complete program that demonstrates the error. Please run the code (exactly as posted) that I posted previously. Verify that it works correctly. Modify it so it fails in the way you describe. Post the modified program. If the original fails, or you are unable to make it fail, show us exactly what you tried. Post complete examples that we can run! Good Luck, Bill

Every line of your failing example is the same as one in my working example. The difference must be in the part you are not showing us. Post complete programs that we can run and debug. Good Luck, Bill

As you can see, I get my first variable (ID) correctly, and it starts to pull the second variable (Time), but then adds a newline and a 1 (or a 0, later in the running). The newline and 1 are NOT visible in the input file.

Much better, but I still cannot duplicate the problem. All we need for a complete script is the print statements that display the bad results.

It now seems that you intend to merge data from two lines of input to create one line of output. Your for statement repeats this pattern for all the data in the file.

One problem is that $count starts at one. This ignores the first line of data which is in $line[0] and later reads one element past the end of @line (a likely source for your strange characters.). Good Luck, Bill

You precisely said the number on the end is what you want and it varys in length. From your code, you're joining each line's end numbers together with " ". I've adapted my code to the way you write it, so if that is the case try this and see if it works out for you.

Before I go about posting my entire script (only because it is on a different computer not connected to the Internet), is there a way to see if there are hidden characters in my input file? That way I can see if there is something that is being captured at the end of that line that I can't see.

The best way to check you data file for unexpected whitespace or non-printing characters is to examine it with a hex editor. Next best thing is your text editor. (It probably has a mode to display non-printing characters). So far three of us have posted code that "works" with made-up data. Try all of them with real data. Even if they are not exactly what you want, they could validate your data. If the data is bad, fix a sample of it and try again. Let us know what happened.

I Think that it much more likely that the problem is in your code rather than your data. It may eventually be necessary to post your entire script, but not yet. Much better to add print statements to the script that you already posted. This will show us (and you!) exactly what is failing and when. Good Luck, Bill