• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

getline in perl?

BlackOmen

Senior member
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.
 
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: $!";
 
Back
Top