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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:57:33+00:00 2026-05-26T11:57:33+00:00

I wrote this code in perl: shift( @interfaces = qx’ifconfig -s’ ); And got

  • 0

I wrote this code in perl:

shift( @interfaces = qx'ifconfig -s' );

And got this error:

Type of arg 1 to shift must be array (not list assignment)

When I write it this way:

@interfaces = qx'ifconfig -s';
shift @interfaces;

It does what I want, which is to get the output of the ifconfig command as an array of lines and remove the first element in the array (which is a header, not an actual interface).

My personal preference is to write this as a one liner. It seems to me the parentheses in the first example should cause the assignment to be resolved fully, therefore allowing shift to see @interfaces as an array, but clearly perl thinks it’s a “list assignment.”

This is surely an easy question for the perl gurus but I’ve googled and googled and haven’t found enlightenment.

If someone would please provide the specific semantics to accomplish what I want in one line I would appreciate it. If you would also please take the time to explain why my first version isn’t working I would be eternally grateful (teach a man to fish and all that).

Thank you in advance for your help.

  • 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-26T11:57:34+00:00Added an answer on May 26, 2026 at 11:57 am

    As you saw, shift requires a literal array, not the result of an assignment. This is because when perl parses shift @interfaces it is actually rewriting it into something like &CORE::shift(\@interfaces) and you can not take a reference of an assignment and get an array ref.

    You could break it into two lines as you have found, you could hide the assignment inside a bracketed dereference as mob shows, or you could simply throw away the first value:

    (undef, @interfaces) = qx'ifconfig -s';
    

    undef in an lvalue position is a placeholder for values that you don’t need.

    (parsing of shift has changed a bit in perl 5.14+, but the argument above still holds)


    a few more ways that you probably shouldn’t use, ordered only by increasing length 🙂

    my @interfaces = sub {shift; @_}->(qx'ifconfig -s');
    
    my @interfaces = sub {@_[1..$#_]}->(qx'ifconfig -s');
    
    my @interfaces = map {@$_[1..$#$_]} [qx'ifconfig -s'];
    
    my @interfaces = map {shift @$_; @$_} [qx'ifconfig -s'];
    
    our @interfaces; shift @{*interfaces = [qx'ifconfig -s']};
    
    my @interfaces = sub {*_ = [qx'ifconfig -s']; shift; @_}->();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
i wrote this tiny code on gedit and ran it :- #/usr/bin/perl print Enter
I have this code: $coder = JSON::XS->new->utf8->pretty->allow_nonref; %perl = $coder->decode ($json); When I write
I wrote this code in C# to encrypt a string with a key: private
I wrote this code. The constructor works normally, but in the destructor I get
If I wrote this code: typeof(myType).TypeHandle Would it use reflection? How much different from:
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
I was trying to understand something with pointers, so I wrote this code: #include
I want to convert function object to function. I wrote this code, but it
I wrote this tiny code: #include <stdio.h> int main() { size_t temp; temp =

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.