Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl -Tw
    use strict;
    ...
    my $fname = "CommaSample.dat";
    my $pretty = 1;
    BARE: {
    
  2. or download this
        my ($toggle, @data) = ('');
    
  3. or download this
        open FH, "< $fname" or die "Cannot open datfile: ", $!;
    
  4. or download this
        while (<FH>) {
            $toggle = 1, next if /^"PER"\s*$/;
            $toggle = 0, next if /^"EMP"\s*$/;
            last if /^"EOS"\s*$/;
    
  5. or download this
            die "Unknown or missing record tag: Got $_ on line $., datafil
    +e $fname.$/" if $toggle eq '';
    
  6. or download this
            chomp;
            @data = &quotewords('\s+', 0, $_);
            print "Entity      = $data[0]$/";
            if ($toggle) {
    
  7. or download this
                print "Name        = $data[1]$/";
                print "Color       = $_ $/" for split /\s*,\s*/, $data[2];
                print "Date        = $data[3]$/";
            }
            else {
    
  8. or download this
                print "Employment  = $data[1]$/",
                      "Job Title   = $data[2]$/",
    ...
                      "Location    = $data[4], $data[5] $data[6]$/",
                      "Salary      = $data[7]$/";
            }
    
  9. or download this
            $toggle = '';
            print $/ if $pretty;
        }
    
  10. or download this
        print $/;
    }