Ok, let's say that @calarray (not a good name by the way, very easy to type it wrong) has alreay been populated, and populated with tainted user input to make things icky:
my @line = qw(foo;bar baz;qux user;errors;suck trust; ;no-one ;);
You can use this snippet to only get those items that have one token before the first semi-colon, and also one token after that semi-colon:
my %hash = grep !/^$/, map { ($a,$b) = $_ =~ /^([^;]+);([^;]+)/; ($a,$b); } @line;
I chose not to worry about possible whitespace, it is ugly enough as it is. The idea is to do as guha rightfully said, use a regex. The map filters out the key and value pairs, but because of tainted user input, we still get an undefined key (actually, three candidates that overwrite each other). The grep takes care of those.

Warning: I use $a and $b in this example. These variables are meant to be used with sort, but i see no problem in using them here - you don't even have to declare them. Just don't be tempted to use them for any task more than temporary. In fact, you should probably just stick to only using them for sort. ;)

Also, a time saving tip: If you want to quickly see if the hash (or array or any other data strucure) contains what you think it should, use Data::Dumper (thanks to guha for clearing up my blunder - see below ;))

use Data::Dumper; print Dumper \@array; print Dumper \%hash; print Dumper $reference;
From the first two code snippets, the variable %hash should look like:
$VAR1 = {
          'foo' => 'bar',
          'baz' => 'qux',
          'user' => 'errors'
        };

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: How to assign a hash from an array? by jeffa
in thread How to assign a hash from an array? by jamen

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.