![]() |
| ||
| array problem - help! Ok, I am about to pull all my hair out. I have written many many perl scripts and have done it all pretty much. All of a sudden, I have hit a real problem, and I DON'T know why! I am doing a very simple array declaration by reading a text file into an array. open (FILE, $file_var); Pretty simple stuff, huh!? I have used this same routine hundreds of times. But for some reason, declaring the array with "my" is resulting in an empty array! If I just declare it with "@contents=<FILE>", it works fine! Why on earth is this happening? I even declared another array using the same format in the same SCRIPT, and it works fine, but this particular array is turning up empty EVERY time! I hope someone can help me! Derek |
| ||
| Re: array problem - help! - did you actually open the file? - does the file you actually opened contain any data? - does another approach to reading the same file yield data? 3 lines out of context, and an information-free story doesn't help. |
| ||
| Re: array problem - help! Quote:
|
| ||
| Re: array problem - help! OK this is getting stupider by the moment. I set path like so: $path_to_file="path/file.txt"; If the file exists (need to verify that the file exists before continuing), then read the data into the array, otherwise create the file: if (-e $path_to_file) Tada! The array is EMPTY! However, if i remove the "if exists" check from around the routine to read data into array, it works! Why!? |
| ||
| Re: array problem - help! Well the 'my' exists inside a { } scope, so I guess it goes out of scope when the block exits. |
| ||
| Re: array problem - help! Quote:
Yep, thats probably the reason. my @contents = (); |
| All times are GMT -4. The time now is 5:49 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC