GE interview question

Write perl code to find the number of lines in a file

Interview Answers

Anonymous

26 Feb 2014

#!/usr/bin/perl my $file = @argv[0]; if ( $ARGV > 0 ) { die "Usage: Lines.pl filename \n" }; my $lines = `wc -l $file`; print "$file has $lines lines \n"; lol

Anonymous

26 Feb 2014

I meant #!/usr/bin/perl my $file = @ARGV[0]; if ( $ARGV > 0 ) { die "Usage: Lines.pl filename \n" }; my $lines = `wc -l $file`; print "$file has $lines \n";

Anonymous

11 Aug 2015

if ($#ARGV < 0) { die "Usage : q4.pl filename\n"; } my $file = $ARGV[0]; my $lines = `wc -l $file`; my ($line,$rest) = split(//,$lines); print "$file has $line lines \n";