User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 375,274 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,218 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser:
Aug 28th, 2006
Views: 1,557
I've seen this question (or similar) asked many times on forums:

I have a variable in a file (text) and want to expand it. For example, I have this line in a text file:

Mary had a little $lamb

and I want to be able to expand $lamb but text files are treated as single-quoted strings and perl does not interpolate variables in single-quoted strings.
Last edited : May 16th, 2007.
perl Syntax | 5 stars
  1. my $lamb = 'wolf';
  2. my $text = 'Mary had a little $lamb.';
  3. $text =~ s/(\$\w+)/$1/eeg;
  4. print $text;
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 6:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC