Arowana
10-30-03, 12:29 PM
Hi all,
I am trying to write a basic script that will print out the longest line in a given file. Right now, it prints a blank line when executed. I would like it to perform this action on a file in the same directory called "raven.txt". I know this script does not look into the file right now. That's what I'm trying to figure out how to do. I'm a real perl newbie, so could someone show me how I could add this functionality to the perl script, please? I would really appreciate it. Thanks!
#!/usr/bin/perl
#print the longest line in a file
while(<>) {
chomp;
if (length ($_) > length ($maxlength) ) {
$longest = $_;
}
}
print "The longest line is $longest.\n";
I am trying to write a basic script that will print out the longest line in a given file. Right now, it prints a blank line when executed. I would like it to perform this action on a file in the same directory called "raven.txt". I know this script does not look into the file right now. That's what I'm trying to figure out how to do. I'm a real perl newbie, so could someone show me how I could add this functionality to the perl script, please? I would really appreciate it. Thanks!
#!/usr/bin/perl
#print the longest line in a file
while(<>) {
chomp;
if (length ($_) > length ($maxlength) ) {
$longest = $_;
}
}
print "The longest line is $longest.\n";