if i understand what you want, it's something like this:

note: i'm using the DATA filehandle for this example, just plug in your handle to work on real data. i assume you're reading in a record delimited by ".ENDS\n", then splitting on space, and pushing to arrays depending on the match. you don't want to push more than once per record.

correct me if i'm wrong.

#!/usr/bin/perl -w use strict; $|++; my(@PN, @GN); $/ = ".ENDS\n"; my @a; while( <DATA> ) { my %seen; local $\ = "\n"; my @words = split / /, $_; for( @words ) { if( /VDD|VCC/ ) { print "Matched VDD $_\n"; push @PN, $_ unless $seen{Power}++; } elsif( /VSS|GND/ ) { print "Matched VSS $_\n"; push @GN, $_ unless $seen{GND}++; } } } print scalar @PN, "\n", scalar @GN, "\n"; __DATA__ .SUBCKT FOO X y Z .PININFO test VDD VDD VDD Vss vdd VSS t y foo blah blah bla .ENDS .SUBCKT test2 vdds VSS VDD .PININFO test2 2FS SEL blah blah blah .ENDS

~Particle *accelerates*


In reply to Re: Adding elements to an array from an array by particle
in thread Adding elements to an array from an array by Rhodium

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.