Re: Using qr// with substitution and group-interpolation in the substitution part

2023-10-26 Thread Octavian Rasnita
ew Solomon" Cc: "Josef Wolf" ; Sent: Thursday, October 26, 2023 12:07 AM Subject: RE: Using qr// with substitution and group-interpolation in the substitution part Josef, Inspired by Levi's “eval” idea, here is my solution: sub substitute_lines { my ($content

RE: Using qr// with substitution and group-interpolation in the substitution part

2023-10-25 Thread Claude Brown via beginners
things" command on your system. -Original Message- From: Claude Brown via beginners Sent: Thursday, October 26, 2023 8:07 AM To: Levi Elias Nystad-Johansen ; Andrew Solomon Cc: Josef Wolf ; beginners@perl.org Subject: RE: Using qr// with substitution and group-interpolation

RE: Using qr// with substitution and group-interpolation in the substitution part

2023-10-25 Thread Claude Brown via beginners
Josef, Inspired by Levi's “eval” idea, here is my solution: sub substitute_lines { my ($contents, $regex, $subst) = @_; eval "\$contents =~ s/$regex/$subst/g"; return $contents; } $data = "foo whatever bar"; $data = &substitute_lines($data, qr/^foo (whatever) bar$/m, 'bar $1 baz'); p

Re: Using qr// with substitution and group-interpolation in the substitution part

2023-10-25 Thread Andrew Solomon
That's a fun question, Josef! I don't think you can pass a replacement phrase around, so this is all I came up with: sub substitute_lines { my ($contents, $subst) = @_; $contents = $subst->($contents); return $contents; } my $data = "foo whatever bar"; print(substitute_lines($data, sub { $