Greetings, I am a newbie, so please bear with me if this is too simple to be posted. When I run the following code, I don't get any output. I have included the expected output at the bottom. What am I missing? I could directly "print $version", but I need to access through a hash(key) for additional processing. Using Perl version 5.8.8

use strict ; my %seen = (); while(<DATA>){ chomp; my($file,$version) = split(/vobx/,$_); print "$seen{$file} \n"; } __DATA__ /view/d602_edf3/vobx/copy/pp/copy/ticrwpth /view/d602_edf3/vobx/copy/pp/copy/ticrwptr /view/d602_edf3/vobx/copy/pp/copy/tirrwphz /view/d602_edf3/vobx/copy/pp/copy/tirrwprq

Expected output : /copy/pp/copy/ticrwpth /copy/pp/copy/ticrwptr /copy/pp/copy/tirrwphz /copy/pp/copy/tirrwprq

I understand I can get the string I need from the $version. But like I mentioned, I need to be able to access it as a $hash{$key}. I am not sure why this code is not working.

Here is what I am actually trying to do. Assume that, I have a file which looks as follows file1@@/main/trunk/1 file2@@/main/trunk/2 file2@@/main/trunk/3 file1@@/main/trunk/2 file1@@/main/trunk_2/1 If the file name (before @@) is unique, I need to capture that straight away. If there is trunk_2, that line trumps other lines which have the same file name. If there is no trunk_2, I need to get the line with just "trunk" which has the highest numeric at the end after the last "/". There might be more than one line for trunk_2 with different numeric at the end, in which case, I need to get the higher numeric among all lines with same file names before "@@". So, the output should be file1@@/main/trunk_2/1 file2@@/main/trunk/3 Hope this helps.


In reply to Split and hash by ksam

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.