Created
          October 28, 2012 01:27 
        
      - 
      
 - 
        
Save thinkhy/3967122 to your computer and use it in GitHub Desktop.  
    using unpack to deal with fix-width data
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | my $format = 'A2 @4 A10 @16 A6 @24 A*'; | |
| my $string = <<'COLUMMNAR'; | |
| ID First Name Middle Last Name | |
| 1 brian d foy | |
| 2 Joshua McAdams | |
| 3 Joseph N Hall | |
| COLUMMNAR | |
| open my ($fh), '<', \$string; | |
| my @headers = unpack $format, <$fh>; | |
| my @names; | |
| while(<$fh>) { | |
| my %hash; | |
| @hash { @headers } = unpack $format, $_; | |
| push @names, \%hash; | |
| } | |
| use Data::Dumper::Names; | |
| print Dumper( \@names ); | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment