Mazhar wrote:
> Dear Frndz,

Hello,

> I am writing the below code and i am facing a problem in chomp (its an
> HP UX Box)
> 
> --------------------Code----------------------------
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> my $file_name=$ARGV[0];
> open(FILE,"$file_name") || die "Not been Accessed" ;
> @host_array=<FILE>;
> close(FILE);
> 
> foreach my $host(@host_array)
>  {
>      chomp($host);
>      print "$host \n";
> }
> --------------------------------------------------------
> 
> -------------Input-----------
> tecomsip
> ossnnmcs01
> ossnnmcs02
> -----------------------------
> 
> Output is
> 
> ecomsip
> ssnnmcs01
> ossnnmcs02
> 
>> From the output i see the first character is missing in the output..

My guess would be that the lines are terminated by CR and LF and chomp() is
only removing the LF.  This should work better:

#!/usr/bin/perl
use strict;
use warnings;

my $file_name = $ARGV[ 0 ];

open( FILE, $file_name ) || die "$file_name not been Accessed: $!";

while ( my $host = <FILE> )
 {
     $host =~ s/\s+\z//;
     print "$host \n";
}

close( FILE );




John
-- 
use Perl;
program
fulfillment

-- 
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