I don't think you really want to have the first element be a real array name -- do you have a package named IL12::1 ? If you want to reference these things by name, I suggest (as others have) a hash, with the first element of each row in your file being the key.

Text::CSV_XS would work wonderfully for this application.

#!/usr/bin/perl use strict; use warnings; use IO::File; use Text::CSV_XS; use Data::Dumper; my $io = IO::File->new('myinputfile.txt','<') or die "Cannot open input file for reading: $!"; my $csv = Text::CSV_XS->new(); my %data; while (my $row = $csv->getline($io)) { # getline() reads a line from $io and parses it -- fast! # $row will contain an ARRAYref, one value for each element my $element_name = shift @$row; #first element is the name $data{$element_name} = $row; } print Dumper(\%data); # this will show you how the structure looks

The output from this should look like:

$VAR1 = { 'IL12::1::287' => [ '6', '-17', '-9', '-21', '-24', '-15', '-2', '11', '4', '4', '-15', '-26', '-16', '-9', '-18', '-25', '27', '17', '6' ] ... };

(I've used ... to indicate that there will be more of the same, to save space in this node)

I hope that helps!

<radiant.matrix>
Ramblings and references
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Re: how to make first element of an string as a the array name by radiantmatrix
in thread how to make first element of an string as a the array name by koleti

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.