Hi ,
i have file of 32kb , i want to read the whole file into string ,
i tried this by doing the below code, but i dint got the whole content of the file in the string , i guess the variable is not able to hold the all data, is there any way where i can achive the same? -
open(FH, "$file");
-
my @output = <FH>;
-
close FH;
-
foreach $logmsg (@output)
-
{
-
$sdpString = "$sdpString" ."$logmsg";
-
-
}
-
3 9120 -
open(FH, $file) or die "$!";
-
my $sdpString = do{local $/; <FH>;};
-
close FH;
-
print $sdpString;
-
I typically do like so: -
open(FH, $file) or die "$!";
-
my $sdpString = join('', <FH>);
-
close FH;
-
print $sdpString;
-
I do want to say, though, that if it's in any way feasible for you to do whatever operation you're doing on one line of the file at a time, you ought to try doing it that way. The structure of Perl encourages you to do things one-line-at-a-time because it's a good idea.
I typically do like so: -
open(FH, $file) or die "$!";
-
my $sdpString = join('', <FH>);
-
close FH;
-
print $sdpString;
-
I do want to say, though, that if it's in any way feasible for you to do whatever operation you're doing on one line of the file at a time, you ought to try doing it that way. The structure of Perl encourages you to do things one-line-at-a-time because it's a good idea.
Do it the way I show above, much more effcient than using join(), but if its a small file it won't matter much.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lionel B |
last post by:
Greetings,
I need to read (unformatted text) from stdin up to EOF into a char
buffer; of course I cannot allocate my buffer until I know how much
text is available, and I do not know how much...
|
by: Dave Reid |
last post by:
Hi everyone...
I'm pretty much a newbie C++ user, and I've run into a problem.
I'm trying to read in a large text file, and then do manipulations on
it. I can read it into a large 2-dimensional...
|
by: Claire |
last post by:
This works ok in a new empty project. I write an empty string to a file.
Looking at the file with a hex editor, there's a single byte of value zero.
I expect this, it's utf8 encoding and this is...
|
by: Tonio Cartonio |
last post by:
I have to read characters from stdin and save them in a string. The
problem is that I don't know how much characters will be read.
Francesco
--
-------------------------------------
...
|
by: jimmy |
last post by:
Hi,
I have an XML string that has been returned using a WebRequest object
that i now need extract some data from. Some sample data is shown
below.
<?xml version="1.0" encoding="UTF-8"?>...
|
by: random guy |
last post by:
Hi,
I'm writing a program which creates an index of text files. For each
file it
processes, the program records the start and end positions (as
returned by
tellg()) of sections of interest,...
|
by: Mannie |
last post by:
Hi!
In my C++ application I use a COM Object (written in C#). When I try to call one of the methods (that tries to read settings from configuration file) I get a nasty error -0x7c812a5b...
|
by: miss time |
last post by:
Hi all,
my java friends ^-^
I have next week quiz in reading file text ,and understand the topic very well.
can any one give some question related to this topic .this help me more to...
|
by: Coldfire |
last post by:
Hi,
The strange problem i am having is,
the input element of type='file' not reading file names after 20 file elements. It simple returns null on reading the 'name' of file.
The code is...
|
by: bjoarn |
last post by:
I have an Application C# handling file reading, building index on this file, using dll wrapped with SWIG. The dll is originaly programmed in C++.
Dll reports back to the the C# programm throug...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |