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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:29:11+00:00 2026-05-27T16:29:11+00:00

With respect to the following code segment, foreach my $Index1 (sort { $A <=>

  • 0

With respect to the following code segment,

foreach my $Index1 (sort { $A <=> $B } keys %{$dat1->{dat1}->[$Index2]->{Vector}})
{
if($dat1->{dat1}->[$Index2]->{Vector}->{$Index1} == 2.0) { next }
    printf $sth
}

How to understand the my $Index1 (sort { $A <=> $B } keys %{$dat1->{dat1}->[$Index2]->{Vector}}) and ($dat1->{dat1}->[$Index2]->{Vector}->{$Index1} == 2.0)

How to understand their underlying logic piece by piece? Thanks.

  • 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-27T16:29:12+00:00Added an answer on May 27, 2026 at 4:29 pm

    It helps if you abstract the nested data structure away:

    my $VectorHashRef = $dat1->{dat1}->[$Index2]->{Vector};
    foreach my $Index1 (sort { $A <=> $B } keys %$VectorHashRef ) {
        # This should be corrected to $a <=> $b - names are case sensitive
        if ($VectorHashRef->{$Index1} == 2.0) { 
             next;
        }
        printf $sth;
    }
    

    $dat1->{dat1}->[$Index2]->{Vector} is a way to access some piece of data (a hashref) deep in a nested data structure. It takes a hashref $dat1, accesses the data structure that is pointed to by a hash key "dat1" – and that key points to an array reference. You take the value from that array with an index $Index2 – and that value is a reference to the next data structure (hashref). You take the value of that hash for the key "Vector" – which is another hashref.

    Now, let’s alias that Vector hashref with $VectorHashRef variable (I’m using the word alias loosely).

    Now, you are iterating over the keys of that hashref, sorted numerically (see Dan’s answer for details on how that works), and for each key, comparing the hash value to 2.0, printing something only if the value is NOT 2.0.

    To understand this well, you need to read somee data structures in Perl tutorial – for example Data Structures Cookbook (aka perldoc perldsc)

    In short:

    • When you see something that looks likie EXPRESSION->{KEY_EXPRESSION}, that means accessing the value (for a key specified by KEY_EXPRESSION) in a hashref, with the hash reference being the result of EXPRESSION.

    • When you see something that looks likie EXPRESSION->[INDEX_EXPRESSION], that means accessing the value (for a array subscript specified by INDEX_EXPRESSION) in an array reference, with the array reference being the result of EXPRESSION.

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

Sidebar

Related Questions

With respect to the following code segment: struct Pair{ string name; double val; }
With respect to the following code segment, I would like to know whether my
With respect to the following code snippet for making a dynamic array template <class
Still struggling to understand what best practices are with respect to macros. I'm attempting
Assume that the following code is being executed by 10 threads. pthread_mutex_lock(&lock) Some trivial
Suppose I'm using the following Oracle code in a stored procedure: CREATE GLOBAL TEMPORARY
I used the following piece of code to read data from files as part
I have the following code written to make my lazy second CPU core working.
alt text http://akashkava.com/blog/wp-content/uploads/2009/12/ListBoxItem-Selection-Problem.png The following code, behaves little strange. <ListBox SelectionMode=Multiple> <StackPanel> <TextBlock>Selection is
I have the following code in a view controller that (in all other respects)

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.