Hi Monks!
I'm working on yet another program, and have run into a little problem. The program is designed to remove data from a series of text files and print it out in a series of columns. Thus far, my program gets all the required data, but is unable to output it correctly. The sub get_signal gives me a hash of arrays containing my data; I need to asign each of these arrays a different name, and then know those names so I can print them. Theoretically, I want this automated enough so that no matter how many files are inputed into the program(and therefore no matter how many arrays I end up with), the program will assign each one a unique variable name and then be capable of printing them out. My code:
#! usr/local/bin/perl use Cwd; print STDOUT "Please enter the name and location of the directory to p +arse\:\n"; $directory=<STDIN>; chomp $directory; open (OUTPUTFILE,">junk.txt"); opendir (DIR, "$directory") or die "Failed to open directory: $!"; @filename=readdir(DIR); @trash=splice(@filename, 0,2); @genius=@filename; sub get_signal { while (@filename) { $file=shift @filename; @final_data=''; use Cwd 'chdir'; chdir "./data"; open (FILE, "$file") or die; @data=<FILE>; $spliced_data=splice(@data, 1, 14); foreach (@data) { ($a, $b, $c, $d, $e, $f)=split(/\t/); push(@final_data, "$d\n");} %hash={"$file"=>@final_data}; #this hash assignment +doesn't wor +k close (FILE); } @values=values(%hash); return @values; } sub get_targets { $target=shift @genius; use Cwd 'chdir'; chdir "./data"; open (FL, "$target") or die; @info=<FL>; $excess=splice(@info, 1, 14); foreach (@info) { ($z, $x, $w, $y, $u, $v)=split(/\t/); push(@targets, "$z\n");} close (FL); return @targets; } @column=get_targets; @next_columns=get_signal; for ($i=0;$i<=scalar(@next_columns);$i++) { @$i=@next_columns[$i];} #my attempt at assigning a +unique variabl +e, which doesn't work. print @next_columns; print OUTPUTFILE "@final_data"; close OUTPUTFILE; exit;
Thank you all for your time and thoughts!!!
bioinformatics

In reply to Unique Variable names... by bioinformatics

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.