in reply to Reading from files

If the string between the two keywords doesn't contain newlines, you can simply use a regex:
#!/usr/bin/perl use warnings; use strict; open my $IN, '<', shift or die $!; open my $OUT, '>', shift or die $!; while (<$IN>) { my ($before, $between, $after) = /(.*?clothes)(.*?)(mall.*)/; print {$OUT} "$before '$between' $after\n"; }

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Reading from files
by AmberThai (Initiate) on Jan 18, 2016 at 10:34 UTC

    and if you have something like :"abc clothes doing shopping at the .m abc something doing shopping at the .mabc" why does something like :

    use warnings 'all'; use strict; use autodie; open my $input, '<', $ARGV[0]; open my $out, '>', $ARGV[1]; while (<$input>) { my ($before, $between, $after) = /(.*?.clothes|.something +)(.*?)(\.m.*)/; print {$out} "$before $after"; }

    does not read the values :"abc abcabc" and after the explanations can you tell me how could I do this?

      The matching only happens once, unless you specify the /g modifier.

      I'd probably use look-arounds for what you need:

      #!/usr/bin/perl use warnings; use strict; use Syntax::Construct qw{ \K }; while (<DATA>) { s/ (?:clothes|something) # Starting keyword. \K # Don't include the previous part into th +e replacement. (.*?) # The part to be quoted. (?=\.m) # Followed by ".m". /'$1'/xg; print; } __DATA__ abc clothes doing shopping at the .m abc something doing shopping at t +he .mabc
      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,