in reply to Re: Perl parse text file using hash
in thread Perl parse text file using hash

Hi Bill

> I assume that the character ! will never appear in the name of any person or fruit.

Actually you are reinventing the wheel here.

Perl has a built-in mechanism for multidimensional keys.

see $; aka $SUBSCRIPT_SEPARATOR in perlvar

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: Perl parse text file using hash
by BillKSmith (Monsignor) on Dec 20, 2022 at 18:46 UTC
    Rolf, That is a cleaver use of the Multi-Dimensional Array Emulation syntax even though that is not exactly what we are doing.

    In the spirit of 'not inventing a wheel', perl can also do the input, looping and splitting for us if we use the -n and -a command switches. (perlrun).

    #!perl -na use strict; use warnings; our %info; $info{$F[0],$F[1]} = $F[2]; END{ my $name = 'Jack'; my $fruit = 'pineapple'; my $path = $info{$name,$fruit}; print "$name $fruit $path\n"; }

    OUTPUT:

    >perl 1114899a.pl paths.csv Jack pineapple /path/to/somewhere/b
    Bill