in reply to Re^9: How can I expand my substring?
in thread How can I expand my substring?

I am very sorry, I did not mean at any point that you should write the code for me...I was just wondering if you would be kind enough to re-write your substitution statements in more lines instead of 1. Then I would be able to insert the if clause and restrain the expanding to +-200 that I want, that's all...

Replies are listed 'Best First'.
Re^11: How can I expand my substring?
by Corion (Patriarch) on Jul 23, 2014 at 06:57 UTC

    perlop, as I already linked to you, explains how the right hand side part of s///e works. I don't know how I could break down an if statement more than writing down the if statement within the right hand side of s///e. But as I'm sure you already have read that in the documentation that I already linked to, I don't know how to help you further.

      I wrote this and it seems to work... Do you think it's correct?
      if($initial_string=~/((-*)(B+)(-*))/) { $total=$1; $position_total=index($initial_string, $total); $substring_until_total=substr($initial_string,0,$position_tota +l); $blank_left=$2; $b_region=$3; $blank_right=$4; if(length($blank_left)>200) { substr($blank_left, -200, 200, ('B' x 200)); } else { $blank_left=~s/\-/B/g; } if(length($blank_right)>200) { substr($blank_right, 0, 200, ('B' x 200)); } else { $blank_right=~s/\-/B/g; } print $substring_until_total.$blank_left.$b_region.$blank_right."\ +n"; }
Re^11: How can I expand my substring?
by GrandFather (Saint) on Jul 23, 2014 at 05:24 UTC

    To understand Corion's code you need to read and understand the regular expression documentation Corion pointed you to earlier in the thread. Regular expressions aren't amenable to "break your code down a bit" in the way you mean. They are a powerful language in their own right and learning how to use regular expressions is an important part of using Perl well. Read back through this thread and pay special attention to the bits you skimmed the first time through.

    Perl is the programming world's equivalent of English