Well, there seem to be some similarities between the code snippet from the text book and the original code that you posted, but your original code didn't show anything that would set the contents of the "@bex" array. And neither your original statement of the problem, nor this later "clarification", has made it clear enough (to me, at least) what you are trying to do, or how that differs from what is actually happening.

You say that @array2 contains "this kind of data":

"0451524934","1984",7.9500,67,"Penguin Putnam" "0618056815","42nd Parallel",13.0000,25,"Houghton Mifflin" "0195167929","A Strange Likeness - Becoming Red and White in Eighteent +h Century",29.9500,0,"Oxford University Press" "0520204026","Abortionist : A Woman Against the Law",25.0000,30,"Unive +rsity of California Press"
(Note that it is possible and preferable to use <code> tags around data samples as well as code snippets.)

Looks like you want to parse each element as CSV data, because it's possible that some of the quoted fields may contain commas, and a simple regex will have trouble with that. Text::CSV will probably be what you want:

use Text::CSV; # ... load data into @array2 my $csv = Text::CSV->new(); for my $line ( @array2 ) { if ( $csv->parse( $line )) { my @fields = $csv->fields; $Tex{$fields[0]} = \@fields; # or maybe you want this instead? : # $Tex{$fields[0]} = [ @fields[1..$#fields] ]; } else { warn "CSV parse error on: $line\n"; } }
(I'm expecting that Text::CSV will remove the quotes that surround some field values, but if it doesn't, you can handle that easily enough.)

In reply to Re^2: Hash problem by graff
in thread Hash problem by Gnat53

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.