develooper Front page | perl.beginners | Postings from May 2019

Re: can I use some kind of binary string?

Thread Previous | Thread Next
Shlomi Fish
May 16, 2019 20:17
Re: can I use some kind of binary string?
Message ID:
On Thu, 16 May 2019 13:13:16 +0200
hwilmer <> wrote:

> On 5/11/19 11:07 AM, Shlomi Fish wrote:
> > Hi hwilmer,
> > 
> > On Fri, 10 May 2019 19:09:50 +0200
> > hwilmer <> wrote:
> >   
> >> Hi,
> >>
> >> I would like to use curl to retrieve an image from a web server which I
> >> want to store in a table in a mariadb database without downloading the
> >> image to a file.  For this application, I do not want to store
> >> references to files stored in some file system instead.
> >>
> >> So I would want to use something like
> >>
> >>
> >> my $binary_data = `curl -k ""`;
> >>  
> > 
> > Perl distinguishes between 8-bit/binary strings and unicode ones. See
> > .  
> What kind of string do I get when using backticks like in the above 
> example?  One that perl considers as a text string I could use stuff 
> like uc or lc on, or as a binary string I could use pack or unpack on? 
> Variables are without types, so there is no way to tell.  If I was using 
> curl to receive a text string, how would I know which encoding is being 
> used?  For all I know that could depend on the machine my program is 
> running on after lots of factors I would never know about.  And this 
> same encoding could happen to the image data.
> Why would I use pack or unpack on the image data curl puts into the 
> string?  Do I need to worry that somewhere --- like in my program or in 
> some method DBI provides or somewhere else --- some kind of string 
> transformation might take place that damages the image data?  Is there a 
> way to tell perl that this is actually not a string but some binary data 
> that must not be transformed or encoded?
> So far, it's working, but that could be just luck ...

Perhaps use open "-|" with an encoding - see .

> > Note however that you should see
> > and use a module instead of trapping curl.exe's output. Perl has bindings to
> > libcurl too if that is what you want.  
> First I tried to use WWW::Mechanize, and that failed because it can't 
> deal witch the self-signed certificates the web server is using.  I 
> couldn't find anywhere in the documentation how to allow such 
> certificates.  Otherwise it seemed to be able to do what I wanted.


> Using curl via the library bindings is somewhat going to lengths I would 
> rather avoid.

Shlomi Fish - Anime in Real Life!! (Parody)

Well, one thing I can tell you about parenthood is that such things
can progress from figurative to literal, extremely quickly.

Please reply to list if it's a mailing list post - .

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About