
Admin
Deleted
Apr 17, 2000, 7:06 AM
Post #4 of 5
(395 views)
|
To write the contents after it's been split... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> open (FILE,"<file.txt") or die "Couldn't open file.txt $!"; while (<FILE> ){ chomp; my ($name,$address,$email)=split(/\t/,$_); # do something with $name $address and $email} open (FILE2,">file2.txt") or die "Couldn't open file.txt $!"; print FILE2 join(/\t/,$name,$address,$email); print FILE2 "\n"; close FILE2; } </pre><HR></BLOCKQUOTE> chomp takes off the newline character \n from a line. chop removes the last character indiscriminantly. For example: $line = "Hello"; chomp $line; would do nothing here, because there is no newline character. chop $line; would make $line = "Hell"; Example 2: $line = "Hello "; or $line = "Hello\n"; both chomp and chop will make $line = "hello". It's best, if working with a file to use chomp because it's the one way to make sure that your text never gets chopped
|