John W. Krahn wrote:
> Sharan Basappa wrote:
>>Question is how to embed text in a perl program instead of reading it
>>from a file or initializing the text in a string variable.
>>
>>I have done the following but when I execute the script, I get no output.
>>
>>Is there an issue I am overlooking ?
>>
>>Another question is whether perl will replace the variable defined in
>>the embedded text with actual values ?
>>
>>
>>#!/usr/bin/perl
>>my $one = "onex";
>>my $two = "twox";
>>while (<MY_BLOCK>)
>>{
>> print $_;
>>}
>>exit;
>>
>>__MY_BLOCK__
>>once
>>upon
>>there was a person who was
>>very fond of $one and $two
> 
> That will work if you change <MY_BLOCK> to <DATA> and change __MY_BLOCK__ to
> either __DATA__ or __END__ or alternatively use the Inline::Files module.

I didn't notice your $one and $two variables in the data.  You can do what you
want like this:


#!/usr/bin/perl
use warnings;
use strict;

my $one = 'onex';
my $two = 'twox';

open my $fh, '<', \<<MY_BLOCK or die "Cannot open variable: $!";
once
upon
there was a person who was
very fond of $one and $two
MY_BLOCK

while ( <$fh> ) {
    print;
}

__END__




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to