Replace local $_ = undef; with local $/ = undef; This undefines the input record separator which is what you want when you want to slurp a whole file into an array.
Wags ;) -----Original Message----- From: Perl [mailto:perl@;codyartsupply.com] Sent: Thursday, November 14, 2002 13:58 To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: can't read in whole file Hi Paul, Thank you for taking the time to help. >> foreach my $fileName (@list) { >> chomp($fileName); >> my $duhFileName = $fileName; >> #okay, I need help with scope too :-) > >You sure you didn't just misspell the variable name? >It's case sensitive..... with the '$duhFileName' scope problem/work around, it 'went away' on my newest attempt so I not sure why it was there. I had copied and pasted it to ensure the names where identical... oh well I'll figure that one out when I inadvertently repeat it... > >> if (open SEARCH_FILE, "< $fileName") { >> my $searchData = join "", <SEARCH_FILE>; >> close SEARCH_FILE; > >ok, $searchData should be the whole file, but maybe it's the line-based >read you're doing. A less attractive but more efficient way is > > if (open SEARCH_FILE, "< $fileName") { > local $_ = undef; > $searchData = <SEARCH_FILE>; > } > >That slurps it all in as one big scalar read. okay, I switched it to: if (open SEARCH_FILE, "< $fileName") { local $_ = undef; my $searchData = <SEARCH_FILE>; .....and I get the same problem: I added: print "$fileName is "; print length($searchData); print " characters long.<br>\n"; and the output on a text length test reads: C:\[clip]\retail\Account Purchases Spreadsheet.wks is 179 characters long. C:\[clip]\retail\Account Purchases Spreadsheet.xlr is 6 characters long. C:\[clip]\retail\All Brush Prices Printout.xlr is 6 characters long. >From windows, the file properties show the file sizes (not disk space used) are: Account Purchases Spreadsheet.wks is 1.54 KB (1,587 bytes) Account Purchases Spreadsheet.xlr is 10.5 KB (10,752 bytes) All Brush Prices Printout.xlr is 51.0 KB (52,224 bytes) ..... this is what is messing up my head. I can dump the data from the first file into my code editor, and save it as text, and get a new size: C:\[clip]\retail\Account Purchases Spreadsheet.txt is 561 characters long. It is indeed pulling the first 6 characters 'DIa!?' correctly - but just cutting it off there. Do I need to read it as a binary file or something, and convert it to ASCII? >> >> if ($searchData =~ /(\w*\s*\w*$search\w*\s*\w*)/i) { > >ouch. \w*\s*\w*$search\w*\s*\w* ?? > >That's zero or more word chars followed by zero or more whitespaces >followed by zero or more word chars followed by the search pattern >followed by zero or more word chars followed by zero or more >whitespaces followed by zero or more word chars. Is there a compelling >reason you can't just say /$search/i and then use "$`$&$'" ???? I >realize it's not exactly the same, but all those asterisks work the >regex engine pretty hard..... yeah, it's ugly. my goal is to grab a word or two just before and just after the matched text to display the context within which the search found the info. Any optimizing tips are appreciated. It's not production or cgi code, so while I want to do it the best way, I'm trying to just get better results than the pitiful file search tools built into XP (don't laugh) > >I don't suppose /([\w\s]+$search[\w\s]+)/i is specific enough either? > >Sorry, that may sound critical, which I don't mean. It's just a lot of >backtracking if it isn't absolutely necessary. > hey, critical is good. Any thoughts on this partial file read? It's bending my brain out of whack. Thanks >__________________________________________________ >Do you Yahoo!? >Yahoo! Web Hosting - Let the expert host your site >http://webhosting.yahoo.com > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ********************************************************** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. **************************************************************** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]