RE: simple substitution question

2005-02-18 Thread Manav Mathur
=~ is the bind operator. see perldoc perlop. Manav -Original Message- From: Harold Castro [mailto:[EMAIL PROTECTED] Sent: Friday, February 18, 2005 12:17 PM To: beginners@perl.org Subject: simple substitution question Hi, There is something that's bothering me for so

Re: simple substitution question

2005-02-18 Thread Ing. Branislav Gerzo
Harold Castro [HC], on Thursday, February 17, 2005 at 22:47 (-0800 (PST)) typed: HC> for example: HC> here is my string: HC> $_ = "but"; HC> s/u/a/g; HC> print $_; what about this: ( my $string = "but" ) =~ s/u/a/g; -- ...m8s, cu l8r, Brano. [Old Farts don't have to be politically correct.]

RE: simple substitution question

2005-02-17 Thread Bedanta Bordoloi, Gurgaon
old Castro [mailto:[EMAIL PROTECTED] Sent: Friday, February 18, 2005 12:17 PM To: beginners@perl.org Subject: simple substitution question Hi, There is something that's bothering me for so long regarding the use of $_ variable. for example: here is my string: $_ = "but"; s/

simple substitution question

2005-02-17 Thread Harold Castro
Hi, There is something that's bothering me for so long regarding the use of $_ variable. for example: here is my string: $_ = "but"; s/u/a/g; print $_; This will simply print "bat" My problem is using a variable in place of $_. how will I tell that the one i'm going to substitute is the $strin

Re: Should be a simple substitution?

2004-12-08 Thread Dave Gray
> It's on the right hand-side of the regex, however. Look at the output: > > C:\src\perl>perl -pe"s<{([^}]+)}><(?:@{[ ($a = $1) =~ y/,/|/ && $a ]})>" > blargh{a,b,c}blargh > blargh(?:a|b|c)blargh > > The OP didn't want the ?: in there So it is! I'm usually a fan of one-liners, but I think t

RE: Should be a simple substitution?

2004-12-08 Thread Bakken, Luke
> > I think the ?: must be extraneous: > > That construct lets the regex engine know that it doesn't need to > worry about saving backreferences to the parenthesized group. It's on the right hand-side of the regex, however. Look at the output: C:\src\perl>perl -pe"s<{([^}]+)}><(?:@{[ ($a = $1) =

Re: Should be a simple substitution?

2004-12-08 Thread Dave Gray
> I think the ?: must be extraneous: That construct lets the regex engine know that it doesn't need to worry about saving backreferences to the parenthesized group. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: Should be a simple substitution?

2004-12-08 Thread Bakken, Luke
> > $var =~ s<{([^}]+)}><(?:@{[ ($a = $1) =~ y/,/|/ && $a ]})>; > > > Does it not need the 'ge' at the end? > > I don't understand why you are creating an anonymous array > with a single > value, then dereferencing it... And what does the "?:" do? I think the ?: must be extraneous: C:\src

RE: Should be a simple substitution?

2004-12-08 Thread Bakken, Luke
> And is this method any faster or more efficient than this? > > $var =~ s/\{([^}]+)\}/$v = $1; $v =~ s!,!|!g; qq!($v)!/ge; Why not find out yourself? C:\src\perl>type rebench.plx use strict; use Benchmark qw/cmpthese/; sub luke { my $var = 'blargh{a,b,c}'; my $v; $var =

Re: Should be a simple substitution?

2004-12-07 Thread Bryan R Harris
>>> I can usually figure out regexes, and this one seems simple, but it still >>> eludes me-- >>> >>> I'm looking for a regex (or a couple of regexes) to do the following: >>> >>> blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah >>> blahblah{a,b,c}blah --> blahblah(a|b|c)blah >>> >>> I

Re: Should be a simple substitution?

2004-12-07 Thread John W. Krahn
John W. Krahn wrote: Bryan R Harris wrote: I can usually figure out regexes, and this one seems simple, but it still eludes me-- I'm looking for a regex (or a couple of regexes) to do the following: blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah blahblah{a,b,c}blah --> blahblah(a|b|c)blah

Re: Should be a simple substitution?

2004-12-07 Thread John W. Krahn
Bryan R Harris wrote: I can usually figure out regexes, and this one seems simple, but it still eludes me-- I'm looking for a regex (or a couple of regexes) to do the following: blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah blahblah{a,b,c}blah --> blahblah(a|b|c)blah If it's not obvious I

Re: Should be a simple substitution?

2004-12-06 Thread Bryan R Harris
>> I can usually figure out regexes, and this one seems simple, but it still >> eludes me-- >> >> I'm looking for a regex (or a couple of regexes) to do the following: >> >> blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah >> blahblah{a,b,c}blah --> blahblah(a|b|c)blah >> >> If it's no

Re: Should be a simple substitution?

2004-12-06 Thread John W. Krahn
Bryan R Harris wrote: I can usually figure out regexes, and this one seems simple, but it still eludes me-- I'm looking for a regex (or a couple of regexes) to do the following: blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah blahblah{a,b,c}blah --> blahblah(a|b|c)blah If it's not obvious

Re: Should be a simple substitution?

2004-12-06 Thread Chris Devers
On Mon, 6 Dec 2004, Chris Devers wrote: > On Mon, 6 Dec 2004, Bryan R Harris wrote: > > > > Can you do this: > > > > > > $var =~ s/\{([^}]*)\}/$v = $1; $v =~ s!,!|!g; qq!($v)!/ge; > > > > Holy cow, is that legal??!! It took me at least 30 seconds just to > > figure out that those commands wer

Re: Should be a simple substitution?

2004-12-06 Thread Chris Devers
On Mon, 6 Dec 2004, Bryan R Harris wrote: > > Can you do this: > > > > $var =~ s/\{([^}]*)\}/$v = $1; $v =~ s!,!|!g; qq!($v)!/ge; > > Holy cow, is that legal??!! It took me at least 30 seconds just to > figure out that those commands were inside the s/// command. See the 'e' at the end of the

