CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
how to assign...

 



shinned
Deleted

Sep 5, 2000, 11:05 PM

Post #1 of 5 (2868 views)
how to assign... Can't Post

 
How do I read the whole content of the file into a single variable?

I tried using read() but it returns a value lesser than the actual bytes. Will this affect the actual characters being read?

Anybody please help.

shinned


fashimpaur
User

Sep 6, 2000, 4:07 AM

Post #2 of 5 (2868 views)
Re: how to assign... [In reply to] Can't Post

Shinned,

May not be the best way, but try this:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



my $fileVar;

open (INFILE, "myfile.txt");
while (defined($line = <INFILE> )){
$fileVar .= $line;
}
close (INFILE);

</pre><HR></BLOCKQUOTE>

HTH,

Dennis


shinned
Deleted

Sep 6, 2000, 4:22 AM

Post #3 of 5 (2868 views)
Re: how to assign... [In reply to] Can't Post

Thank you very much for your response. You see, while waiting for anybody to answer, I was able to figure it out.

I have already tried your code but I was looking for a code that will not go into a loop structure.

my solution was :

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



$/ = "0777";
open(SRC, "$infile");
$whole = <SRC>;

</pre><HR></BLOCKQUOTE>

again, thank you very much for taking time to reply.

shinned
shinned@yahoo.com


dws
Deleted

Sep 7, 2000, 10:16 AM

Post #4 of 5 (2868 views)
Re: how to assign... [In reply to] Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

{
local $/;
$whole = <FILE>;
}</pre><HR></BLOCKQUOTE>
Has the benefit of not leaving $/ modified.



shinned
Deleted

Sep 11, 2000, 2:52 AM

Post #5 of 5 (2868 views)
Re: how to assign... [In reply to] Can't Post

Thank you both for having taking time to reply. It really helped me a lot.

shinned

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives