Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 867077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:54:57+00:00 2026-05-15T09:54:57+00:00

In Perl, is it appropriate to use a string as a byte array containing

  • 0

In Perl, is it appropriate to use a string as a byte array containing 8-bit data? All the documentation I can find on this subject focuses on 7-bit strings.

For instance, if I read some data from a binary file into $data

my $data;

open FILE, "<", $filepath;
binmode FILE;
read FILE $data 1024;

and I want to get the first byte out, is substr($data,1,1) appropriate? (again, assuming it is 8-bit data)

I come from a mostly C background, and I am used to passing a char pointer to a read() function. My problem might be that I don’t understand what the underlying representation of a string is in Perl.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:54:57+00:00Added an answer on May 15, 2026 at 9:54 am

    The bundled documentation for the read command, reproduced here, provides a lot of information that is relevant to your question.

    read FILEHANDLE,SCALAR,LENGTH,OFFSET

    read FILEHANDLE,SCALAR,LENGTH

    Attempts to read LENGTH characters of data into variable SCALAR
    from the specified FILEHANDLE. Returns the number of
    characters actually read, 0 at end of file, or undef if there
    was an error (in the latter case $! is also set). SCALAR will
    be grown or shrunk so that the last character actually read is
    the last character of the scalar after the read.

    An OFFSET may be specified to place the read data at some place
    in the string other than the beginning. A negative OFFSET
    specifies placement at that many characters counting backwards
    from the end of the string. A positive OFFSET greater than the
    length of SCALAR results in the string being padded to the
    required size with “\0” bytes before the result of the read is
    appended.

    The call is actually implemented in terms of either Perl’s or
    system’s fread() call. To get a true read(2) system call, see
    “sysread”.

    Note the characters: depending on the status of the filehandle,
    either (8-bit) bytes or characters are read. By default all
    filehandles operate on bytes, but for example if the filehandle
    has been opened with the “:utf8” I/O layer (see “open”, and the
    “open” pragma, open), the I/O will operate on UTF-8 encoded
    Unicode characters, not bytes.
    Similarly for the “:encoding”
    pragma: in that case pretty much any characters can be read.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 433k
  • Answers 433k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Short answer: Always. Long answer: Always. That's what they are… May 15, 2026 at 3:03 pm
  • Editorial Team
    Editorial Team added an answer It may be due to the fact that Notepad inserts… May 15, 2026 at 3:03 pm
  • Editorial Team
    Editorial Team added an answer Done correctly it can be better for: the end user,… May 15, 2026 at 3:03 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.