Re: Should be a simple substitution?

2004-12-06 Thread Bryan R Harris
I can usually figure out regexes, and this one seems simple, but it still eludes me-- I'm looking for a regex (or a couple of regexes) to do the >> following: blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah blahblah{a,b,c}blah --> blahblah(a|b|c)blah >

RE: Should be a simple substitution?

2004-12-06 Thread Bakken, Luke
> >> I can usually figure out regexes, and this one seems simple, but it > >> still eludes me-- > >> > >> I'm looking for a regex (or a couple of regexes) to do the > following: > >> > >> blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah > >> blahblah{a,b,c}blah --> blahblah(a|b|c)blah >

Re: Should be a simple substitution?

2004-12-06 Thread Dave Gray
> I'm looking for a regex (or a couple of regexes) to do the following: > > blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah > blahblah{a,b,c}blah --> blahblah(a|b|c)blah Anybody have a faster way to do this? __CODE__ #!/usr/bin/perl use strict; use warnings; sub uncommify { my ($glob

Re: Should be a simple substitution?

2004-12-06 Thread Bryan R Harris
>> I can usually figure out regexes, and this one seems simple, but it >> still eludes me-- >> >> I'm looking for a regex (or a couple of regexes) to do the following: >> >> blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah >> blahblah{a,b,c}blah --> blahblah(a|b|c)blah > > Well, you ca

RE: Should be a simple substitution?

2004-12-06 Thread Bob Showalter
Bryan R Harris wrote: > I can usually figure out regexes, and this one seems simple, but it > still eludes me-- > > I'm looking for a regex (or a couple of regexes) to do the following: > > blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah > blahblah{a,b,c}blah --> blahblah(a|b|c)blah Wel

Should be a simple substitution?

2004-12-06 Thread Bryan R Harris
I can usually figure out regexes, and this one seems simple, but it still eludes me-- I'm looking for a regex (or a couple of regexes) to do the following: blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah blahblah{a,b,c}blah --> blahblah(a|b|c)blah If it's not obvious I'm trying to glo

Re: Simple Substitution

2002-06-12 Thread Michael Norris
Ok, I'm trying to understand this. >open(CONFIG, "< /home/mnorris/$first_file") || die "Sorry, I couldn't READ >/home/mnorris/$first_file\n"; > while () { > s//$first_var/; > push @newdata, $_; > } >close(CONFIG); this pushes the replaced values into @newdata? How is this keeping

Re: Simple Substitution

2002-06-12 Thread David vd Geer Inhuur tbv IPlib
Nope, open(CONFIG, "< /home/mnorris/$first_file") || die "Sorry, I couldn't READ /home/mnorris/$first_file\n"; while () { s//$first_var/; push @newdata, $_; } close(CONFIG); open(NEWCFG, "> /home/mnorris/$first_file") || die "Sorry, I couldn't WRITE to /home/mnorris/$first_f

RE: Simple Substitution

2002-06-12 Thread Bob Showalter
> -Original Message- > From: Michael Norris [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, June 12, 2002 10:24 AM > To: [EMAIL PROTECTED] > Subject: Simple Substitution > > > This should work, shouldn't it? > > open(CONFIG,">>/home/mnor

Simple Substitution

2002-06-12 Thread Michael Norris
This should work, shouldn't it? open(CONFIG,">>/home/mnorris/$first_file") || die "Sorry, I couldn't create /home/mnorris/$first_file\n"; while () { $_ =~ s//$first_var/; } close(CONFIG); It should be opening the file named "$first_file" (created earlier in t