in reply to Accessing secondary elements in array

I would use a regexp to extract the "bold" part, and compare that. Which part do you have a problem with? The regexp? Comparing two strings? Intersecting the array (for that: see the perlfaq)?
  • Comment on Re: Accessing secondary elements in array

Replies are listed 'Best First'.
Re^2: Accessing secondary elements in array
by chavanak (Initiate) on Nov 04, 2009 at 12:21 UTC
    The problem for me is in regexp and intersection. To be very honest I have no idea how to use regexp for this particular task :( I am very new to perl so any guidance to material or example code will be really helpful
      A few assumptions, "bold text" is the part of the text that is surrounded by [b] and [/b]. "bold text" isn't nested inside "bold text", and there's at most one piece of "bold text" per string. Strings not containing any bold text is to be ignored.

      Then I would do something like (not tested):

      my %seen; m{\[b\](.*?)\[/b\]} and $seen{$1} = 1 for @array1; my @result = grep {m{\[b\](.*?)\[/b\]} && !$seen{$1}} @array2;
        Hi, Thanks for the reply but the first assumption itself is not true, the bold tags were added just to differentiate the text that has to be used for comparing. Can you please let me know any other idea I can proceed with? Cheers