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

2023-11-21 Thread gordonfish
On 10/25/23 10:32, Josef Wolf wrote: [...] Basically, I want to do the same as $data =~ s/^foo (whatever) bar$/bar $1 baz/mg; but with a different interface (because it has to be embedded into a bigger project), So I have come with this; sub substitute_lines { my ($contents,

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 { $

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

2023-10-25 Thread Josef Wolf
Hallo all, maybe this is not exactly a beginner question, but I could not find an appropriate mailing list (all other lists seem to be developer realted). Basically, I want to do the same as $data =~ s/^foo (whatever) bar$/bar $1 baz/mg; but with a different interface (because it has to be

Re: Substitution operator is not working in perl - Windows OS

2014-12-05 Thread Jitendra Barik
quot; or die($!); >>> > >>> > for(@array){ >>> > #print "Hi"; >>> > s/\%VERSIONS\%/$version1/g; >>> > >>> > >>> > } >>> > untie(@array); >>> > >>> > FILE: >>>

Re: Substitution operator is not working in perl - Windows OS

2014-12-05 Thread Adam Millerchip
e::File,"$rtf1" or die($!); >> > >> > for(@array){ >> > #print "Hi"; >> > s/\%VERSIONS\%/$version1/g; >> > >> > >> > } >> > untie(@array); >> > >> > FILE: >> > ***

Re: Substitution operator is not working in perl - Windows OS

2014-12-04 Thread Jitendra Barik
gt; > *** > > > > *Version *%VERSION%, Hello,HI > > In the substitution, you have VERSIONS but in the file, you have VERSION > > If the S is optional, use: s/\%VERSIONS?\%/$version1/g; > > > -- > Don&

Re: Substitution operator is not working in perl - Windows OS

2014-12-04 Thread Shawn H Corey
NS\%/$version1/g; > > > } > untie(@array); > > FILE: > *** > > *Version *%VERSION%, Hello,HI In the substitution, you have VERSIONS but in the file, you have VERSION If the S is optional, use: s/\%VERSIONS?\%/$version1/g; -- Don't stop where t

Re: Substitution operator is not working in perl - Windows OS

2014-12-04 Thread Hans Ginzel
Hello, I am sorry, I don't know what are you doing wrong, but this code works for me. use strict; #use warnings; use Tie::File; my $file = 'file.txt'; my $version1 = "JITENDRA"; tie my(@array), 'Tie::File', $file or die "Cannot open file `$file': $!"; for(@array) { #warn "F: ", $_; s/%VER

Substitution operator is not working in perl - Windows OS

2014-12-04 Thread Jitendra Barik
HI All, My code is: $version1 = "JITENDRA"; tie @array,Tie::File,"$rtf1" or die($!); for(@array){ #print "Hi"; s/\%VERSIONS\%/$version1/g; } untie(@array); FILE: *** *Version *%VERSION%, Hello,HI *Installation Notes* T

Re: perlre(1) and substitution evaluations

2013-11-30 Thread Charles DeRykus
On 11/30/2013 5:16 AM, Lars Noodén wrote: On 11/30/2013 02:55 PM, Charles DeRykus wrote: [ .. Thanks. I see those in perlop and perlfunc. In perlfunc, it is grouped as "Regular expressions and pattern matching" though that man page just points to perlop. A really clear description in perlre

Re: perlre(1) and substitution evaluations

2013-11-30 Thread Lars Noodén
On 11/30/2013 02:55 PM, Charles DeRykus wrote: > See the substitution operator in perlop: > > |||<http://perldoc.perl.org/functions/s.html>| A |/e| will cause the > replacement portion to be treated as a full-fledged Perl expression and > evaluated right then and there. I

Re: perlre(1) and substitution evaluations

2013-11-30 Thread Charles DeRykus
On 11/30/2013 4:07 AM, Lars Noodén wrote: perlre(1) seems to be missing information about substitution evaluations with the /e option. The functionality is present in perl: perl -e '$_=2; s/2/1+3/e; print' But it is not listed in the pod documentation for v5.16.3 or v5

Re: perlre(1) and substitution evaluations

2013-11-30 Thread Rob Dixon
"Lars Noodén" wrote: >perlre(1) seems to be missing information about substitution >evaluations >with the /e option. The functionality is present in perl: > > perl -e '$_=2; s/2/1+3/e; print' > >But it is not listed in the pod documentation fo

perlre(1) and substitution evaluations

2013-11-30 Thread Lars Noodén
perlre(1) seems to be missing information about substitution evaluations with the /e option. The functionality is present in perl: perl -e '$_=2; s/2/1+3/e; print' But it is not listed in the pod documentation for v5.16.3 or v5.18.1. The modifier /e is described in "P

Re: substitution: interpolate capture buffer into variable?

2012-12-26 Thread Charles DeRykus
On Wed, Dec 26, 2012 at 10:29 AM, Paul Johnson wrote: > On Wed, Dec 26, 2012 at 04:10:06PM +0100, gator...@yahoo.de wrote: >> Hi, >> >> I would like to store regular expressions and substitution strings in >> a hash variable. If a given string matches any of

Re: substitution: interpolate capture buffer into variable?

2012-12-26 Thread gator_ml
On 2012-12-26 19:29, Paul Johnson wrote: > This is a situation where string eval is warranted: > > eval "\$s =~ s/\$rx/$r/"; ... thanks a lot! Now that I now how it works, I can't believe I couldn't find the problem! I had tried string eval too; the real trick that I didn't get right is that t

Re: substitution: interpolate capture buffer into variable?

2012-12-26 Thread Paul Johnson
On Wed, Dec 26, 2012 at 04:10:06PM +0100, gator...@yahoo.de wrote: > Hi, > > I would like to store regular expressions and substitution strings in > a hash variable. If a given string matches any of the stored patterns, > the corresponding substitution should be applied. What or

Re: substitution: interpolate capture buffer into variable?

2012-12-26 Thread timothy adigun
Hi, Please, check my comments below: On Wed, Dec 26, 2012 at 4:10 PM, wrote: > Hi, > > I would like to store regular expressions and substitution strings in > a hash variable. If a given string matches any of the stored patterns, > the corresponding substitution should b

substitution: interpolate capture buffer into variable?

2012-12-26 Thread gator_ml
Hi, I would like to store regular expressions and substitution strings in a hash variable. If a given string matches any of the stored patterns, the corresponding substitution should be applied. What originally looked trivial turned out to be quite a challenge, particularly if the substitution

Re: regx substitution question

2012-09-05 Thread John W. Krahn
Shlomi Fish wrote: thanks for your answer. See below for my response. On Wed, 5 Sep 2012 09:54:11 -0400 Shawn H Corey wrote: On Wed, 5 Sep 2012 14:33:13 +0100 jet speed wrote: i have an regx question. i have the array contents, now i want to remove the first 2 characters (fc) of each elem

Re: regx substitution question

2012-09-05 Thread John W. Krahn
Shlomi Fish wrote: Replying to myself, I have a correction which Shawn inspired. On Wed, 5 Sep 2012 16:49:42 +0300 Shlomi Fish wrote: On Wed, 5 Sep 2012 14:33:13 +0100 jet speed wrote: i have an regx question. i have the array contents, now i want to remove the first 2 characters (fc) of e

Re: regx substitution question

2012-09-05 Thread John W. Krahn
Shlomi Fish wrote: On Wed, 5 Sep 2012 14:33:13 +0100 jet speed wrote: i have an regx question. i have the array contents, now i want to remove the first 2 characters (fc) of each element in the array and store it in a second array ex: @array2 @array ="fc20/1, fc30/22, fc40/3, fc20/1"; outpu

Re: regx substitution question

2012-09-05 Thread Jim Gibson
On Sep 5, 2012, at 7:02 AM, Shlomi Fish wrote: >># remove the first 2 characters from every element of the array >>my @array2 = map { s/^..//msx } @array1; >> > > This code is wrong in two respects: > > 1. the map clause will return the return value of the s/// subtitution and > will

Re: regx substitution question

2012-09-05 Thread Shlomi Fish
Replying to myself, I have a correction which Shawn inspired. On Wed, 5 Sep 2012 16:49:42 +0300 Shlomi Fish wrote: > Hi Sj, > > On Wed, 5 Sep 2012 14:33:13 +0100 > jet speed wrote: > > > Hi All, > > > > i have an regx question. i have the array contents, now i want to > > remove the first 2

Re: regx substitution question

2012-09-05 Thread Shlomi Fish
Hi Shawn, thanks for your answer. See below for my response. On Wed, 5 Sep 2012 09:54:11 -0400 Shawn H Corey wrote: > On Wed, 5 Sep 2012 14:33:13 +0100 > jet speed wrote: > > > Hi All, > > > > i have an regx question. i have the array contents, now i want to > > remove the first 2 characters

Re: regx substitution question

2012-09-05 Thread Shawn H Corey
On Wed, 5 Sep 2012 14:33:13 +0100 jet speed wrote: > Hi All, > > i have an regx question. i have the array contents, now i want to > remove the first 2 characters (fc) of each element in the array and > store it in a second array ex: @array2 > > @array ="fc20/1, fc30/22, fc40/3, fc20/1"; > > o

Re: regx substitution question

2012-09-05 Thread Shlomi Fish
Hi Sj, On Wed, 5 Sep 2012 14:33:13 +0100 jet speed wrote: > Hi All, > > i have an regx question. i have the array contents, now i want to > remove the first 2 characters (fc) of each element in the array and > store it in a second array ex: @array2 > > @array ="fc20/1, fc30/22, fc40/3, fc20/1"

regx substitution question

2012-09-05 Thread jet speed
Hi All, i have an regx question. i have the array contents, now i want to remove the first 2 characters (fc) of each element in the array and store it in a second array ex: @array2 @array ="fc20/1, fc30/22, fc40/3, fc20/1"; output @array2 ="20/1, 30/22, 40/3, 20/1"; please advice. Thanks Sj

Re: double substitution

2011-09-20 Thread Shawn H Corey
On 11-09-19 08:56 PM, Rajeev Prasad wrote: $string="alpha number='42'" $string=~s/.*\=// ; $string=~s/\'//g; to get 42 and not '42' can these two substitutions be combined? thank you. It depends on what you want to extract. To extract a string inside single quotes after an equal sign:

Re: double substitution

2011-09-19 Thread Rob Dixon
On 20/09/2011 02:17, Jim Gibson wrote: On 9/19/11 Mon Sep 19, 2011 5:56 PM, "Rajeev Prasad" scribbled: $string="alpha number='42'" $string=~s/.*\=// ; $string=~s/\'//g; to get 42 and not '42' can these two substitutions be combined? If you know what you want to extract, then use capturin

Re: double substitution

2011-09-19 Thread Jim Gibson
On 9/19/11 Mon Sep 19, 2011 5:56 PM, "Rajeev Prasad" scribbled: > $string="alpha number='42'" > $string=~s/.*\=// ; > $string=~s/\'//g; > > to get 42 and not '42' > > > can these two substitutions be combined? If you know what you want to extract, then use capturing: if( $string =~ /'(\d+)

Re: double substitution

2011-09-19 Thread Rob Dixon
On 20/09/2011 01:56, Rajeev Prasad wrote: $string="alpha number='42'" $string=~s/.*\=// ; $string=~s/\'//g; to get 42 and not '42' can these two substitutions be combined? Hi Rajeev Well they can be combined, and because it is far from obvious what your code is doing I think it should be r

double substitution

2011-09-19 Thread Rajeev Prasad
$string="alpha number='42'" $string=~s/.*\=// ; $string=~s/\'//g; to get 42 and not '42' can these two substitutions be combined? thank you. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: why si this code not working (variable substitution)

2011-08-19 Thread Rajeev Prasad
Beginners Sent: Friday, August 19, 2011 2:59 AM Subject: Re: why si this code not working (variable substitution) Hi, On Wed, 17 Aug 2011 16:15:18 -0400 "Uri Guttman" wrote: > >>>>> "RP" == Rajeev Prasad writes: > >  RP> foreach $line (@arr1){ >

Re: why si this code not working (variable substitution)

2011-08-19 Thread Shlomi Fish
ou do in a program #!/usr/bin/perl use strict; use warnings; my $expr = shift(@ARGV); eval $expr; Then if you allow the user of the program to input arbitrary Perl code inside $ARGV[0], which will then be executed. So don't abuse string eval this way. > and also what this 'ge' i

Re: why si this code not working (variable substitution)

2011-08-19 Thread Shlomi Fish
Hi, On Wed, 17 Aug 2011 16:15:18 -0400 "Uri Guttman" wrote: > > "RP" == Rajeev Prasad writes: > > RP> foreach $line (@arr1){ > RP>  foreach (@arr2) { > RP>  chomp($_); > RP>  @arr3 = split(/ /,$_); > RP>  $mystringvar = eval "qq{$line}"; <--this > RP> su

Re: why si this code not working (variable substitution)

2011-08-17 Thread Uri Guttman
> "RP" == Rajeev Prasad writes: RP> foreach $line (@arr1){ RP>  foreach (@arr2) { RP>  chomp($_); RP>  @arr3 = split(/ /,$_); RP>  $mystringvar = eval "qq{$line}"; <--this suggestion came from web search. and it is a very bad idea. string eval is very dange

Re: why si this code not working (variable substitution)

2011-08-17 Thread Rajeev Prasad
b. thx to all coders out there. From: Shlomi Fish To: Rajeev Prasad Cc: Perl Beginners Sent: Wednesday, August 17, 2011 10:54 AM Subject: Re: why si this code not working (variable substitution) Hi Rajeev, On Tue, 16 Aug 2011 17:38:16 -0700 (PDT) Rajeev Prasad wrote: >   >   >

Re: why si this code not working (variable substitution)

2011-08-17 Thread Shlomi Fish
Hi Rajeev, On Tue, 16 Aug 2011 17:38:16 -0700 (PDT) Rajeev Prasad wrote: >   >   > foreach $str1 (@arr1){ >  foreach (@arr2) { >  @arr3 = split(/ /,"$_"); >  print "array = @arr3  element0 = $arr3[0] element1 = $arr3[1]";   #this > is just to check, it showing values 0 and 1 as correctly assigne

why si this code not working (variable substitution)

2011-08-16 Thread Rajeev Prasad
cc 233 sdf xyz       BUT I am getting:---SUBSTITUTION not happening comm cc $arr3[0] sdf xyz comm scdrf cc $arr3[0] sdf xyz comm dddbb cc $arr3[0] sdf xyz     please help resolve. thx. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail

Re: ip address substitution

2011-03-17 Thread Rob Dixon
On 16/03/2011 15:08, Shawn H Corey wrote: On 11-03-16 11:05 AM, John W. Krahn wrote: Jim wrote: $old_ip_address = "1.2.3.4"; $new_ip_address = "5.6.7.8" $old_ip_address_regexp = $old_ip_address; $old_ip_address_regexp =~ s/\./\\./ig; $read_line =~ s/(\D*)$old_ip_address_regexp(\D*)/$1$new_ip_ad

Re: ip address substitution

2011-03-16 Thread Brian Fraser
/x does exactly what you think it does; It's "free form" style, where any non-escaped whitespace is ignored. See perlretut[0], perlop[1], and perlre[2]. (?http://perldoc.perl.org/perlretut.html [1] http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators [2] http://perldoc.perl.org/perlre.h

Re: ip address substitution

2011-03-16 Thread Shawn H Corey
On 11-03-16 11:05 AM, John W. Krahn wrote: Jim wrote: $old_ip_address = "1.2.3.4"; $new_ip_address = "5.6.7.8" $old_ip_address_regexp = $old_ip_address; $old_ip_address_regexp =~ s/\./\\./ig; $read_line =~ s/(\D*)$old_ip_address_regexp(\D*)/$1$new_ip_address$2/ig; (\D*) won't work because it c

Re: ip address substitution

2011-03-16 Thread John W. Krahn
find any fault in it or see if I overlooked something, please? Of particular concern is if I've considered enough by wrapping my substitution string within (\D*) $old_ip_address = "1.2.3.4"; $new_ip_address = "5.6.7.8" $old_ip_address_regexp = $old_ip_address; $old_ip_addr

Re: ip address substitution

2011-03-16 Thread Shawn H Corey
On 11-03-16 10:29 AM, Jim wrote: $old_ip_address_regexp = $old_ip_address; $old_ip_address_regexp =~ s/\./\\./ig; $old_ip_address_regexp = quotemeta( $old_ip_address ); See `perldoc -f quotemeta`. -- Just my 0.0002 million dollars worth, Shawn Confusion is the first step of understand

ip address substitution

2011-03-16 Thread Jim
fault in it or see if I overlooked something, please? Of particular concern is if I've considered enough by wrapping my substitution string within (\D*) $old_ip_address = "1.2.3.4"; $new_ip_address = "5.6.7.8" $old_ip_address_regexp = $old_ip_address; $old_ip_addr

RE: string substitution command question

2011-02-26 Thread Katya Gorodinsky
, Katya -Original Message- From: Richard Green [mailto:gree...@uw.edu] Sent: Saturday, February 26, 2011 10:07 PM To: beginners@perl.org Subject: string substitution command question Hi Perl users, Quick question, I have a one long string with tab delimited values separated

Re: string substitution command question

2011-02-26 Thread Richard Green
d? >> I have $ to designate the end of the row >> $gene_id > > $gene_id designates $gene_id period. > >> > Why are you escaping the quote marks? >> I thought it would be easier to perform substitution without them > > What made you think that? > >>

Re: string substitution command question

2011-02-26 Thread John Delacour
the quote marks? I thought it would be easier to perform substitution without them What made you think that? > Why is there no space after 'gene_id'? I guess there should be You can guess as much as you like but Perl Regular Expressions don't care what you think or

Re: string substitution command question

2011-02-26 Thread Parag Kalra
On Sat, Feb 26, 2011 at 12:56 PM, Uri Guttman wrote: > > "PK" == Parag Kalra writes: > > >> why are you doing s/// against $_? by default it does that. > > you didn't rectify this one. > Oops. Missed that. > > > PK> Sorry. Hope this reply is better and so as the following code: > > muc

Re: string substitution command question

2011-02-26 Thread Richard Green
> What is $gene_id? > Are you by any chance using '$' at the beginning of your search pattern > instead of the end? I have $ to designate the end of the row $gene_id > > Why are you escaping the quote marks? I thought it would be easier to perform substitution witho

Re: string substitution command question

2011-02-26 Thread Uri Guttman
> "PK" == Parag Kalra writes: >> why are you doing s/// against $_? by default it does that. you didn't rectify this one. PK> Sorry. Hope this reply is better and so as the following code: much better. PK> use strict; PK> use warnings; PK> while(){ PK> $_ =~ s/NM_(\d+

Re: string substitution command question

2011-02-26 Thread Uri Guttman
-- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org

Re: string substitution command question

2011-02-26 Thread Parag Kalra
On Sat, Feb 26, 2011 at 12:34 PM, Uri Guttman wrote: > > "PK" == Parag Kalra writes: > > PK> use strict; > PK> use warnings; > PK> while(){ > PK> chomp; > > why are you chomping here when you add in the \n later? > Agreed and corrected in the example at the bottom. > PK> if

Re: string substitution command question

2011-02-26 Thread Uri Guttman
> "PK" == Parag Kalra writes: PK> use strict; PK> use warnings; PK> while(){ PK> chomp; why are you chomping here when you add in the \n later? PK> if ($_ =~ /NM_(\d+)/){ PK> my $found = $1; PK> $_ =~ s/$found/$found:12345/g; many issues there. why do

Re: string substitution command question

2011-02-26 Thread John Delacour
e_id "NM_001033581:12346"; transcript_id "NM_001033581:12346"; Here is the substitution command I am trying to use: $data_string=~ s/$gene_id\"NM_173083\"\; transcript_id \"NM_173083\"\;/\"NM_173083:12345\"\; \"NM_173083:12345\"\;/g; $d

Re: string substitution command question

2011-02-26 Thread Parag Kalra
transcript_id "NM_001033581"; > chr1ucscexon2066701 2066786 0.00+ . > gene_id "NM_001033581"; transcript_id "NM_001033581"; > > I am trying to perform substitution on some values at the end of each rows, > for example, I'm trying

string substitution command question

2011-02-26 Thread Richard Green
3581"; chr1ucscexon2066701 2066786 0.00+ . gene_id "NM_001033581"; transcript_id "NM_001033581"; I am trying to perform substitution on some values at the end of each rows, for example, I'm trying to replace the above string

Re: Perl, pattern matching, substitution, replacing

2010-11-14 Thread Jim Gibson
At 2:16 PM -0500 11/14/10, shawn wilson wrote: so, if you've got a file, do something like: while ($line = ) { $line =~ m/^(.+)$/ig; print "$1<\/s>\n"; } If all you want to do is print each line in the file surrounded by tags, you don't need regular expressions, and you don't need to esca

Re: Perl, pattern matching, substitution, replacing

2010-11-14 Thread Rob Dixon
On 14/11/2010 19:04, Zachary Brooks wrote: What happened when I used the code -- $hello =~ s/^(.+)$/\1<\/s>/gis; -- is that is properly marked and the beginning of the sentence and at the end of the sentence, but then it only worked for one sentence. Any suggestions on getting to appear at t

Re: Perl, pattern matching, substitution, replacing

2010-11-14 Thread shawn wilson
so, if you've got a file, do something like: while ($line = ) { $line =~ m/^(.+)$/ig; print "$1<\/s>\n"; } On Sun, Nov 14, 2010 at 1:53 PM, Uri Guttman wrote: > > "sw" == shawn wilson writes: > > sw> second, why not use a place holder like someone recommended yesterday? > sw> somethin

Re: Perl, pattern matching, substitution

2010-11-14 Thread Rob Dixon
On 14/11/2010 13:53, Zachary Brooks wrote: Hey Rob, Of all the feedback. yours was the one I was able to drop into my code and make it work, no matter how rudimentary my understanding of Perl is. Thanks. You're welcome. I'm glad to be able to help. As far as the XML libraries, we are suppose

Re: Perl, pattern matching, substitution, replacing

2010-11-14 Thread Zachary Brooks
What happened when I used the code -- $hello =~ s/^(.+)$/\1<\/s>/gis; -- is that is properly marked and the beginning of the sentence and at the end of the sentence, but then it only worked for one sentence. Any suggestions on getting to appear at the beginning of every sentence and to appea

Re: Perl, pattern matching, substitution, replacing

2010-11-14 Thread shawn wilson
On Sun, Nov 14, 2010 at 1:53 PM, Uri Guttman wrote: > > "sw" == shawn wilson writes: > > sw> second, why not use a place holder like someone recommended yesterday? > sw> something like: > sw> s/^(.+)$/\1<\/s>/g > > what is a placeholder? nothing like that in regexes. what you have there >

Re: Perl, pattern matching, substitution, replacing

2010-11-14 Thread Uri Guttman
> "sw" == shawn wilson writes: sw> second, why not use a place holder like someone recommended yesterday? sw> something like: sw> s/^(.+)$/\1<\/s>/g what is a placeholder? nothing like that in regexes. what you have there is a backreference and used in the wrong place. \1 is meant to b

Re: Perl, pattern matching, substitution, replacing

2010-11-14 Thread Shawn H Corey
On 10-11-14 11:42 AM, Zachary Brooks wrote: $hello = "This is some sample text."; $hello =~ s/^..//gi; $hello =~ s/..$/<\/s>/gi; print "$hello\n"; *is is some sample tex* The meta-character '.' matches every character except a newline. The first subs

Re: Perl, pattern matching, substitution, replacing

2010-11-14 Thread shawn wilson
On Sun, Nov 14, 2010 at 11:42 AM, Zachary Brooks wrote: > Hello again, > > Yesterday I had a question on pattern matching. A couple of people > responded > with very useful information. After some finagling, I got my rudimentary > code to work. I'm a PhD student studying computational linguistics

Perl, pattern matching, substitution, replacing

2010-11-14 Thread Zachary Brooks
Hello again, Yesterday I had a question on pattern matching. A couple of people responded with very useful information. After some finagling, I got my rudimentary code to work. I'm a PhD student studying computational linguistics without any formal programming training. While there are various mod

Re: Perl, pattern matching, substitution

2010-11-13 Thread Rob Dixon
ello =~ s/.*<\/DATELINE>//gi; print "$hello\n"; This works until the code comes across a quotation mark ("). So then I replace double quotation marks (") with single quotation marks ('). But then as, I put more text under $hello, the code seems to break. For example,

Re: Perl, pattern matching, substitution

2010-11-13 Thread Sheppy R
I've had similar issues and the \Q \E flags didn't fix it. One thing I've done to fix an issue where regex metacharacters are being caught is to do a replace on all of the characters to include a \ right in front. Something like this: open (my $FILE, "<", $file) or die "$!\n"; my @lines = <$FILE

Re: Perl, pattern matching, substitution

2010-11-13 Thread Shawn H Corey
On 10-11-13 01:42 PM, Zachary Brooks wrote: 1. My first approach was to use substitute to get rid of a range of things between and. A short version looks like this. $hello = " man at the bar order the"; $hello =~ s/.*<\/DATELINE>//gi; print "$hello\n"; I was about to say that you should use

Perl, pattern matching, substitution

2010-11-13 Thread Zachary Brooks
uot;$hello\n"; This works until the code comes across a quotation mark ("). So then I replace double quotation marks (") with single quotation marks ('). But then as, I put more text under $hello, the code seems to break. For example, running the substitution against the code b

Re: Substitution Problem

2010-06-28 Thread Chas. Owens
On Mon, Jun 28, 2010 at 19:48, John W. Krahn wrote: snip > s/\((\d+)\)/($1)/g; snip Since Perl 5.8.0, \d does not mean [0-9], it means any character that is classified as a digit in Unicode. In Perl 5.12.1, there are five hundred seventy-seven characters that will match \d. If it is your intent

Re: Substitution Problem

2010-06-28 Thread Steve Bertrand
On 2010.06.28 20:39, jimston...@aol.com wrote: > > In a message dated 6/28/2010 7:49:47 P.M. Eastern Daylight Time, > jwkr...@shaw.ca writes: > > jimston...@aol.com wrote: >> >> can anyone give me some help on a perl program to change a file of mine. >> The string is: >> >> $_ = "from ''ala

Re: Substitution Problem

2010-06-28 Thread Jimstone77
In a message dated 6/28/2010 7:49:47 P.M. Eastern Daylight Time, jwkr...@shaw.ca writes: jimston...@aol.com wrote: > > can anyone give me some help on a perl program to change a file of mine. > The string is: > > $_ = "from ''alam' (481) or possibly (in the sense of dumbness); > solitary;

Re: Substitution Problem

2010-06-28 Thread John W. Krahn
jimston...@aol.com wrote: can anyone give me some help on a perl program to change a file of mine. The string is: $_ = "from ''alam' (481) or possibly (in the sense of dumbness); solitary; Ulam, the (6155) name of two Soldiers;--Ulam." Where each line is $_ I'm trying to substitute a hyperli

Re: Substitution Problem

2010-06-28 Thread John W. Krahn
jimston...@aol.com wrote: can anyone give me some help on a perl program to change a file of mine. The string is: $_ = "from ''alam' (481) or possibly (in the sense of dumbness); solitary; Ulam, the (6155) name of two Soldiers;--Ulam." Where each line is $_ I'm trying to substitute a hyperli

Re: Substitution Problem

2010-06-28 Thread Jimstone77
same thing with each line in a file. Should I use a substitution? Can anyone show me some code to accomplish this. Thanks.

Re: Can we perform substitution to the matched pattern inside a regular expression so that the modified pattern gets returned instead of earlier matched one ?

2010-05-13 Thread C.DeRykus
On May 5, 7:02 am, learn.tech...@gmail.com (Amit Saxena) wrote: > On Fri, Apr 30, 2010 at 10:40 PM, C.DeRykus wrote: > > On Apr 30, 3:55 am, learn.tech...@gmail.com (Amit Saxena) wrote: > > > Hello everybody, > > > > Can we perform substitution to the ma

Re: Can we perform substitution to the matched pattern inside a regular expression so that the modified pattern gets returned instead of earlier matched one ?

2010-05-13 Thread C.DeRykus
On May 5, 7:02 am, learn.tech...@gmail.com (Amit Saxena) wrote: > On Fri, Apr 30, 2010 at 10:40 PM, C.DeRykus wrote: > > On Apr 30, 3:55 am, learn.tech...@gmail.com (Amit Saxena) wrote: > > > Hello everybody, > > > > Can we perform substitution to the ma

Re: Can we perform substitution to the matched pattern inside a regular expression so that the modified pattern gets returned instead of earlier matched one ?

2010-05-05 Thread Amit Saxena
On Fri, Apr 30, 2010 at 10:40 PM, C.DeRykus wrote: > On Apr 30, 3:55 am, learn.tech...@gmail.com (Amit Saxena) wrote: > > Hello everybody, > > > > Can we perform substitution to the matched pattern inside a regular > > expression so that the modified pattern gets

Re: Can we perform substitution to the matched pattern inside a regular expression so that the modified pattern gets returned instead of earlier matched one ?

2010-04-30 Thread C.DeRykus
On Apr 30, 3:55 am, learn.tech...@gmail.com (Amit Saxena) wrote: > Hello everybody, > > Can we perform substitution to the matched pattern inside a regular > expression so that the modified pattern gets returned instead of earlier > matched one ? > > As a reference, in the fo

Can we perform substitution to the matched pattern inside a regular expression so that the modified pattern gets returned instead of earlier matched one ?

2010-04-30 Thread Amit Saxena
Hello everybody, Can we perform substitution to the matched pattern inside a regular expression so that the modified pattern gets returned instead of earlier matched one ? As a reference, in the following code below, I want to perform the substitution of "~" character with "_&qu

Re: $_ substitution Question

2010-04-02 Thread jet speed
On Thu, Apr 1, 2010 at 5:58 PM, Shawn H Corey wrote: > jet speed wrote: > >> Hi Chaps, >> >> I need bit more help with this, i slightly modified the code based on the >> inputs, still having the same issue of $_ substitution. >&g

Re: $_ substitution Question

2010-04-01 Thread Shawn H Corey
jet speed wrote: Hi Chaps, I need bit more help with this, i slightly modified the code based on the inputs, still having the same issue of $_ substitution. Appreciate your help with this. ## #!/usr/bin/perl use strict; use warnings; my $base

Re: $_ substitution Question

2010-04-01 Thread jet speed
e or directory # Cheers Js On Thu, Apr 1, 2010 at 5:24 PM, jet speed wrote: > Hi Chaps, > > I need bit more help with this, i slightly modified the code based on the > inputs, still having the same issue of $_ substitutio

Re: $_ substitution Question

2010-04-01 Thread jet speed
Hi Chaps, I need bit more help with this, i slightly modified the code based on the inputs, still having the same issue of $_ substitution. Appreciate your help with this. ## #!/usr/bin/perl use strict; use warnings; my $base = "/usr/

Re: $_ substitution Question

2010-03-30 Thread Shlomi Fish
Hi Sarath, I'm CCing to the list. On Monday 29 Mar 2010 08:55:55 KKde wrote: > HI Shlomi, > > > system("/usr/bin/find \"$_\" -mtime 3 -print -exec ls '{}' \;"); > > I got confused. Can you plz explain me why $_ is surrounded by another > double quotes? Why it isn't interpolated in the outer dou

Re: $_ substitution Question

2010-03-29 Thread jet speed
Many Thanks Simon, John and everyone else for pointing me to the correct direction. Cheeers !! Js On Fri, Mar 26, 2010 at 7:03 PM, Shlomi Fish wrote: > On Friday 26 Mar 2010 20:51:17 John W. Krahn wrote: > > jet speed wrote: > > > Hi, > > > > Hello, > > > > > I have a simple code below, > > > >

Re: $_ substitution Question

2010-03-27 Thread Shlomi Fish
On Saturday 27 Mar 2010 06:59:10 chintan sheth wrote: > Hi , > use system "(/usr/bin/find \"$_\" -type f -mtime 3 -print -exec ls '{}' > \;)"; > No! That's wrong! This is your second reply of this trend. Are you some kind of spammer or troll? Regards, Shlomi Fish --

Re: $_ substitution Question

2010-03-26 Thread chintan sheth
Hi , use system "(/usr/bin/find \"$_\" -type f -mtime 3 -print -exec ls '{}' \;)"; Thanks , Chintan On 3/26/10, Shlomi Fish wrote: > > On Friday 26 Mar 2010 20:51:17 John W. Krahn wrote: > > jet speed wrote: > > > Hi, > > > > Hello, > > > > > I have a simple code below, > > > > > > #

Re: $_ substitution Question

2010-03-26 Thread Shlomi Fish
On Friday 26 Mar 2010 20:51:17 John W. Krahn wrote: > jet speed wrote: > > Hi, > > Hello, > > > I have a simple code below, > > > > ### > > #!/usr/bin/perl > > > > use strict; > > use warnings; > > > > my @list =( '/usr/data/logs' , '/usr/data1/logs'); > > forea

Re: $_ substitution Question

2010-03-26 Thread John W. Krahn
John W. Krahn wrote: jet speed wrote: I have a simple code below, ### #!/usr/bin/perl use strict; use warnings; my @list =( '/usr/data/logs' , '/usr/data1/logs'); foreach (@list) { print "$_ \n"; system "(/usr/bin/find "$_" -mtime 3 -print -exec ls '{}' \;)";

Re: $_ substitution Question

2010-03-26 Thread Shlomi Fish
Hi jet speed, On Friday 26 Mar 2010 19:17:46 jet speed wrote: > Hi, > I have a simple code below, > > ### > #!/usr/bin/perl > > use strict; > use warnings; > > my @list =( '/usr/data/logs' , '/usr/data1/logs'); > foreach (@list) > { > print "$_ \n"; > > system "

Re: $_ substitution Question

2010-03-26 Thread John W. Krahn
jet speed wrote: Hi, Hello, I have a simple code below, ### #!/usr/bin/perl use strict; use warnings; my @list =( '/usr/data/logs' , '/usr/data1/logs'); foreach (@list) { print "$_ \n"; system "(/usr/bin/find "$_" -mtime 3 -print -exec ls '{}' \;)"; } #

$_ substitution Question

2010-03-26 Thread jet speed
Hi, I have a simple code below, ### #!/usr/bin/perl use strict; use warnings; my @list =( '/usr/data/logs' , '/usr/data1/logs'); foreach (@list) { print "$_ \n"; system "(/usr/bin/find "$_" -mtime 3 -print -exec ls '{}' \;)"; } ###

Re: How to use scalar value in substitution pattern?

2009-12-30 Thread Uri Guttman
> "sk" == suresh kumar writes: sk> I got your problem. sk> Pass the parameters like below, sk> &replace_txt('\$a', '$b'); sk> It will work fine. did you test that? it has the same problem as the original code. your other post had better answers. please refrain from answering here un

  1   2   3   4   5   6   >