home *** CD-ROM | disk | FTP | other *** search
- # This getline() function returns the next line from an
- # input file. It checks for lines ending in an escaped
- # newline (i.e. backslash) and concats the next line if
- # it finds such. Use this way:
- #
- # open(AFILE,$pathname);
- # $line = &getline('AFILE');
- #
- # This shows good use of local variables, passing
- # file descriptors by name, and the redo loop control
- # mechanism. Perl optimizes "/xxx$/" tests as well as appending
- # the next input line "$foo .= <bar>", so this is pretty quick.
-
- sub getline {
- local($file) = @_;
- local($_);
-
- $_ = <$file>;
- {
- chop;
- if (/\\$/) {
- chop;
- $_ .= <$file>;
- redo;
- }
- }
- $_;
- }
-