Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: grep confusion

by LanX (Saint)
on Sep 01, 2017 at 02:07 UTC ( [id://1198482]=note: print w/replies, xml ) Need Help??


in reply to grep confusion

Something like

print grep { $DetailSheet{ColumnName}{$_}{XlsColumn} == 2 } keys %{$DetailSheet{ColumnName}} ?

(Untested)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

update

Added ColumnName level

Replies are listed 'Best First'.
Re^2: grep confusion
by BillKSmith (Monsignor) on Sep 01, 2017 at 13:58 UTC
    The function first_value (from List::MoreUtils) is slightly better than grep because it returns the single value that you expect as a scalar.
    use strict; use warnings; use List::MoreUtils qw(first_value); my(%DetailSheet) = ( ... ); my %Column = %{$DetailSheet{ColumnName}}; my $description = first_value {$Column{$_}{XlsColumn} == 2} keys %Colu +mn; print $description, "\n";
    Bill
      IMHO it's unclear from the OP s description how many results he expects.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      I will need to look into that Bill, I'm always looking for shortcuts !

      I tried re-inventing the wheel again, but everytime I push it, it still falls flat on it's side...
Re^2: grep confusion
by PriNet (Monk) on Sep 01, 2017 at 02:13 UTC
    Hmmm... 'Error: Not a HASH reference'
    but I see where your going...

    I tried re-inventing the wheel again, but everytime I push it, it still falls flat on it's side...
        'Experimental keys on scalar is now forbidden'
        Let me see if I can add the %{...} and fix that...

        I tried re-inventing the wheel again, but everytime I push it, it still falls flat on it's side...
      wait... let me try that

      I tried re-inventing the wheel again, but everytime I push it, it still falls flat on it's side...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1198482]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-19 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found