What's the best way to take some plain text (not PHP code) which contains PHP-style variables, and then substitute in the value of the variable. This is kinda hard to describe, so here's an example.
// -- myFile.txt --
Mary had a little $pet.
// -- parser.php --
$pet = "lamb";
// open myFile.txt and transform it such that...
$newConten...
I am trying to put the stuff within parentheses into the value of a src attribute in an img tag:
while(<TOCFILE>)
{
$toc_line = $_;
$toc_line =~ s/<inlineFig.*?(\.\.\/pics\/ch09_inline99_*?\.jpg)*?<\/inlineFig>/<img src="${1}" alt="" \/\>/g;
$new_toc_file .= $toc_line;
}
So I expected to see tags like this in the output:
...
I have been programming in Perl, off and on, for years now, although only sporadically is it my primary language. Because I often go months without writing any perl, I rely heavily on my dog-eared Camel Book to remind me how to do things. However, when I copy recipes verbatim with no understanding, this bothers me. This is one of the mos...
I'm using System.Data.Linq.DataContext file for accessing a mdf Database
I want to use the Database from the project directory and not the one created by the debugger in the Debug directory.
The problem is when I edit the Connection String and choose the path for AttachDBFilename,
VS2008 automaticly substitutes my project directory wit...
For my program, I'm attempting to replace the value of a specific hash in an external file with a newly created value. The external file has the value tab-delimited from the key, and I had read the hash in from the external file. I've been looking around online, and this is the closest way I could figure out how to do it, yet it doesn't ...
In Unix the ^ allows you to repeat a command with some text substituted for new text. For example:
csh% grep "stuff" file1 >> Results
grep "stuff" file1
csh% ^file1^file2^
grep "stuff" file2
csh%
Is there a Vim equivalent? There are a lot of times I find myself editing minor things on the command line over and over again.
...
I would like to do the following:
$find="start (.*) end";
$replace="foo \1 bar";
$var = "start middle end";
$var =~ s/$find/$replace/;
I would expect $var to contain "foo middle bar", but it does not work. Neither does:
$replace='foo \1 bar';
Somehow I am missing something regarding the escaping.
I fixed the missing 's'
...
I.e.:
echo H#97llo | MagicPerlCommand
Stdout:
Hallo
were MagicPerlCommand is something like
perl -pnle "s/#(\d+)/chr(\1)/ge"
(but that doesn't work).
...
Using vi, how do I substitute the current line number somewhere into the current line? For example, if the cursor is on line 10, I would like to put the number 10 somewhere on that line.
...
I am trying to use XSLT variables and not having much success, hopefully I'm just doing something dumb.
I have the following code snippet:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt"
version="1.0">
<xsl:template match="/">
<xsl:variable name="config" select=...
I'm using VIM, and I want to substitute some placeholder text with a long string, that spans several lines, which is already written somewhere else in the file.
Is it possible to replace a pattern with the contents of a register? Something like
:%s/foo/<contents of register A>
Otherwise, is it possible to replace with a range of line...
I have a query roughly like this:
select *
from A_TABLE
where A_COLUMN = '&aVariable'
union
select *
from A_TABLE
where B_COLUMN = '&aVariable';
But when I run it, SQL Developer prompts me for the variable twice, even though it's the same variable.
If there's a way to make it prompt only once for a variable that is ...
So my Perl script basically takes a string and then tries to clean it up by doing multiple search and replaces on it, like so:
$text =~ s/<[^>]+>/ /g;
$text =~ s/\s+/ /g;
$text =~ s/[\(\{\[]\d+[\(\{\[]/ /g;
$text =~ s/\s+[<>]+\s+/\. /g;
$text =~ s/\s+/ /g;
$text =~ s/\.*\s*[\*|\#]+\s*([A-Z\"])/\. $1/g; # replace . **** Begin or . #### B...
Given the plain text file with lines
bli foo bla
abc
dfg
bli foo bla
hik
lmn
what sed or awk magic transforms it to
bli foo_01 bla
abc
dfg
bli foo_02 bla
hik
lmn
so that every occurence of 'foo' is replaced by 'foo_[occurence number]'.
...
Hi! I simply wanna read in a logfile, do a search and replace, and then write out the changes to that same logfile.
What's the best practice way of doing this in Perl?
...
I need to substitute a list of words with with an equally long list of words.
So for example you have:
"a","b","c","d","e","f"
And you want to replace each word with the uppercase version of each word:
"A","B","C","D","E","F"
I know how to find each string using the regex:
(a\|b\|c\|d\|e\|f)
I know you could do a global substitution ...
Hi
I am reading each line of an input file (IN) and printing the line read to an output file (OUT) if the line begins with one of the patterns, say "ab", "cd","ef","gh","ij" etc. The line printed is of form "pattern: 100" or form "pattern: 100:200". I need to replace "pattern" with "myPattern", i.e. print the current line to FILE but re...
Hello friends,
I have a file that contains:
foo1 = 1
foo2 = 2
foo3 = 8
.
.
.
I need to replace only the values (1,2,8...) in that file with part of a memory hash values, the ones with the same keys (foo1 -> 33,foo2 -> 44,foo3...) How can I change it using the "s///" operator? If there is other elegant ways to conduct it I'll b...
This is not as simple as it seems. Most of you are likely thinking of the regex /([A-Z])/_$1/ like I have found all over the Internet, but my particular situation is slightly more complicated. My source string contains more content that I don't want to have converted before a portion that I do.
Consider a regular setter:
public funct...
I have several thousand xml files generated from java properties files prepared for translation in the TTX format. They contain quite a few variables, that I need to protect from the translators, as they often break such things. The variables are in the form of numbers or occasionally text between a pair of curly braces eg. {0}, {this}.
...