Hi monks;

I want to be able to capture in a regex output say like this: Viridiplantae Crenarchaeota Fungi Crenarchaeota Fungi Fungi Fungi Metazoa Metazoa Euryarchaeota Fungi, using a regex:

$line=~ /\bkingdom\b\|(.*?)\|/).

The problem is I want to be able to capture the output not as a single scalar but as individual values to be used in an @array and stored in hash as individual keys say.

Much app help x.

Ok sorry I should have done;

my code is:
my $key; while($line=<>){ if($line=~/\bkingdom\b\|(.*?)\|/g){ $key.=$1; } }
and (part of) my data is: (a bit of a jumble)
species|Caragana arborescens | genus|Caragana | subfamily|Papilionoide +ae | family|Fabaceae | order|Fabales | no rank|eurosids I | subclass| +Rosidae | no rank|core eudicots | no rank|eudicotyledons | no rank|Ma +gnoliophyta | no rank|Spermatophyta | no rank|Euphyllophyta | no rank +|Tracheophyta | phylum|Embryophyta | no rank|Charophyta/Embryophyta g +roup | no rank|Streptophyta | kingdom|Viridiplantae | superkingdom|Eu +karyota | no rank|cellular organisms | no rank|root || species|syncytium endosymbiont of Diaphorina citri | no rank|unclassif +ied beta proteobacteria (miscellaneous) | no rank|unclassified beta p +roteobacteria | class|beta subdivision | phylum|Proteobacteria | supe +rkingdom|Bacteria | no rank|cellular organisms | no rank|root || subspecies|Trypanosoma brucei brucei | species|Trypanosoma brucei | su +bgenus|Trypanozoon | genus|Trypanosoma | family|Trypanosomatidae | or +der|Kinetoplastida | no rank|Euglenozoa | superkingdom|Eukaryota | no + rank|cellular organisms | no rank|root || species|unculturable Mariana archaeon no. 1 | no rank|environmental sa +mples | no rank|unclassified Crenarchaeota | kingdom|Crenarchaeota | +superkingdom|Archaea | no rank|cellular organisms | no rank|root || species|Suillus aeruginascens | genus|Suillus | family|Boletaceae | or +der|Boletales | subclass|Hymenomycetidae | class|Hymenomycetes | phyl +um|Basid
BUT I think I managed it using this now and this answers my question, I'm pretty sure:
@array= split(/\s+/, $key); print $array[0], $array[1], $arrray[2] etc..
so now I can access each element/key in the array and store it in a hash now as individual keys

Edit: g0n - code tags


In reply to capturing separately by ada

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.