Forum Moderators: coopster & phranque

Message Too Old, No Replies

Perl Pattern matching

         

DarReNz

3:06 pm on Apr 12, 2003 (gmt 0)

10+ Year Member



Hey if i haf 1, "up", "down", "" in an array how do i go about splitting up into an array and down into another array ignoring numbers and commas and "" at the end? Thanks

amoore

4:21 pm on Apr 12, 2003 (gmt 0)

10+ Year Member



Could you give an example, please? I don't really understand what you're looking for, I'm afraid.

Here's what I imagine. tell me where I'm wrong.

start with @foo = qw( up3 down4 down2 up1 up8 );
and you want
@up = qw( up "" "" up up ); and
@down = qw( "" down down "" "" );

If that's what you want, then something like this should work:

my ( @up, @down );
foreach my $f ( @foo ) {
$f =~ s/\d*$//;
if ( $f eq "up ) {
push @up, $f;
push @down, "";
} else {
push @up, "";
push @down, "";
}
}

SinclairUser

4:31 pm on Apr 12, 2003 (gmt 0)

10+ Year Member



I think the 4th line of perl code is missing a double quote

if ( $f eq "up" ) {

Just in case cut-n-paste is used.