HI,
I would like to change output format of a file from:
abinabdu adanie2  agibson  agoh1    aiabouse 
akko     alau     alee1    alee2    amitb    
amohdali amshams  anmohand 
 
to the format listed below when printing it out to the standard output:

abinabdu
adanie2  
agibson  
agoh1    
aiabouse
akko     
alau     
alee1    
alee2    
amitb     
amohdali 
amshams  
anmohand 

Each elements in the file are sepated by 1 or more spaces (see attached file).

The script written below attempts to do so:
#!/usr/bin/perl
$currDir = `pwd`;
chomp($currDir);
$file = $currDir."/PSCS-ORIG";
open(INFILE, "$file") or die("Cannot open $file : $!");
@entries = <INFILE>;
print "[EMAIL PROTECTED] ... \n";
print "@entries ";
close(INFILE);
print "Printing contents ... \n";
for($i=0; $i<@entries; $i++){
   chomp($entries[$i]);
   print "$entries[$i] \n";
   @lineItems = split(/\s+/, $entries[$i]);
   print "[EMAIL PROTECTED] = @lineItems\n";
   print "\n";
   print "Printing [EMAIL PROTECTED] \n";
   for($j=0;$j<@lineItems;$j++){
      chomp($lineItems[$j]);
      print "$lineItems[$j] \n";
   }
}

However, the script did not print the entire array elements all at once, and that the 
elements are not joined together in the array, as shown in the output below:

pglc0002> ./extract.pl
@entries ... 
abinabdu adanie2  agibson  agoh1    aiabouse 
akko     alau     alee1    alee2    amitb    
amohdali amshams  anmohand 
 Printing contents ... 
abinabdu adanie2  agibson  agoh1    aiabouse aicole      
@lineItems = abinabdu adanie2 agibson agoh1 aiabouse 

Printing @lineItems 
abinabdu 
adanie2 
agibson 
agoh1 
aiabouse 

akko     alau     alee1    alee2    amitb   
@lineItems = akko alau alee1 alee2 amitb

Printing @lineItems 
akko 
alau 
alee1 
alee2 
amitb 

amohdali amshams  anmohand 
@lineItems = amohdali amshams  anmohand 

Printing @lineItems 
amohdali
amshams  
anmohand 

May I know where did I go wrong and how should I solve this problem?

Thanks.

 <<PSCS-ORIG.txt>> 
abinabdu adanie2  agibson  agoh1    aiabouse    
akko     alau     alee1    alee2    amitb    
amohdali amshams  anmohand 
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Reply via email to