recentpopularlog in

kme : inputoutput   18

perlfaq5 - Files and Formats - metacpan.org | https://metacpan.org/

Whenever you see someone do this:
<code class="language-perl">my @lines = <INPUT>;</code>

You should think long and hard about why you need everything loaded at once. It's just not a scalable solution.

If you "mmap" the file with the File::Map module from CPAN, you can virtually load the entire file into a string without actually storing it in memory:
<code class="language-perl">
use File::Map qw(map_file);
map_file my $string, $filename;
</code>

Or you can read the entire file contents into a scalar like this:
<code class="language-perl">
my $var;
{
local $/;
open my $fh, '<', $file or die "can't open $file: $!";
$var = <$fh>;
}
</code>

That temporarily undefs your record separator, and will automatically close the file at block exit. If the file is already open, just use this:
<code class="language-perl">
my $var = do { local $/; <$fh> };
</code>
perl  filehandle  inputoutput  newbie  dammitbrain  solution 
december 2017 by kme
java - Scanner No Line Found Exception - Stack Overflow
You should use if(in.hasNextLine()) before calling in.nextLine(). Otherwise for last line it will thrown Line not found exception.
java  inputoutput  bestpractices  errormessage  exception  solution 
september 2016 by kme
java - Scanner No Line Found Exception - Stack Overflow
You should use if(in.hasNextLine()) before calling in.nextLine(). Otherwise for last line it will thrown Line not found exception.
java  inputoutput  bestpractices  solution 
september 2016 by kme
How do I read a text file into a string variable in Python - Stack Overflow
You could use:

with open('data.txt', 'r') as myfile:
data=myfile.read().replace('\n', '')
python  fileio  dammitbrain  solution  inputoutput  textprocessing 
june 2016 by kme
BashFAQ/001 - Greg's Wiki
while IFS= read -r line; do
printf '%s\n' "$line"
done < "$file"
bash  shellprogramming  fileio  inputoutput  textprocessing  faq  dammitbrain 
november 2014 by kme
Why does my input seem to process past the end of file?, C++ FAQ [http://www.parashift.com/]
Because the eof state may not get set until after a read is attempted past the end of file. That is, reading the last byte from a file might not set the eof state. E.g., suppose the input stream is mapped to a keyboard — in that case it's not even theoretically possible for the C++ library to predict whether or not the character that the user just typed will be the last character.

For example, the following code might have an off-by-one error with the count i:

int i = 0;
while (! std::cin.eof()) { // WRONG! (not reliable)
std::cin >> x;
++i;
// Work with x ...
}
What you really need is:
int i = 0;
while (std::cin >> x) { // RIGHT! (reliable)
++i;
// Work with x ...
}


Source: http://bytes.com/topic/c/answers/752362-while-fp-eof-reading-last-data-point-file-twice#post2998223
cplusplus  annoyance  dammitbrain  iostream  inputoutput  solutiondidntwork 
april 2014 by kme
"puts" without line feed - Ruby Forum

On Mon Aug 11 04:27:56 2008, Bob Miner wrote:
> then
> does what I want at all, eh?
> Thanks for kind & timely responses.

You need to flush $stdout and move to the beginning of the line each
time:

jump = "\r\e[0K" # That is return to beginning of line and use the
# ANSI clear command "\e" or "\003"

(1..10).each do |i|
print jump + i
sleep 1
$stdout.flush
end

That should sort you.
ruby  inputoutput  solution 
march 2014 by kme
Tips and Tricks for Using C++ I/O (input/output)
#include<limits> //for numeric_limits
float fl;
while(!(std::cin >> fl))
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
}
iostream  reference  cplusplus  programming  inputoutput  solution 
january 2014 by kme

Copy this bookmark:





to read