UPDATE: Sorry I think I messed up here. Is this something like you want? My brain is hurting today.
use strict; use warnings; while (<DATA>) { next unless /\S/; chomp; my ($name, $markerA, $markerB, $height) = split (/\s+/,$_); $name //= ""; $markerA //= ""; $markerA ="" if $markerA =~ /^0$/; $markerB //= ""; $markerB ="" if $markerB =~ /^0$/; if ($markerA !~ /A/) { $markerA = $markerB; $markerB = "B"; } $height //= ""; if (!$height) { my $string; foreach ($name, $markerA, $markerB) { $string .= "\'$_\',"; } chop $string; print "$string\n"; } } =prints '2','A','' '3','','B' =cut #Name Marker1 Marker2 Height Time __DATA__ 1 A A 6246 0.9706 1 B B 3237 0.9706 2 A 0 2 B B 5495 0.9775 3 A A 11254 0.9694 3 B 0
I think this could be done better. Below was a admittedly failed bogus solution for first post.
use strict; use warnings; my %name; while(my $line =<DATA>) { next unless $line =~ /\S/; #skip blank lines chomp $line; my ($undef, $markerName,undef, undef, $height) = split (/\s+/, $line); $name{$markerName} = $height; } foreach (sort keys %name) { print "$_ => $name{$_}\n"; } =prints a => 55 b => 32 c => 34 =cut __DATA__ 1 a 23 99999 55 4 c 55 8888 34 5 b 45 88888 32

In reply to Re: Combine duplicated keys in Hash array by Marshall
in thread Combine duplicated keys in Hash array by Tikplay

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.