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

2014-12-05 Thread Jitendra Barik
Hi Adam, Yes File is RTF. Regards, Jitendra On Fri, Dec 5, 2014 at 7:57 PM, Adam Millerchip wrote: > Your filename is in a variable called $rtf1, is the file an RTF? > > Maybe something funny is going on with the file-format/encoding, and the > first line doesn't contain %VERSION% when parsed

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

2014-12-05 Thread Adam Millerchip
Your filename is in a variable called $rtf1, is the file an RTF? Maybe something funny is going on with the file-format/encoding, and the first line doesn't contain %VERSION% when parsed by your script. You could try printing out the line in your script to see what it's trying to match: for(@arra

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

2014-12-04 Thread Jitendra Barik
Hi Shawn, it is VERSION. This is the not a issue. s/\%VERSION\%/$version1/g; the correct one. If I changed VERSION to VERSIONABC it is working correctly OR if I add more character to VERSION then it is working. I could not understand why it is not working for me. The first place in the file is n

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

2014-12-04 Thread Shawn H Corey
On Thu, 4 Dec 2014 16:06:26 +0530 Jitendra Barik wrote: > My code is: > > $version1 = "JITENDRA"; > tie @array,Tie::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 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

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 the stored patterns, >> the correspondi

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 originally looked > t

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 be applied. What original

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
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 hyperlink for each NUMBER tha

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. >> >> Appreciate your help with this. >> >> ###

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
Hi All, Further to my previous email, if i add the fulll path of each directory the, $_ Sustitution works with below code #!/usr/bin/perl use strict; use warnings; my @list = ( '/usr/openv/netbackup/logs/bpcd' , '/usr/openv/netbackup/logs/bprd' , '/usr/openv/netbackup/logs/admin' , '/usr/openv

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/openv/netba

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 '{}' \;)"; } #

Re: Substitution question

2009-07-01 Thread John W. Krahn
Gurunandan R. Bhat wrote: On Tue, 2009-06-30 at 22:47 -0700, John W. Krahn wrote: That should be: $current_path =~ s|/|\\|g; Oh!! Did not know you could use '|' as a pattern delimiter. Yes. You can use just about any character. John -- Those people who think they know everything ar

Re: Substitution question

2009-07-01 Thread Gurunandan R. Bhat
On Tue, 2009-06-30 at 22:47 -0700, John W. Krahn wrote: > That should be: > > $current_path =~ s|/|\\|g; Oh!! Did not know you could use '|' as a pattern delimiter. Regards

RE: Substitution question

2009-06-30 Thread sanket vaidya
Thanks John. It works Regards, Sanket Vaidya -Original Message- From: John W. Krahn [mailto:jwkr...@shaw.ca] Sent: Wednesday, July 01, 2009 11:17 AM To: Perl Beginners Subject: Re: Substitution question sanket vaidya wrote: > Hi all, Hello, > As a part of one program I need

Re: Substitution question

2009-06-30 Thread John W. Krahn
sanket vaidya wrote: Hi all, Hello, As a part of one program I need to get the current working directory. So I get this using cwd(). I want to replace forward slash (/) by backslash (\) in the path which I get because I work on windows. You shouldn't need to do that. Kindly look at the co

Re: Substitution question

2009-06-30 Thread Gurunandan R. Bhat
Are you sure that your substitution works? With the pattern you have quoted, you should be getting a "Search pattern not terminated" error. To answer your other question, patterns to search must be enclosed inside '/'s (forward slashes). You can change pattern delimiters then you must precede th

Re: substitution from line in context to matched line

2008-08-14 Thread tony
On Aug 14, 5:48 am, [EMAIL PROTECTED] (Rob Dixon) wrote: > - isn't an implicit array. Where did you read that? It's a read > operattion on the STDIN file handle. > Does this program help? > > Rob I was unclear, sorry about that. You're correct I meant there is an implicit 'loop' (not array!) wit

Re: substitution from line in context to matched line

2008-08-14 Thread John W. Krahn
tony wrote: Hello, Hello, gnu grep -C allows for output in context to the matched line is there an updated way to do this in perl using $. == $linenumber + context? I looked into the other thread that mentioned it, but none of the scripts worked. I tried the -00 switch and regex backreferenc

