Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > interpolation

Reply
Thread Tools

interpolation

 
 
new2perl@gmail.com
Guest
Posts: n/a
 
      07-20-2007
Assigning a variable.
Then reading in text file that uses the variable.
It's isn't resolved.

Input file:
Your name is: $name

Script:
#!/bin/perl

$name="Rupert";
$text="textin";

open (MYFILE, $text) or die "cant open erik";

while (<MYFILE>) { $value = $_ }

print "$value";


Output:
Your name is: $name


Output that I want:
Your name is Rupert.


What am I doing wrong here ?

Bob

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      07-20-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
> Assigning a variable.
> Then reading in text file that uses the variable.
> It's isn't resolved.



Of course not. Data is not the same thing as Code.


> Input file:
> Your name is: $name
>
> Script:
> #!/bin/perl


use strict;
use warnings;


> $name="Rupert";


my $name="Rupert";


> $text="textin";
>
> open (MYFILE, $text) or die "cant open erik";



You did not try to open "erik", you tried to open "textin".


> while (<MYFILE>) { $value = $_ }



That reads all the lines, and discards all of them except the last line.


> print "$value";



print $value;

perldoc -q vars

What’s wrong with always quoting "$vars"?


> Output:
> Your name is: $name
>
>
> Output that I want:
> Your name is Rupert.
>
>
> What am I doing wrong here ?



Conflating what is "data" with what is "code".


Your Question is Asked Frequently:

perldoc -q expand

How can I expand variables in text strings?


However, I'm quite sure that you are asking the wrong question.

You should instead be asking about Templating systems.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
 
 
 
new2perl@gmail.com
Guest
Posts: n/a
 
      07-20-2007
On Jul 19, 7:32 pm, Tad McClellan <(E-Mail Removed)> wrote:
> (E-Mail Removed) <(E-Mail Removed)> wrote:
> > Assigning a variable.
> > Then reading in text file that uses the variable.
> > It's isn't resolved.

>
> Of course not. Data is not the same thing as Code.
>
> > Input file:
> > Your name is: $name

>
> > Script:
> > #!/bin/perl

>
> use strict;
> use warnings;
>
> > $name="Rupert";

>
> my $name="Rupert";
>
> > $text="textin";

>
> > open (MYFILE, $text) or die "cant open erik";

>
> You did not try to open "erik", you tried to open "textin".
>
> > while (<MYFILE>) { $value = $_ }

>
> That reads all the lines, and discards all of them except the last line.
>
> > print "$value";

>
> print $value;
>
> perldoc -q vars
>
> What's wrong with always quoting "$vars"?
>
> > Output:
> > Your name is: $name

>
> > Output that I want:
> > Your name is Rupert.

>
> > What am I doing wrong here ?

>
> Conflating what is "data" with what is "code".
>
> Your Question is Asked Frequently:
>
> perldoc -q expand
>
> How can I expand variables in text strings?
>
> However, I'm quite sure that you are asking the wrong question.
>
> You should instead be asking about Templating systems.
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


this should do it:
$value =~ s/\$(\w+)/${$1}/g;

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      07-21-2007
Tad McClellan schreef:


> Content-Type: text/plain; charset=iso-8859-1
> [...]
> Whatâ?Ts wrong


Try LANG="" perldoc ...

--
Affijn, Ruud

"Gewoon is een tijger."

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linear interpolation in vhdl df84077@gmail.com VHDL 8 10-07-2011 08:38 AM
How to stop interpolation of Escape character in variable? \Rob\ ASP .Net 8 02-24-2006 08:52 AM
Opening files with interpolation Mat W Perl 3 05-21-2004 08:40 AM
problem using JAI bilinear interpolation to scale a bufferedimage Raj Java 2 11-25-2003 11:52 AM
Your votes please ( drawImage bad interpolation bug id 4950176) Michele Puccini Java 0 11-09-2003 11:06 AM



Advertisments