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

  • Home
  • SEARCH
  • 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 6829099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:27:37+00:00 2026-05-26T22:27:37+00:00

I have an array of hash references: my @price = ( { id =>

  • 0

I have an array of hash references:

my @price = (
    {
        id    => '1',
        label => 5.00
    },
    {
        id    => '2',
        label => 7.50
    },
);

I also have 2 variable integers, $diff and $last. when I try to iterate over the array to multiply the “label” by $diff/$last:

foreach (@price) {
    print "(($diff/$last)*$_->{label})\t";
}

i get the following output:

((12/30)*5.00)
((12/30)*7.50)

I assume it is not multiplying because I have two integers and a hash reference. If this is correct, how can I make the hash reference an integer? How can I force Perl to actually do the math and print the resulting product?

  • 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-26T22:27:37+00:00Added an answer on May 26, 2026 at 10:27 pm

    It’s not multiplying because all of that is inside the double quotes. You need to do:

    print( (($diff/$last)*$_->{label}) . "\t" );
    

    The way you’re doing it perl is simply interpolating the variables and printing their values because they are enclosed within the quotes. The * is simply treated as a character to print. The above does the math then the . causes a concatenation to "\t" (which converts the result to a string).

    $a = 5;
    $b = 6;
    print "$a + $b\n";
    print $a + $b . "\n";
    

    Outputs:

    5 + 6
    11

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

Sidebar

Related Questions

I have an array of hash references. The hashes contain 2 keys, USER and
I have an array, and I want to make a hash so I can
I have array that element is hash a = [{:history_date=>15/07/10}, {:open_price=>7.90}] I want to
I have to pass two references as arguments to a subroutine (buildRanges) as hash
If I have an array and hash like these #!/usr/bin/perl use warnings; use strict;
I have a array of hash refs. The date field in a hash is
So lets say I have an array containing a hash like this: [{head=> {title=>$20,000
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
if i have array array[0] = jack; array[1] = jill; array[2] = lisa; array[2]

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.