Re: substitution from line in context to matched line

2008-08-14 Thread Rob Dixon
tony wrote: > > gnu grep -C allows for output in context to the matched line is there an > updated way to do this in perl using $. == $linenumber + context? I looked > into the other thread that mentioned it, but none of the scripts worked. > > I tried the -00 switch and regex backreferences with

Re: substitution from line in context to matched line

2008-08-14 Thread Xavier Mas
El Wednesday 13 August 2008 22:45:46 tony va escriure: > Hello, > > gnu grep -C allows for output in context to the matched line > is there an updated way to do this in perl using $. == $linenumber + > context? > I looked into the other thread that mentioned it, but none of the > scripts worked. >

Re: Substitution within an html page

2008-08-05 Thread Dr.Ruud
"John W. Krahn" schreef: > while ( my $str = ) > { > chomp; chomp $str; > Although you don't need the chomp() because you are not modifying the > end of the line. Right. :) -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For addit

Re: Substitution within an html page

2008-08-05 Thread John W. Krahn
Amit Saxena wrote: Try this code fragment (have not run it though) :- #/usr/bin/perl use warnings; use strict; open (HTMLFILE, "/tmp/test1.html") or die 'Can't create HTML FILE /tmp/test1.html : $!\n\n"; my $str; while (chomp($str = )) { That is *NOT* the correct way to read a line in a wh

Re: Substitution within an html page

2008-08-04 Thread Amit Saxena
On Sat, Aug 2, 2008 at 3:12 AM, David Allender <[EMAIL PROTECTED]> wrote: > Hello all, > > I've been trying multiple different ways, but I am still unable to > have the output that i am looking for. > > What I'm trying to do is change certain text in an html file. How > would i go about doing tha

Re: substitution

2008-07-04 Thread Dr.Ruud
epanda schreef: Don't top post. Don't quote signatures and other trailers. > rvtol: >> epanda: >>> I want to replace my pattern by the corresponding value of the key >>> in the hash table [...] >>> with a single %s/pattern/hashpattern/g expression >> >> Why that last condition? Sounds like homew

Re: substitution

2008-07-03 Thread epanda
It is ok I have found the good one substitution for me but I am amazing that perl is not as clever as vimscript regex in limitation of assertions. ex : perl is lost when I want to say that a digit has to not be preceed by this sentence : /(? epanda schreef: > > > I want to replace my pattern by t

Re: substitution

2008-07-02 Thread Dr.Ruud
epanda schreef: > I want to replace my pattern by the corresponding value of the key > in the hash table [...] > with a single %s/pattern/hashpattern/g expression Why that last condition? Sounds like homework. And is unsound: often you want to do the longest possible change first. -- Affijn, R

Re: substitution

2008-07-01 Thread epanda
yes to distinguish in file3 the first d;, it is sufficient to avoid it by preceded WORD;\s+\d+; but I have tried that and it is not working (? epanda wrote: > > this is not working > > > here is an example of my file and I just want to replace with one > > regexp > > > in file1 ddd ddd ddd

Re: substitution

2008-07-01 Thread Rob Dixon
epanda wrote: > this is not working > > here is an example of my file and I just want to replace with one > regexp > > in file1 ddd ddd by the value stored in my hash table > in file2 all d > in file3 not the first d; but all the others which is preceed by > WORD; > > in all files > no

Re: substitution

2008-07-01 Thread Rob Dixon
Amit Saxena wrote: > > On Tue, Jul 1, 2008 at 4:19 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: >> >> Amit Saxena wrote: >> >>> Why don't use perl "s" operator with "e" option ? >>> >>> $str =~ s/([^ ]+)/$hash{\1}/ge >>> >> You don't need the /e option to interpolate a variable in a double quoted >

Re: substitution

2008-07-01 Thread Amit Saxena
Hi John, I am not only expanding a variable but also using that expanded variable as a key to ultimately find the value. That's why I need "e". Secondly, inside text that is to be substituted, I can use \1 as well. And moreover, for this, I don't need double quotes. If i purposefully incorporate

Re: substitution

2008-07-01 Thread John W. Krahn
Amit Saxena wrote: Why don't use perl "s" operator with "e" option ? $str =~ s/([^ ]+)/$hash{\1}/ge You don't need the /e option to interpolate a variable in a double quoted string and you should use $1 instead of \1 inside a double quoted string: $str =~ s/([^ ]+)/$hash{$1}/g John -- Pe

Re: substitution

2008-07-01 Thread Amit Saxena
Why don't use perl "s" operator with "e" option ? $str =~ s/([^ ]+)/$hash{\1}/ge Regards, Amit Saxena On Tue, Jul 1, 2008 at 3:57 AM, Brad Baxter <[EMAIL PROTECTED]> wrote: > On Jun 30, 4:20 pm, [EMAIL PROTECTED] (Epanda) wrote: > > Hi, > > > > I have to do a substitution of a pattern in a text

Re: substitution

2008-06-30 Thread Brad Baxter
On Jun 30, 4:20 pm, [EMAIL PROTECTED] (Epanda) wrote: > Hi, > > I have to do a substitution of a pattern in a text file, So you know about perl -i, right? > > this pattern is a key of a hash table previously set. > > so I want to replace my pattern by the corresponding value of the key > in the h

Re: substitution

2008-06-30 Thread Rob Dixon
epanda wrote: > > I have to do a substitution of a pattern in a text file, > > this pattern is a key of a hash table previously set. > > > so I want to replace my pattern by the corresponding value of the key > in the hash table > > > ex : > > file : n1 n22 > > hash : n1 => wordA >

Re: substitution key->value

2007-08-27 Thread Dr.Ruud
"Chas Owens" schreef: > Alternations are notoriously inefficient in Perl due to how the regex > engine works. Perl 5.10 fixes this, at least somewhat, by using > something called Tries (which are something like trees, but I don't > fully understand them yet), These tries are a method of optimisa

Re: substitution key->value

2007-08-27 Thread Chas Owens
On 8/27/07, Chas Owens <[EMAIL PROTECTED]> wrote: > On 8/27/07, Chas Owens <[EMAIL PROTECTED]> wrote: > snip > > Rate join hard joinqropt qr > > join 42708/s ---0%-1% -11% -56% > > hard 42708/s 0% ---1% -11% -56% > > joinqr 43115/s 1%

Re: substitution key->value

2007-08-27 Thread Xavier Noria
On Aug 27, 2007, at 1:29 PM, Chas Owens wrote: Bad idea*, at least until Perl 5.10 (and maybe not even then). Well, it may or may not be a bad idea. On the one hand that performance penalty may be negligible for the OP problem and thus it just does not matter. On the other hand your solut

Re: substitution key->value

2007-08-27 Thread Chas Owens
On 8/27/07, Chas Owens <[EMAIL PROTECTED]> wrote: snip > Rate join hard joinqropt qr > join 42708/s ---0%-1% -11% -56% > hard 42708/s 0% ---1% -11% -56% > joinqr 43115/s 1% 1% -- -11% -56% > opt48188/s13%13%12

Re: substitution key->value

2007-08-27 Thread Chas Owens
On 8/27/07, Mumia W. <[EMAIL PROTECTED]> wrote: > On 08/27/2007 03:59 AM, Petra Vide Ogrin wrote: > > Hi all, > > > > I have a hash and some prose text and want my perl to identify the keys of > > the hash in this text and replace them with the corresponding values of > > the keys. > > > > I tried

Re: substitution key->value

2007-08-27 Thread Mumia W.
On 08/27/2007 03:59 AM, Petra Vide Ogrin wrote: Hi all, I have a hash and some prose text and want my perl to identify the keys of the hash in this text and replace them with the corresponding values of the keys. I tried the following foreach (keys %expan) { if ($sbl =~ m/$_/g) { $sbl =~

Re: substitution key->value

2007-08-27 Thread Chas Owens
On 8/27/07, Petra Vide Ogrin <[EMAIL PROTECTED]> wrote: > Hi all, > > I have a hash and some prose text and want my perl to identify the keys of > the hash in this text and replace them with the corresponding values of > the keys. > > I tried the following > > foreach (keys %expan) { > if ($sbl =

Re: substitution key->value

2007-08-27 Thread Xavier Noria
On Aug 27, 2007, at 10:59 AM, Petra Vide Ogrin wrote: Hi all, I have a hash and some prose text and want my perl to identify the keys of the hash in this text and replace them with the corresponding values of the keys. I tried the following foreach (keys %expan) { if ($sbl =~ m/$_/g) {

Re: substitution key->value

2007-08-27 Thread Jeff Pang
I'm not sure what's your special situation. But see this simple test,it can work. $ perl -e '$hash{x}="33"; $s="xyzx"; for(keys %hash){ $s=~s/\Q$_/$hash{$_}/g } print $s ' 33yz33 2007/8/27, Petra Vide Ogrin <[EMAIL PROTECTED]>: > Sorry, tried all that with escaping - doesn't work eit

Re: substitution key->value

2007-08-27 Thread Petra Vide Ogrin
Sorry, tried all that with escaping - doesn't work either ??? > you may need the \Q for meta-character escape. > > for (keys %expan) { > $sbl =~ s/\Q$_/$expan{$_}/g; > } > > see also 'perldoc perlre' and search for '\Q'. > > 2007/8/27, Petra Vide Ogrin <[EMAIL PROTECTED]>: >> Hi all, >> >> I

Re: substitution key->value

2007-08-27 Thread Jeff Pang
you may need the \Q for meta-character escape. for (keys %expan) { $sbl =~ s/\Q$_/$expan{$_}/g; } see also 'perldoc perlre' and search for '\Q'. 2007/8/27, Petra Vide Ogrin <[EMAIL PROTECTED]>: > Hi all, > > I have a hash and some prose text and want my perl to identify the keys of > the has

Re: substitution

2006-02-13 Thread John W. Krahn
Michael Gargiullo wrote: > The carrot is a special char, The carrot is an orange vegetable. s/carrot/caret/g; :-) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: substitution

2006-02-13 Thread Hans Meier (John Doe)
Bowen, Bruce am Sonntag, 12. Februar 2006 22.31: > I have a text string = "^0176 ^0176" > > I have set $a = "^0176 ^0176"; > I have set $b = "^0176 "; > > I'm using text =~ s/$a/$b/g; > > And the text string doesn't change. I expected it to come out as "^0176 " > after the substitution. What

RE: substitution

2006-02-13 Thread Bowen, Bruce
That worked perfectly. Thanks, Bruce -Original Message- From: Michael Gargiullo [mailto:[EMAIL PROTECTED] Sent: Monday, February 13, 2006 10:47 AM To: Bowen, Bruce Cc: beginners@perl.org Subject: RE: substitution The carrot is a special char, so if you want that to be included as a

RE: substitution

2006-02-13 Thread Michael Gargiullo
: Monday, February 13, 2006 10:45 AM To: Michael Gargiullo Subject: RE: substitution It did but the suggestion did not work. They had me placing \ in front of the ^. I'll try this also. TX, Bruce -Original Message- From: Michael Gargiullo [mailto:[EMAIL PROTECTED] Sent: Monday, F

Re: substitution

2006-02-12 Thread Tom Phoenix
On 2/12/06, Bowen, Bruce <[EMAIL PROTECTED]> wrote: > I have a text string = "^0176 ^0176" > > I have set $a = "^0176 ^0176"; > I have set $b = "^0176 "; > > I'm using text =~ s/$a/$b/g; > > And the text string doesn't change. The caret is a metacharacter. You may want to use \Q or the quoteme

Re: Substitution problem

2005-09-06 Thread John W. Krahn
John W. Krahn wrote: > Moon, John wrote: >>Does any one know how to do this with just a substitution? >> >>perl -e '$a=q{Data.m1234.D1234567890}; >> $a =~/\d+$/; >> $numbers = q{#} x length($&); >> $a=~ s/\d+$/$numbers/; print "$a\n";' >> >>What " Data.m1234.D## " as a result

Re: Substitution problem

2005-09-06 Thread John W. Krahn
Moon, John wrote: > Does any one know how to do this with just a substitution? > > perl -e '$a=q{Data.m1234.D1234567890}; > $a =~/\d+$/; > $numbers = q{#} x length($&); > $a=~ s/\d+$/$numbers/; print "$a\n";' > > What " Data.m1234.D## " as a result. $ perl -le'$_ = q{Da

RE: Substitution problem

2005-09-06 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Moon, John wrote: > Does any one know how to do this with just a substitution? > > perl -e '$a=q{Data.m1234.D1234567890}; > $a =~/\d+$/; > $numbers = q{#} x length($&); > $a=~ s/\d+$/$numbers/; print "$a\n";' > > What " Data.m1234.D## " as a result. > > John W Moon Did

Re: substitution doesn't work on all files ?

2005-08-06 Thread Jeff 'japhy' Pinyan
On Aug 5, Brian Volk said: Now that I have my program working ( much thanks to the group ) I'm totally stumped as to why the substitution only works on some of the .txt files and not all. I'm attaching two files.. 70119.txt and 30700.txt. The s/ / /; in the program below works for file 701

Re: Substitution inside a loop

2004-11-24 Thread Gunnar Hjalmarsson
Gunnar Hjalmarsson wrote: Brian Volk wrote: while () { You want to remove the newline character: chomp; print "$main_url\n"; s/1804/KCITEM/ and print "$main_url\n"; You probably mean: $main_url =~ s/1804/$_/ and print "$main_url\n"; Hmm.. That suggestion wasn't very clever, I think. $ma

Re: Substitution inside a loop

2004-11-24 Thread Gunnar Hjalmarsson
Brian Volk wrote: I have a .txt file which contains item numbers like so.. 1234 1245 1278 1240 etc. I am trying to print the entire url, $main_url after substituting the item number in the .txt file... I'm having a little trouble w/ my loop... Below is the script. #!/usr/bin/perl -w use stric

Re: substitution and assignment fun ( was RE: Becoming Disenheartened )

2004-10-01 Thread Chris Devers
On Fri, 1 Oct 2004, Nicolay A. Vasiliev wrote: > No doubt please, I know about regular expressions and Python/Ruby > support them fully. I only showed the approach of method calling. > There could be not "replace" method. You're arguing about semantics, but you concede that the functionality y

Re: substitution and assignment fun ( was RE: Becoming Disenheartened )

2004-10-01 Thread Nicolay A. Vasiliev
No doubt please, I know about regular expressions and Python/Ruby support them fully. I only showed the approach of method calling. There could be not "replace" method. William M West wrote: Python and Ruby don't write the code for me. But look at this Python code: s = "I am Perl guru"; new_s =

Re: Substitution/Regex problem

2004-05-02 Thread Cedric Godin
On Thursday 29 April 2004 10:31, Owen wrote: > I would like to replace all instances of > > @non_space_characters[non_space_characters] with > $non_space_characters[non_space_characters] > > The program below gets the first one only. How do I get the others? > > TIA > > Owen > ---

Re: Substitution/Regex problem

2004-04-29 Thread John W. Krahn
Owen wrote: > > I would like to replace all instances of > > @non_space_characters[non_space_characters] with > $non_space_characters[non_space_characters] > > The program below gets the first one only. How do I get the others? > > --- > #!/usr/

Re: Substitution/Regex problem

2004-04-29 Thread Damon Allen Davison
Hi Owen, I think I would do things a little differently. Owen wrote: I would like to replace all instances of @non_space_characters[non_space_characters] with $non_space_characters[non_space_characters] [...] $line=~s/(@)(\S+\[\S+\])/\$$2/g; __DATA__ @[EMAIL PROTECTED]@banana[4]; So this is my

Re: Substitution/Regex problem

2004-04-29 Thread Jose Alves de Castro
The problem is that your regex is matching the whole line: @ [EMAIL PROTECTED]@banana[4]; ^ ^ $1 $2 Instead, use non greedy matches: $line =~ s/(@)(\S+?\[\S+?\])/\$$2/g; and you'll get what you want: @ array[1] = @ array[2] +@ banana[4]; ^ ^

Re: substitution

2004-02-24 Thread R. Joseph Newton
"Charles K. Clarkson" wrote: > : >> my %replacements = (ARE => 756, TYP => 978, SPE => 840); > : >> $marque =~ s/(ARE|TYR|SPE)/$replacements{$1}/; > : > > : > my %replacements = (ARE => 756, TYP => 978, SPE => 840); > : > $marque =~ s/(ARE|TYR|SPE)/$replacements{$1}/eg; > ... Though I think I woul

RE: substitution

2004-02-23 Thread Charles K. Clarkson
James Edward Gray II <[EMAIL PROTECTED]> wrote: : : On Feb 23, 2004, at 5:14 PM, David le Blanc wrote: : : >> -Original Message- : >> From: Hanson, Rob [mailto:[EMAIL PROTECTED] : >> Sent: Tuesday, 24 February 2004 5:43 AM : >> To: 'Olivier Wirz&#

Re: substitution

2004-02-23 Thread James Edward Gray II
On Feb 23, 2004, at 5:14 PM, David le Blanc wrote: -Original Message- From: Hanson, Rob [mailto:[EMAIL PROTECTED] Sent: Tuesday, 24 February 2004 5:43 AM To: 'Olivier Wirz'; [EMAIL PROTECTED] Subject: RE: substitution Is it possible to do this No, at least not the way you ar

RE: substitution

2004-02-23 Thread David le Blanc
> -Original Message- > From: Hanson, Rob [mailto:[EMAIL PROTECTED] > Sent: Tuesday, 24 February 2004 5:43 AM > To: 'Olivier Wirz'; [EMAIL PROTECTED] > Subject: RE: substitution > > > Is it possible to do this > > No, at least not the way you are

RE: substitution

2004-02-23 Thread Hanson, Rob
> Is it possible to do this No, at least not the way you are doing it. Something like this will work (untested) my %replacements = (ARE => 756, TYP => 978, SPE => 840); $marque =~ s/(ARE|TYR|SPE)/$replacements{$1}/; Rob -Original Message- From: Olivier Wirz [mailto:[EMAIL PROTECTED] Se

Re: substitution problem

2003-11-06 Thread John W. Krahn
Steve Massey wrote: > > Hi Hello, > I though I had sussed this s/ stuff but > > #! /usr/bin/perl -w > > $test = "BRIGHTON (Firm)"; > > print "$test\n"; > $test =~ s/,*/,/; > $test =~ s/,*$/,/g; > > print "$test\n"; > > does not work, I want to su

Re: substitution problem

2003-10-23 Thread R. Joseph Newton
Steve Massey wrote: > Hi > > I though I had sussed this s/ stuff but > > #! /usr/bin/perl -w > > $test = "BRIGHTON (Firm)"; > > print "$test\n"; > $test =~ s/,*/,/; > $test =~ s/,*$/,/g; > > print "$test\n"; > > does not work, I want to substitute all m

RE: substitution problem

2003-10-23 Thread Mark Anderson
> From: Steve Massey [mailto:[EMAIL PROTECTED] > Sent: 23 October 2003 11:33 > > #! /usr/bin/perl -w > > $test = "BRIGHTON (Firm)"; > > > print "$test\n"; > $test =~ s/,*/,/; > $test =~ s/,*$/,/g; > > print "$test\n"; It looks like the +/* issue has bee

RE: substitution problem

2003-10-23 Thread Wiggins d Anconia
> Ok scrub that > > + works but * doesn't > > i'm guess the * is matching anything > > took me 2 hours to figure that ;) > To de-mystify the regexes some have a look at: perldoc perlretut perldoc perlre http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional comma

Re: substitution problem

2003-10-23 Thread Gary Stainburn
On Thursday 23 Oct 2003 11:52 am, Steve Massey wrote: > Ok scrub that > > + works but * doesn't > > i'm guess the * is matching anything > > took me 2 hours to figure that ;) > Hi Steve, + matches 1 or more, * matches 0 or more. for better efficiency, you really want to do s/,,+/,/; which

RE: substitution problem

2003-10-23 Thread Steve Massey
Ok scrub that + works but * doesn't i'm guess the * is matching anything took me 2 hours to figure that ;) -Original Message- From: Steve Massey [mailto:[EMAIL PROTECTED] Sent: 23 October 2003 11:33 To: [EMAIL PROTECTED] Subject: substitution problem Hi I though I had sussed

RE: substitution or matching regex

2002-12-31 Thread Paul Kraus
#!/usr/bin/perl $num=14.45905495; @post=$1 if ($num=~/(\d+\.\d\d)\d+/); print "$post[0]\n"; output 14.45 explanation -- \d+ = at least one digit or more \. = followed by a period. \d\d = two digits \d+ = followed by any number of digits (\d+\.\d\d) Sets the portion in parens to be memo

RE: substitution or matching regex

2002-12-31 Thread Kipp, James
> I have a variable: > $NUM = '14.45905495'; > and I want to remove the trailing digits and only leave 2 > after the period > so it ends up > > '14.45' > > I've tried to do this but it appears to return as an array > and always prints > out "1". > > #!perl -w > > $NUM = '14.45905495'; > @POS

RE: substitution or matching regex

2002-12-31 Thread wiggins
You may want to do this with sprintf rather than a regex, check out: perldoc -f sprintf I believe because your regex isn't grouping any terms it is returning a status of true or false, aka 1 for true since your regex does in fact match. You might try paren's around the whole thing if you still

RE: substitution

2002-11-20 Thread Timothy Johnson
--Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 20, 2002 6:01 PM To: 'Chris Zampese'; [EMAIL PROTECTED] Subject: RE: substitution There are two things happening here. 1) You need to include the e switch at the end of your s/// expres

RE: substitution

2002-11-20 Thread Timothy Johnson
There are two things happening here. 1) You need to include the e switch at the end of your s/// expression. Otherwise the second part of the substitution is taken literally. 2) When you use a variable as the first part of a regular expression, it is interpolated first, and then the resul

Re: substitution

2002-11-20 Thread Wiggins d'Anconia
Two things... Chris Zampese wrote: Hi everyon, thanks for your help so far I am trying to substitute a path for another path. I have html documents which refer to some images in the following directory: C:\Documents and Settings\chrisz\Desktop\Web_notes\PFLogo.gif I would like to change th

Re: substitution

2002-04-09 Thread Jeff 'japhy' Pinyan
On Apr 9, Raghupathy, Ramesh . said: > I am trying to translate the abbreviation of the form A(4) to . I >tried substitution as follows: >$wholefile =~ s/(\w)\((\d+)\)/$1{$2}/g; It seems like you think that x{y} syntax used in a regex can be used elsewhere -- nope. Instead, you need to u

RE: Substitution: How do I say ...

2002-03-29 Thread Daryl J. Hoyt
That's what I get for not reading to carefully ;-). The proper command is "s/\t(?!454354)//g;". Sorry about that. -Original Message- From: KEVIN ZEMBOWER [mailto:[EMAIL PROTECTED]] Sent: Friday, March 29, 2002 11:38 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: R

RE: Substitution: How do I say ...

2002-03-29 Thread David Gray
> er... > s/\t(?!454354)//g; > > > > s/\t454354//g; > > > > replace every \t (tab character) which is NOT > > immediately proceeded > > by '454354' with ''? > > > > Thanks. I suspect this is any easy one, but I've been staring > > at it for > > an hour, and I can't figure it out. Brain

RE: Substitution: How do I say ...

2002-03-29 Thread KEVIN ZEMBOWER
Hi, Daryl, thanks for writing. Wouldn't this substitute for tabs which DO have a 454354 after them? I was asking how to sub for tabs which do NOT. -Kevin >>> "Daryl J. Hoyt" <[EMAIL PROTECTED]> 03/29/02 12:32PM >>> s/\t454354//g; Daryl J. Hoyt Performance Engineer Geodesic Systems 31

RE: Substitution: How do I say ...

2002-03-29 Thread Nikola Janceski
er... s/\t(?!454354)//g; > -Original Message- > From: Daryl J. Hoyt [mailto:[EMAIL PROTECTED]] > Sent: Friday, March 29, 2002 12:33 PM > To: KEVIN ZEMBOWER; [EMAIL PROTECTED] > Subject: RE: Substitution: How do I say ... > > > s/\t454354//g; > >

  1   2   >