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