Re: (hash|2-dim array) question
From: Tassos (chatasos_at_yahoo.com)
Date: 12/15/03
- Next message: Uri Guttman: "Re: recursive closures?"
- Previous message: Bart Van der Donck: "Re: Russian to Windows-1252 (htmlencode)"
- In reply to: Tad McClellan: "Re: (hash|2-dim array) question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 15 Dec 2003 18:01:08 +0200
Tad McClellan wrote:
> Tassos <chatasos@yahoo.com> wrote:
>
>
>>I want while reading the file to create something (a hash? a 2-dim array?)
>
>
>
> A Hash Of Lists (HoL) would be convenient.
>
> perldoc perlreftut
> perldoc perlref
> perldoc perllol
> perldoc perldsc
>
>
>
>>that will
>>enable me to get the following results:
>>
>>my $temp;
>>
>>$temp = "I1";
>>print array2($temp,1) # gives "[test1]" as the output
>>print array2($temp,2) # gives "([\w\-\.:/]+)" as the output
>
>
>
> ---------------------------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my %array2;
> while ( <DATA> ) {
> chomp;
> my @fields = split /;/;
> $array2{$fields[0]} = \@fields;
> }
>
> my $key = 'I1';
> print $array2{$key}[1], "\n";
> print $array2{$key}[2], "\n";
>
> __DATA__
> I1;[test1];([\w\-\.:/]+)
> I2;[test2];(\w\d [\d\/]+)
> ---------------------------------------------------
>
I want to have another hash (same $key) with [1],[2] empty.
Is there a better way than the following?
foreach (@Fields) {
chomp($_);
my @fields = split /;/;
my @fields2 = split /;/;
@fields2[1..2] = "";
$array2{$fields[0]} = \@fields;
$array3{$fields[0]} = \@fields2;
}
>
- Next message: Uri Guttman: "Re: recursive closures?"
- Previous message: Bart Van der Donck: "Re: Russian to Windows-1252 (htmlencode)"
- In reply to: Tad McClellan: "Re: (hash|2-dim array) question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|