Ok. I now see the problem.

while (<PFILE>) { chomp; next unless $_; my @tags = split /; |:/; my $key = shift @tags; $patterns{$key} = \@tags; ## <<< HERE }
When you are building your %patterns hash, you are reading the tagged data into an array and then assigning a reference to that array as the value in your hash.

(I didn't encounter the problem because I bypassed this piece of code as I don't have your datafile.)

There are two ways around the problem depending on how you use the data later. If you don't need to access the array's elements individually in other parts of the code, you can convert the array to a scalar when you assign it to the hash. That means substituing the following line for the one I flagged in the code above.

$patterns{$key} = "@tags";

That will convert the array to a scalar and the rest of the program should then work.

However, if you need to use the array as an array elsewhere in your program, then you will need to modify the code that builds the second hash.

If this is needed and you have trouble with it, come back with your attempt at the code to do this, and I'll try and help you further.


Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy

In reply to Re: Re: Re: Re: Re: Re: Re: Match key and return value in some order by BrowserUk
in thread Match key and return value in some order by Anonymous Monk

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.