in reply to Adding elements to an array from an array
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 | |
by CharlesClarkson (Curate) on May 02, 2002 at 03:05 UTC |