On 5/16/19 10:48 PM, Andrew Solomon wrote:
In terms of a definition, do the first four paragraphs here answer your
question?
https://www.oreilly.com/library/view/perl-cookbook-2nd/0596003137/ch01.html
They do not.
I think in bytes, characters or strings, depending on what I want to do
--- and never in lines unless they get in the way and force me to
consider them.
A string is not a single value. And when you keep reading until you get
to the "Discussion" section, you would have to conclude that there are
no characters in perl, and I'm getting back to basically the question
from which this one arose: How can I use --- and even force when I want
to --- a "binary string"?
When you say you're trying to use "binary strings", what do you mean by
that?
That means "binary data", like you would allocate some memory in C to
read a file into (like a jpeg image in my application) or perhaps use a
vector of a suitable data type in C++ for such data, or maybe an array.
Despite being a useful simplification, strings are very complicated
things. You might imagine a "binary string" as a number of consecutive
bytes, with "consecutive" meaning that one byte comes after the other,
and the order in which they come is relevant. You could describe a
string like that, but since all kinds of encodings nowadays come into
play, I end up not knowing what I have when being forced to use a
"string" in perl because I don't know what else I could use instead,
particularly something that is not encumbered by encodings.
It seems I can't even ask perl what encoding it assumes a "string" has,
which is really weird because I may really need to know that.
https://perldoc.perl.org/perlnumber.html
Ok, how do I store a number of bytes consecutively within a variable in
perl? And how do I make it so that I even get the bytes I want to store
to begin with? For example:
my $binary_string = `curl -s -k --max-filesize $MAX_DOWNLOAD_SIZE "$url"`;
$url refers to a jpeg image. I need to store that image in a blob in a
database (using DBI).
Curl prints binary data to STDOUT and not a string. I can't have the
data encoded or otherwise altered because it would make the image
unretrievable. The only way to get it in per is a what perl considers
as a string.
How do I prevent the binary data from being altered without even knowing
what a string is in perl?
For example, noting that
print 4;
and
print 0b100;
both output 4, would you refer to 0b100 as a binary string?
no
Something is not binary just because it's a number. "Binary" tries to
say "the data as is, unaltered". An image is not a string, and the data
representing one isn't, either. But perl doesn't seem to have anything
to deal with that and has strings instead. So I guess I need a "binary
string", or an "unalterable string". Or something else ... But what is
a string?
Since strings in perl seem to inevitably involve encoding, strings can't
be the right data type for my purpose because encoding could make the
data useless. There is no encoding 'jpeg' or 'tiff' or 'png'. Those
are interpretations, and the data must remain encodingless for it to be
interpreted.
On Thu, May 16, 2019 at 5:51 PM hwilmer <h...@gc-24.de
<mailto:h...@gc-24.de>> wrote:
Hi,
since I'm trying to use "binary strings", the question comes up if
there
is a definition of what is a string in perl, and what is it?
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
<mailto:beginners-unsubscr...@perl.org>
For additional commands, e-mail: beginners-h...@perl.org
<mailto:beginners-h...@perl.org>
http://learn.perl.org/
--
Andrew Solomon
Director
P: +44 7931 946 062
E: and...@geekuni.com <mailto:and...@geekuni.com>
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/