in reply to delete multiple string blocks

TIMTOWTDI. It's pretty simple so long as you assign to a lexical in your while loop. eg:

#!/usr/bin/env perl use strict; use warnings; my @substrings = qw/XLON_DBX1AE_USD XLON_DBX1AE_GBP/; while (my $line = <DATA>) { if (grep { index ($line, $_) > -1 } @substrings) { print "Found a match in line: $line"; } } __DATA__ strategies{ XLON_DBX0F2_GBP DynamicSpreadQuoter { tradingServiceAttributes { session LSE1 } fairPrice { securityID LU0490618542 securityIDSource 4 service IDNPS } } XLON_DBX1AE_GBP DynamicSpreadQuoter { tradingServiceAttributes { session LSE3 } fairPrice { securityID LU0322252127 securityIDSource 4 service NMP_ABPS } } XLON_DBX1AE_USD DynamicSpreadQuoter { tradingServiceAttributes { session LSE1 } fairPrice { securityID LU0322252171 securityIDSource 4 service NMP_ABPS } } ;; }

I've assumed here that your patterns are all substrings rather than regular expressions.

Replies are listed 'Best First'.
Re^2: delete multiple string blocks
by grandagent (Novice) on Aug 08, 2019 at 11:21 UTC
    Thanks a lot that worked! Could you elaborate a bit on how this works in detail? Would appreciate that mate..

      Sure. Working from the inside out:

      1. index looks for the substring within the string. Any result greater than -1 indicates it has been found. (If you know your substrings are always at the beginning of the string you can check for zero here)
      2. grep attempts the block of code against every element of the supplied array and returns those which evaluate to a true value.
      3. if tests all this for truth, ie. if the list returned by grep has elements.

      Note that grep isn't the most efficient here because it will go on testing even after a match is found. For a short array/list it won't matter much. For a longer array/list you might want List::Util::any instead.