getline in perl?

BlackOmen

Senior member
Aug 23, 2001
526
0
0
At the suggestion of a friend, I decided to learn to do CGI with perl. Is there an equivalent function in perl similar to the getline facility in C++?

What I'm trying to do is is read a file and perl is just a PITA. Given a file with the following format:

name
dept
phone
email

I need to read those into some arrays (of respective names) for whatever my dirty mind sees fit. I'm about two steps away from just doing this in C++ in which case I'll be done in two seconds. Thanks in advance.
 

Rahminator

Senior member
Oct 11, 2001
726
0
0
I haven't done Perl in a while, but I think this will work:

open FILEHANDLE, "somefile" or die "Couldn't open somefile: $!";
while (<FILEHANDLE> ) {
chomp;
push @names, $_;
chomp($dept = <FILEHANDLE> );
push @depts, $dept;
chomp($phone = <FILEHANDLE> );
push @phones, $phone;
chomp($email = <FILEHANDLE> );
push @emails, $email;
}
close FILEHANDLE or warn "somefile didn't close nicely: $!";