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: Beginner:
How to add each line into single line in txt file?

 



Hellena
New User

Feb 19, 2013, 5:16 AM

Post #1 of 3 (266 views)
How to add each line into single line in txt file? Can't Post

 
I have problem with my code cose of this part:

Code
  

foreach my $line(keys %results){

print Dump($post) if $results{$line} == 1;
}


I need it to be only one time printed 'print Dump($post)'

Here is all that part

Code
my $f1 = "/home/hellena/Desktop/data.txt"; 
my $f2 = "/home/hellena/Desktop/ini.txt";


my %results = ();
open FILE1, "$f1" or die "Could not open file: $! \n";

while(my $line = <FILE1>){$results{$line}=1;
}
close(FILE1);


open FILE2, "$f2" or die "Could not open file: $! \n";
while(my $line =<FILE2>) {
$results{$line}++;
}
close(FILE2);

foreach my $line(keys %results){

print Dump($post) if $results{$line} == 1;

}

$post contains same like it lines but cose of hash I get randomed lines if i print line by line...

If I run code it will repat printed post 4-5 times it depends how much lines have in it post(lines comes dinamicly) but I need post be printed just one time...


(This post was edited by Hellena on Feb 19, 2013, 5:32 AM)


FishMonger
Veteran / Moderator

Feb 19, 2013, 6:15 AM

Post #2 of 3 (258 views)
Re: [Hellena] How to add each line into single line in txt file? [In reply to] Can't Post


Code
print Dump($post) and last if $results{$line} == 1;



Hellena
New User

Feb 19, 2013, 7:44 AM

Post #3 of 3 (249 views)
Re: [FishMonger] How to add each line into single line in txt file? [In reply to] Can't Post

Thanks!!!

 
 


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

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