, $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.
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
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-
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 (
> 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,
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
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=
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
Thanks. That answers my question!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
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
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
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
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);
&
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);
> >>
> >
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: [
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
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
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)
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/
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
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
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
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
>
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
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
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 =~ $_
}
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:
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
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] ===
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 &
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
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!?
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
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
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
35 matches
Mail list logo