Perl Format Howto

This how-to comes with no guaratees other than the fact that these code segments were copy/pasted from code that I wrote and ran successfully.

Declare a format

Solution

    format FORMAT_EXPIRED_ACCOUNTS =
    @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<| @<<<<<<<<<<<<<<<<<<<<<<<<| @<<<<<<<<<<<
    $realname,                        $studentno,                $login
    .

Write a formatted record

Solution

    sub output_formatted_to_screen
    {
        my $arrayref = shift;
 
        $~ = 'FORMAT_EXPIRED_ACCOUNTS';
        for ( @$arrayref ) {
            $realname  = $_->[0] ? $_->[0] : 'NULL';
            $studentno = $_->[1] ? $_->[1] : 'NULL';
            $login     = $_->[2] ? $_->[2] : 'NULL';
            write();
        }
    }


AUTHOR

Alex BATKO <abatko AT cs.mcgill.ca>

Thanks to all those who have written with suggestions and comments.


DONATE

Hi! If this document helped you figure out something you were stuck on; if it saved you time; if it relieved some frustration or anxiety... please consider donating. Thank you kindly!


SEE ALSO

http://www.cs.mcgill.ca/~abatko/computers/programming/perl/howto/

http://alex.exitloop.ca/abatko/computers/programming/perl/howto/