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

2023-11-21 Thread gordonfish
, $regex, $subst) = @_; $contents =~ s/$regex/$subst/mg; return $contents; } } &substitute_lines ($data, qr/^foo (whatever) bar$/mg, 'bar $1 baz'); Which (mostly) works as expected. Unfortunately, this won't interpolate the matched group $1.

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

2023-10-26 Thread Octavian Rasnita
strict; use warnings; my $data = "foo whatever bar"; $data = substitute_lines( $data, qr/^foo (whatever) bar$/, 'bar $1 baz'); print "$data\n"; $data = "foo whatever bar whatever2 baz"; $data = substitute_lines( $data, qr/^foo (whatever) bar (wha

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

2023-10-25 Thread Claude Brown via beginners
I should add that if the script reads values of $regex or $subst from an external source, then my use of eval is seriously flawed. For example, that external source might provide this value for $subst: /; system("do-bad-things"); qr/x/ The eval will execute the "do-bad-

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 (

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

2023-10-25 Thread Andrew Solomon
> project), So I have come with this; > > > sub substitute_lines { > my ($contents, $regex, $subst) = @_; > $contents =~ s/$regex/$subst/mg; > return $contents; > } > } > > &substitute_lines ($data, qr/^foo (whatever) bar$/mg, &#

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

2023-10-25 Thread Josef Wolf
be embedded into a bigger project), So I have come with this; sub substitute_lines { my ($contents, $regex, $subst) = @_; $contents =~ s/$regex/$subst/mg; return $contents; } } &substitute_lines ($data, qr/^foo (whatever) bar$/mg, 'bar $1 baz&#

Re: problem with regex qr operator

2015-06-25 Thread Brandon McCaig
Mike: On Thu, Jun 25, 2015 at 5:42 AM, Mike Martin wrote: > Hi > I am currently getting issues with regexes that use the qr operator. > > The results with qr are different than without. This is a small sample > program to illustrate it > > use strict; > > my $str=&#x

problem with regex qr operator

2015-06-25 Thread Mike Martin
Hi I am currently getting issues with regexes that use the qr operator. The results with qr are different than without. This is a small sample program to illustrate it use strict; my $str='Database Administrator'; my $pattern= '(?=^(?:(?!(?:datab|network|system)).)*$).*(?:Adm

Re: qr() and escaping a RegEx string

2007-10-27 Thread yitzle
Thanks. That answers my question! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: qr() and escaping a RegEx string

2007-10-27 Thread John W . Krahn
On Saturday 27 October 2007 21:18, yitzle wrote: > I want to search some text for a user provided string. > I was getting input and escaping it with qr(). I then used the > qr()'ed value as input to my grep. > However, I realized that qr() works too well for my pursposes. I want

Re: qr() and escaping a RegEx string

2007-10-27 Thread Gunnar Hjalmarsson
yitzle wrote: I want to search some text for a user provided string. I was getting input and escaping it with qr(). I then used the qr()'ed value as input to my grep. However, I realized that qr() works too well for my pursposes. I want the user input to be interpretted as a string literal

qr() and escaping a RegEx string

2007-10-27 Thread yitzle
I want to search some text for a user provided string. I was getting input and escaping it with qr(). I then used the qr()'ed value as input to my grep. However, I realized that qr() works too well for my pursposes. I want the user input to be interpretted as a string literal, not as a RegE

Re: qr + shift

2007-08-15 Thread Paul Lalli
On Aug 14, 3:57 pm, [EMAIL PROTECTED] (Jay Savage) wrote: > On 8/12/07, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote: > > > John W. Krahn wrote: > > > yitzle wrote: > > >> Works: > > >> my $t = shift; > > >> my $id = qr($t); &

Re: qr + shift

2007-08-14 Thread Jay Savage
On 8/12/07, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote: > John W. Krahn wrote: > > yitzle wrote: > >> Works: > >> my $t = shift; > >> my $id = qr($t); > >> Doesn't work: > >> my $id = qr(shift); > >> > >

Re: qr + shift

2007-08-12 Thread Paul Lalli
On Aug 12, 12:55 am, [EMAIL PROTECTED] (Yitzle) wrote: > Works: > my $t = shift; > my $id = qr($t); > Doesn't work: > my $id = qr(shift); > > Why? Variables interpolate. Function calls don't. Paul Lalli -- To unsubscribe, e-mail: [

Re: qr + shift

2007-08-12 Thread Mr. Shawn H. Corey
John W. Krahn wrote: yitzle wrote: Works: my $t = shift; my $id = qr($t); Doesn't work: my $id = qr(shift); Why? perldoc -q "How do I expand function calls in a string" It's because qr is not a function, it's a quote-like operator. Also see `perld

Re: qr + shift

2007-08-12 Thread John W. Krahn
yitzle wrote: Works: my $t = shift; my $id = qr($t); Doesn't work: my $id = qr(shift); Why? perldoc -q "How do I expand function calls in a string" John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts

Re: qr + shift

2007-08-11 Thread yaron
Hi, my $id = qr(shift); will not work from the same reason that my $id = "shift" will not work!!! Yours, Yaron Kahanovitch - Original Message - From: "yitzle" <[EMAIL PROTECTED]> To: beginners@perl.org Sent: Sunday, August 12, 2007 7:55:38 AM (GMT+0200)

qr + shift

2007-08-11 Thread yitzle
Works: my $t = shift; my $id = qr($t); Doesn't work: my $id = qr(shift); Why? Thanks! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: How to use qr to eliminate redundant code

2005-06-07 Thread John W. Krahn
Siegfried Heintze wrote: This piece of code works, but it has a redundant pattern in it. Every time I try to create a variable "my $pRole = qr/Assistant|Executive|Senior//;" That won't work because of the syntax error, you have an extra '/' character at the end. Th

How to use qr to eliminate redundant code

2005-06-07 Thread Siegfried Heintze
This piece of code works, but it has a redundant pattern in it. Every time I try to create a variable "my $pRole = qr/Assistant|Executive|Senior//;" to replace the redundant patterns, it stops working. It has something to do with the "gi" qualifiers for the patterns. Can someo

qr()

2003-09-23 Thread Dan Muey
Howdy list, I am tryign to figure the best way to put a regex in a string: my $regxp = '\w+(\.\d+)?\*\w+'; or my $regxp = qr(\w+(\.\d+)?\*\w+); if($foo !~ m/^$regxp$/) { die "you badly formatted thing you"; } Both ways seem to work the same it's just that qr chan

Re: What is qr for in reg expressions in a a string?

2003-08-14 Thread Rob Dixon
Alan Perry wrote: > <[EMAIL PROTECTED]> wrote: > > I've been reading the previous post and was wondering about what qr does [snip] > For the second array item, the line translates to: > print "found\n" if $str =~ '^from: [EMAIL PROTECTED]'mi >

Re: What is qr for in reg expressions in a a string?

2003-08-14 Thread Motherofperls
In a message dated 8/13/03 8:59:58 AM Pacific Daylight Time, [EMAIL PROTECTED] writes: Thanks, I had wonderful documentation program with perl 5.6. But when I updated to 5.8 with mod_perl php and apache (after formatting my disc because of a virus) I lost the documentation program, and nothi

RE: What is qr for in reg expressions in a a string?

2003-08-14 Thread Perry, Alan
On Wednesday, August 13, 2003 10:45, [EMAIL PROTECTED] wrote: >I've been reading the previous post and was wondering about what qr does in >this code. > >use strict; >  use warnings; > >  my @array = ( >    qr'^to: myprog'mi, >    qr'^from: [EMAIL

What is qr for in reg expressions in a a string?

2003-08-14 Thread Motherofperls
I've been reading the previous post and was wondering about what qr does in this code. use strict;   use warnings;   my @array = (     qr'^to: myprog'mi,     qr'^from: [EMAIL PROTECTED]'mi   );   my $str = 'To: myprog with trailing text';   foreach (@array) {     print "found\n" if $str =~ $_   }

RE: What is qr for in reg expressions in a a string?

2003-08-14 Thread Perry, Alan
On Wednesday, August 13, 2003 11:42, Rob Dixon wrote: > >Alan Perry wrote: >> <[EMAIL PROTECTED]> wrote: >> > I've been reading the previous post and was wondering about what qr does > >[snip] > >> For the second array item, the line translates to:

Re: qr// -- huh?

2003-06-01 Thread R. Joseph Newton
Jeff Westman wrote: > Okay, this may sound pretty basic, but what is the qr// function used for? I > rarely see it used. I've consulted perldoc perlre, and it still makes no > sense. > > Could someone give a simple, practical example of this in use? > > Thanks! > &g

Re: qr// -- huh?

2003-05-29 Thread Jenda Krynicky
From: "John W. Krahn" <[EMAIL PROTECTED]> > If you need to use a variable in a regular expression it is usually > more efficient to compile it with qr// than to have perl interpolate > and compile it at run-time. s/at run-time/each time/ Jenda = [EMAIL PROTECTED] ===

Re: qr// -- huh?

2003-05-29 Thread John W. Krahn
Jeff Westman wrote: > > Okay, this may sound pretty basic, but what is the qr// function used for? It is used to compile a regular expression and store it in a scalar. Note that the value stored is NOT a simple text string. $ perl -le' my $x = qr/.*XX.*/; my $y = q/.*XX.*/; print &

Re: qr// -- huh?

2003-05-29 Thread WC -Sx- Jones
On Wednesday, May 28, 2003, at 12:17 PM, Jeff Westman wrote: qr// See http://webmaster.indiana.edu/perl56/pod/perlop.html HTH/Sx http://InSecurity.org/ _Sx ('>iudicium ferat //\ Have Computer - v_/_W

qr// -- huh?

2003-05-29 Thread Jeff Westman
Okay, this may sound pretty basic, but what is the qr// function used for? I rarely see it used. I've consulted perldoc perlre, and it still makes no sense. Could someone give a simple, practical example of this in use? Thanks! -Jeff __ Do you Yahoo!?

What did people do before qr//

2002-12-11 Thread David Eason
I have recently discovered qr// and it seems to be the only way to cut and paste a functioning regex literal into a variable assignment. Notice below I had to do little more than cut and paste the regex literal from Method 3 into the qr expression in Method 1. Nifty. That is PRECISELY what I want

Re: qr/$stuff/

2002-07-31 Thread Jenda Krynicky
From: Nikola Janceski <[EMAIL PROTECTED]> > I want to make sure that I am using this correctly for efficiency. > > I want to use $stuff as a regex but I want to store it in a data > structure. so when I do use it in a regex will it be more efficient > than just saying /$stuff/? Yes. You do use

qr/$stuff/

2002-07-31 Thread Nikola Janceski
iteration. ex: foreach my $stuff (@stuffs){ $INFO{key1}{regex} = qr/$stuff/; ## do stuff using $INFO{key1}{regex} several times as so: foreach my $test (@tests){ ## yeah I know I could store @tests as qr regexs but this is an example print "somthin