exodius Posted June 12, 2006 Share Posted June 12, 2006 I've been wondering, what's more efficient for reading the contents of a file? 1. Reading a file to an array using _FileReadToArray ( "file.txt", $array ) 2. $file = FileOpen ( File.txt", 0 ) 3. Something else I'm not thinking of? Link to comment Share on other sites More sharing options...
herewasplato Posted June 12, 2006 Share Posted June 12, 2006 I've been wondering, what's more efficient for reading the contents of a file?1. Reading a file to an array using _FileReadToArray ( "file.txt", $array )2. $file = FileOpen ( File.txt", 0 )3. Something else I'm not thinking of?Well 1 and 2 do not do comparable things.Your "option 2" returns the handle of the opened file.If you meant 2. $file = FileRead...thenIt depends on what you want to do with the info. If you just want to check to see if a string exists in the file, then you might not need to place it into an array.If you want/need the info in an array and if you are going to check @error and the return value from _FileReadToArray - then it is best to use it. If you are not going to check the values set by the UDF, then don't use it. You can just use the one line of code that is the core of that UDF.$aArray = StringSplit(FileRead("File.txt")), @LF)not tested, but requires beta [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
exodius Posted June 12, 2006 Author Share Posted June 12, 2006 Well 1 and 2 do not do comparable things.Your "option 2" returns the handle of the opened file.If you meant 2. $file = FileRead...thenIt depends on what you want to do with the info. If you just want to check to see if a string exists in the file, then you might not need to place it into an array.If you want/need the info in an array and if you are going to check @error and the return value from _FileReadToArray - then it is best to use it. If you are not going to check the values set by the UDF, then don't use it. You can just use the one line of code that is the core of that UDF.$aArray = StringSplit(FileRead("File.txt")), @LF)not tested, but requires betaMy intention anytime I do this is to read the contents of the file, parsing out the text that I need... so with that detail in mind... Link to comment Share on other sites More sharing options...
herewasplato Posted June 12, 2006 Share Posted June 12, 2006 ...read the contents of the file, parsing out the text that I need...Sorry, I don't mean to be a pain, but "parsing out" is not enough info of what you want to do for me to comment on your question... and now that I think about it, I'm going to assume that efficient means the fastest executing code and not quickest for you to write.If you have some HTML that you want to "parse out" part of the body, then I would not read the info to an array. I would read it into a variable and then trim left and right using StringInStr.You might want to post a little sample of the data that you want to read in and then explain what you want to do with it.No one method is going to be the most efficient for all situations. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
nfwu Posted June 12, 2006 Share Posted June 12, 2006 It depends on the format of the file that you want to read. #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 12, 2006 Moderators Share Posted June 12, 2006 StringRegExp() is generally better and more efficient if it is specific text you want to find. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now