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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:27:00+00:00 2026-06-11T14:27:00+00:00

I need to circular shift some characters/bit using Perl For example, with the following

  • 0

I need to circular shift some characters/bit using Perl

For example, with the following input (reversing character strings):

1010
1110
hello

I need to obtain:

0101
0111
olleh

How do I achieve this using 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-06-11T14:27:01+00:00Added an answer on June 11, 2026 at 2:27 pm

    However, if you really want to circular shift values, it’s easy to write a function that does it with arbitrary lists for training:

    #!/usr/bin/env perl
    
    use strict;
    use warnings;
    use feature 'say';
    
    # circular shift lists
    sub circular {
        my ($i, @values) = @_;
        return @values[ map +($_ + $i) % @values => 0 .. $#values ];
    }
    
    say circular  4, 1 .. 9;                # 567891234
    say circular -2, 1 .. 9;                # 891234567
    say circular  3, split '' => 'hello';   # lohel
    

    A few words of explanation for the return line of circular:

    return @values[ ... ];
    

    We’re returning an array slice of @values here, which means we evaluate it with a list of indices and return the list of values.

    map ... => 0 .. $#values
    

    We’re returning a list of values here that we calculate from all indices of @values, 0 is the first, $#values is the last.

    +($_ + $i) % @values
    

    This is what we do with these indices. The + sign is only used to tell perl that the parantheses are not the argument paratheses for map. We add $i to the index and to prevent that it becomes > $#values we modulo divide it by the length of @values. Note that it’s not important to call length @values here because % evaluates its second operand in scalar context and arrays in scalar context evaluate to their length.

    I leave it up to you as a simple exercise to convert your things like hello or 1110 to lists and back to scalars.

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

Sidebar

Related Questions

I need to perform a circular left shift of a 64-bit integer in JavaScript.
I need to draw text onto a window HDC along a circular path using
Is there a way to define circular references without using pointers? I need to
Hi I need some help with the following scenario in php. I have a
Is there any variant to draw a circular segment using just CSS/CSS3? I need
I need to animate the filling of a circular progress meter with a HUD-like
I need to store items of varying length in a circular queue in a
Need some regular expressions help. So far I have my code working to allow
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
When you have a circular buffer represented as an array, and you need the

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.