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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:38:00+00:00 2026-06-07T23:38:00+00:00

I need help figuring out how these two subroutines work and what values or

  • 0

I need help figuring out how these two subroutines work and what values or data structures they return. Here’s a minimal representation of the code:

#!/usr/bin/perl
use strict; use warnings;

# an array of ASCII encrypted characters
my @quality = ("C~#p)eOA`/>*", "DCCec)ds~~", "*^&*"); # for instance

# input the quality
# the '@' character in front deferences the subroutine's returned array ref 
my @q = @{unpack_qual_to_phred(@quality)};

print pack_phred_to_qual(\@q) . "\n";

sub unpack_qual_to_phred{
    my ($qual)=@_;
    my $upack_code='c' . length($qual);
    my @q=unpack("$upack_code",$qual);
    for(my $i=0;$i<@q;$i++){
        $q[$i]-=64;
    }
    return(\@q);
}

sub pack_phred_to_qual{
    my ($q_ref)=@_;
    @q=@{$q_ref};
    for(my $i=0;$i<@q;$i++){
        $q[$i]+=64;
    }
    my $pack_code='c' . int(@q);
    my $qual=pack("$pack_code",@q);

    return ($qual);
}


1;

From my understanding, the unpack_qual_to_phread() subroutine apparently decrypts the ASCII character elements stored in @quality. The subroutine reads in an array containing elements of ASCII characters. Each element of the array is processed and apparently decrypted. The subroutine then returns an array ref containing elements of the decrypted array. I understand this much however I’m not really familiar with the Perl functions pack and unpack. Also I was unable to find any good examples of them online.

I think the pack_phred_to_qual subroutine converts the quality array ref back into ASCII characters and prints them.

thanks. any help or suggestions are greatly appreciated. Also if someone could provide a simple example of how Perl’s pack and unpack functions work that would help too.

  • 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-06-07T23:38:02+00:00Added an answer on June 7, 2026 at 11:38 pm

    Calculating the length is needless. Those functions can be simplified to

    sub unpack_qual_to_phred { [ map $_ - 64, unpack 'c*', $_[0] ] }
    sub pack_phred_to_qual { pack 'c*', map $_ + 64, @{ $_[0] } }
    

    In encryption terms, it’s a crazy simple substitution cypher. It simply subtracts 64 from the character number of each character. It could have been written as

    sub encrypt { map $_ - 64, @_ }
    sub decrypt { map $_ + 64, @_ }
    

    The pack/unpack doesn’t factor in the encryption/decryption at all; it’s just a way of iterating over each byte.

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

Sidebar

Related Questions

I need help figuring out these php print (echo) statements and where to place
I need some help figuring out why the following scenario does not work. I'm
I need help figuring out why my rspec tests are running slowly. I am
I need some help figuring out how I should do this. I would like
I need a little help figuring out what the following URL rewrite rule means.
I know I'm close to figuring this out but need a little help. What
I need help figuring out how to change out the view in my application.
I have a 5 byte data element and I need some help in figuring
I need some help figuring out the best way to proceed with creating a
I need help figuring out how to accomodate situations in which $hash {$i} is

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.