Denver wrote:
> Bart Van der Donck wrote:
> > my $bar = "a";
> > my $foo = "bc$bar";
> >
> > "bc$bar" is the assignment of declaration 'my $foo', right ?
>
> No. It is a string expression.
Assignment (also 'initialization' or 're-initialization') sets or
re-sets the value of a variable, I think we can agree on that
definition ?
So, I'ld say my terminology still stands.
I wouldn't use a statement "Assignments don't do interpolation" like
Jürgen. Though it's scientifically correct (the assignment doesn't
*do* it, it are the double quotes that do it), it sounds like it's
impossible to use interpolation inside assignments. Therefore I'ld
rather state "Interpolations occur inside assignments if double quotes
are used to perform the assignment".
> > As I understand it, there is an interpolation of the $bar-variable
> > inside the assignment of $foo,
>
> That's incorrect.
I don't see what's wrong with my statement. I just happen to use double
quotes for my assignment here, so the interpolation took place inside
my assignment.
> >> To me it looks like a misguided attempt to solve a perceived
> >> problem.
> >
> > The problem is that I want a variable to have the exact value as I
> > typed it in the code, regardless of which characters I use (assumed,
> > within the limitations of the OS and of Perl).
>
> Do you mean simply no interpolation?
Yes, no interpolation, and also no escape (as I originally wrote).
> > One could think of a number of application fields, for example, a
> > variable that holds the contents of a .gif file.
>
> That's outside the limitations of Perl.
No. Perl variables may hold the contents of a gif-file correctly:
#!/usr/bin/perl
print "Content-Type: image/gif\n\n";
$file = 'plan.gif';
open my $F, '<', $file || die "Cant open $file: $!";
$chars_of_gif.=$_ while(<$F>);
close $F || die "Cant close $file: $!";
print $chars_of_gif; # $chars_of_gif holds gif file here
Running it as CGI shows that the content is correct. So I'ld conclude
it's not a Perl issue, but a OS and/or editor issue.
> You can't put in an arbitrary binary literal in line in your code.
> (I don't really know why you want to.)
Yes, that seems impossible indeed. Maybe with the perfect editor under
the perfect OS ?
> But as Jue showed you, you can have string literals without interpolation.
> Did you try his examples?
print '$foo\\n';
does not print the literal text, but prints:
$foo\n
--
Bart