#!/usr/local/bin/perl
#
# Program to open the password file, read it in,
# print it, and close it again.
$file = 'C:\PERL\BIN\ABC.XML';
open(INFO, $file) or die "Can't Open the File";
$lines = %26lt;INFO%26gt;;
while (INFO)
{
chomp (@lines=@_);
print @lines;
next;
}
Above is my program. the abc.xml is the file and i want to print each line when i ran this. But i'm having trouble with the chomp. When i try to run this the screen just freezes. I ned to hit ctrl+c to stop th program
need help???
Perl program???
There are several issues with this.
What you want is:
#!/usr/local/bin/perl
#
# Program to open the password file, read it in,
# print it, and close it again.
$file = 'C:\PERL\BIN\ABC.XML';
open(INFO, $file) or die "Can't Open the File";
while (%26lt;INFO%26gt;)
{
chomp; #works on $_ by default
print $_,"\n"; #Don't need the "\n" if you don't chomp
}
close (INFO);
@_ is the list that holds the arguments passed to a subroutine, and I think that chomp only works on a scalar not a list. If you chomp, then you need to add "\n" unless you want everything printed on the same line. The 'next;' statement is unnecessary, but doesn't hurt anything. If you place "use strict;" it would have pointed out some of your problems, good to "use warnings;" too.
apricot
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment