StudentLastName,180,30,Y,,Y StudentFirstName,210,30,N,,Y StudentMiddleName,240,30,N,, DateOfBirth,270,8,Y,,Y Gender,278,2,Y,,Y Grade,280,3,Y,, #### 111E2000 111E2000 201457660112567001 EP015F SSHS 1223200601120 00 0 000 0 111 0 0 sumsoc12S EPEN SS HS NNNNNNNNNN 0000091323 Y 111E2000 111E2000 201457660212567002 EP025F SSHS 1223200601120 00 0 000 0 111 0 0 sumsoc12S EPEN SS HS NNNNNNNNNN 0000091324 Y 111E2000 111E2000 201457660312567003 EP035F SSHS 1223200601120 00 0 000 0 111 0 0 sumsoc12S EPEN SS HS NNNNNNNNNN 0000091325 Y #### #************************************* # Define external utilities #************************************* use strict; #use warnings; #use diagnostics; use List::MoreUtils qw{ any }; use Data::Dumper qw(Dumper); #************************************* # Assign the variables with the value passed to program #************************************* my $Layout = $ARGV[0]; my $File1 = $ARGV[1]; my $Results = $ARGV[2]; #************************************* # Initialize Global Variables #************************************* my $cnt_records_read = 0; my $null = ""; #************************************* # Open Files. #************************************* my ($layoutFile, $inputFile, $resultsFile); if (-e $Layout) { open($layoutFile, "<", "$Layout") or die("Could not open Layout file: $!\n"); } if (-e $File1) { open($inputFile, "<", "$File1") or die("Could not open File 1. $!\n"); } open($resultsFile, ">", "$Results") or die("Could not open Results File. Verify user has permissions for the results folder location. $!\n"); #************************************* # Create hash of layout file #************************************* my $cnt_all_fields = 0; my $cnt_omitted_fields = 0; my %layout=(); my $layout; my $layout_key = $null; my @layout_value = ""; my $layout_value = $null; my @chars=(); while (my $line1=<$layoutFile>) { chomp $line1; my @fields = split("," , $line1); if ( $fields[3] eq "Y" ) { $cnt_all_fields++; my $layout_key = $fields[0]; my $layout_value = { 'Field Name' => $fields[0] ,'Position' => $fields[1] - 1 ,'Length' => $fields[2] - 0 ,'Characters' => [ @chars ] }; $layout{ $layout_key } = [ $layout_value ]; } else { $cnt_omitted_fields++; } } # print Dumper %layout; #************************************* # Update Characters Array in Layout Hash #************************************* my $cnt_records_read_file1=0; my $char; my $chars; my @fld_detail; my @fld_chars=(); while ( my $line1 = <$inputFile> ) { $cnt_records_read_file1++; chomp($line1); foreach my $name ( keys %layout ) { foreach my $fld_detail ( @{ $layout{$name} } ) { my $fld_name = $fld_detail->{'Field Name'}; my $fld_position = $fld_detail->{'Position'}; my $fld_length = $fld_detail->{'Length'}; my @fld_chars = @{ $layout{$name}}{'Characters'}; my $field1 = substr($line1,$fld_position,$fld_length); for(my $pos = 0; $pos < $fld_length; $pos++) { my $char = substr($field1,$pos,1); if (any { $_ eq $char } @fld_chars) { } else { push @fld_chars, $char; $layout_key = $fld_name; $layout_value = { 'Field Name' => $fld_name ,'Position' => $fld_position ,'Length' => $fld_length ,'Characters' => [ @fld_chars ] }; $layout{ $layout_key } = [ $layout_value ]; } } } } } print Dumper \%layout; #************************************* # Format printed layout #************************************* foreach my $name ( keys %layout ) { foreach my $fld_detail ( @{ $layout{$name} } ) { my $fld_name = $fld_detail->{'Field Name'}; my $fld_position = $fld_detail->{'Position'}; my $fld_length = $fld_detail->{'Length'}; my @fld_chars = @{$layout{$name}}{'Characters'}; print @fld_chars; $fld_name = sprintf("%-30s",$fld_name); $fld_position = sprintf("%8s",$fld_position); $fld_length = sprintf("%6s",$fld_length); print $resultsFile "$fld_position $fld_length $fld_name @fld_chars \n"; } } #************************************* # Close Files #************************************* close($layoutFile); close($inputFile); close($resultsFile); #### $VAR1 = { 'StudentLastName' => [ { 'Length' => 30, 'Position' => 179, 'Field Name' => 'StudentLastName', 'Characters' => [ undef, 'E', 'P', '1', '9', '5', 'F', ' ' ] } ], 'SASID' => [ { 'Length' => 10, 'Position' => 159, 'Field Name' => 'SASID', 'Characters' => [ undef, '2', '0', '1', '4', '5', '7', '6', '9' ] } ], 'Grade' => [ { 'Length' => 3, 'Position' => 279, 'Field Name' => 'Grade', 'Characters' => [ undef, '1', '2', '0' ] } ], 'Gender' => [ { 'Length' => 2, 'Position' => 277, 'Field Name' => 'Gender', 'Characters' => [ undef, '0', '1' ] } ], 'DateOfBirth' => [ { 'Length' => 8, 'Position' => 269, 'Field Name' => 'DateOfBirth', 'Characters' => [ undef, '1', '2', '3', '0', '6' ] } ] }; #### Pseudo-hashes are deprecated at procFreq2.pl line 136, <$inputFile> line 20. Use of uninitialized value in string eq at procFreq2.pl line 143, <$inputFile> line 20. Pseudo-hashes are deprecated at procFreq2.pl line 186, <$inputFile> line 20. Use of uninitialized value in print at procFreq2.pl line 188, <$inputFile> line 20.