in reply to Adding elements to an array from an array

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*

Replies are listed 'Best First'.
Re: Re: Adding elements to an array from an array
by Rhodium (Scribe) on May 01, 2002 at 20:00 UTC
    Hi,

    Nice effort, but this grabs all of the records and the problem as most of you noted is that I am only trying to get the matches for a particular .SUBCKT. So for example I only want to get the /VDD|VCC/ and /VSS|GND/ for .SUBCKT FOO. And ignore .SUBCKT test2 all together..

    I hope this clears it up a bit. Thanks


    Rhodium

    The <it>seeker</it> of perl wisdom.

      Put the check back in.

      while( <DATA> ) { next unless m/^\.SUBCKT\s+$runset{SchCell}/; my %seen; . . .

      HTH,
      Charles K. Clarkson
      Clarkson Energy Homes, Inc.