#!/usr/bin/perl use strict; use warnings; # $IN = "someFileName.txt"; my $OUT = "someOutFile.xml"; open (my $fh_out, '>', $OUT) or die "can't open $OUT to write: $!"; #open(IN) or die ("Cannot open file ($IN)"); print $fh_out < TOP my @columns = qw{ category id code title summary prereq group subgroup sequence rolemandatory rolerecommended roleoptional url modality length }; my $id; foreach my $row (){ chomp $row; print $fh_out "\t\n"; my %rec; @rec{@columns} = split ('\|', $row); for my $colname (@columns){ printf $fh_out "\t\t%s\n", $colname, $rec{$colname}, $colname; } print $fh_out "\t\n"; $id++; } print $fh_out "\n"; print "$id records\n"; __DATA__ a|a|a|a|a|a|a|a|a|a|a|a|a|a|a b|b|b|b|b|b|b|b|b|b|b|b|b|b|b c|c|c|c|c|c|c|c|c|c|c|c|c|c|c d|d|d|d|d|d|d|d|d|d|d|d|d|d|d e|e|e|e|e|e|e|e|e|e|e|e|e|e|e f|f|f|f|f|f|f|f|f|f|f|f|f|f|f g|g|g|g|g|g|g|g|g|g|g|g|g|g|g