0

I have the following code in perl that tries to find a string '$dataset' in the keys of %samples_runs and stores it in an array

} elsif ( my @matches = grep /$dataset/, keys %samples_runs ) { 
    my @values = @samples_runs{@matches};

    foreach my $match (@matches) {
    # do something
    }

However, if the 'keys %samples_runs' starts with "prefix-1-1", I don't want this to be considered as a match.

So when there is a match, this will evaluate to true 'grep /$dataset/, keys %samples_runs'. But when there is a match AND the keys%samples_runs starts with 'prefix-1-1', nothing should be added to the @matches array.

How can I implement this?

1
  • What do you mean by 'keys %samples_runs' starts with "prefix-1-1"? Please show sample data and expected results. Commented Jun 4, 2019 at 10:20

1 Answer 1

2

grep will let you implement any conditions you like. So yes, it can be done.

my @matches = grep ( /$dataset/ and not /^prefix-1-1/, keys %sample_runs );

Should do what you want.

Sign up to request clarification or add additional context in comments.

1 Comment

comman above was giving an error. Changed it to: elsif ( my @matches = grep /$dataset/ && ! /^prefix-1-1/, keys %samples_runs)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.