in reply to Re: Reading from files
in thread Reading from files

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?

Replies are listed 'Best First'.
Re^3: Reading from files
by choroba (Cardinal) on Jan 18, 2016 at 13:03 UTC
    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,