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 806409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:14:19+00:00 2026-05-15T00:14:19+00:00

I have text file looks like that: float a[10] = { 7.100000e+000 , 9.100000e+000

  • 0

I have text file looks like that:

float a[10] = {
    7.100000e+000 ,
    9.100000e+000 ,
    2.100000e+000 ,
    1.100000e+000 ,
    8.200000e+000 ,
    7.220000e+000 ,
    7.220000e+000 ,
    7.222000e+000 ,
    1.120000e+000 ,
    1.987600e+000
};

unsigned int col_ind[10] = {
    1 ,
    4 ,
    3 ,
    4 ,
    5 ,
    2 ,
    3 ,
    4 ,
    1 ,
    5
};

Now, I want to convert each array (float / unsigned int) to different binary files – big endian type, a binary file for all float values and a binary file for all integer values.

What is the simple way to do it in Perl, consider I have over two millon elements in each array?

  • 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-15T00:14:19+00:00Added an answer on May 15, 2026 at 12:14 am

    You’ll want to look into binmode and pack. Here’s an example that might get you started. I’m not sure I’ve chosen the pack templates that you need, but see the pack documentation for all of the choices.

    use strict;
    use warnings;
    
    my ($fh, $pack_template);
    
    while (my $line = <>){
        if ( $line =~ /(float|int)/ ){
            $pack_template = $1 eq 'int' ? 'i' : 'f';
    
            undef $fh;
            open $fh, '>', "$1.dat" or die $!;
            binmode $fh;
    
            next;
        }
    
        next unless $line =~ /\d/;
        $line =~ s/[,\s]+$//;
    
        print $fh pack($pack_template, $line);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that looks like this. A 102 B 456 C
I have a text file that looks like this: value1 value2 value3 There are
I have a text file that looks a bit like: random text random text,
I have a file (called print_1012720.txt ) that looks like the text shown below.
I have a text file that looks like this and I'm splitting at each
I have a text file that looks like this: Id:001;status:open;Id:002;status:open;Id:003;status:closed; Id:004;status:open;Id:005;status:closed;Id:006;status:open; .... .... Here
I have a text file that looks like this: 1,Smith, 249.24, 6/10/2010 2,Johnson, 1332.23,
I currently have a text file that looks like this: Test1 = 120827 =
I have a text file (bowtie alignment file) that looks like this: read_1 +
I have a text file that looks like this: [22/Nov/2011 12:57:58] GET /media/js/jquery-1.4.3.min.js HTTP/1.1

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.