diomedea has asked for the wisdom of the Perl Monks concerning the following question:
and I want to put them in the hash to showmy @teststr; my %testhash; $teststr[0] = "32977186 4 -rw-r--r-- 1 owner mygrp 65 Aug 4 +13:16 /long/path/to/my/file/file1.txt"; $teststr[1] = "32977186 4 -rw-r--r-- 1 owner mygrp 65 Aug 4 +13:16 /long/path/to/my/file/file2.txt";
it works fine if I use foreach:file1=>file1.txt file2=>file2.txt
but I think I should be able to use map to do this, I cant seem to account for the changing $_foreach my $line (@teststr) { my ($key, $val); $val = (split /\//, $line)[-1]; ($key = $val) =~ s/\.txt//; $testhash{$key} = $val; }
givesmy %testhash = map {(my $val = (split /\//, $_)[-1]); ((my $key = $va +l) =~ s/\.txt//);} @teststr;
i think im getting the return value of the s//, so how can I do the split then run the regex on the result? thanks1 => 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash assignment using map with multiple statements
by ikegami (Patriarch) on Sep 19, 2008 at 08:27 UTC | |
by diomedea (Sexton) on Sep 19, 2008 at 08:40 UTC | |
|
Re: hash assignment using map with multiple statements
by oko1 (Deacon) on Sep 19, 2008 at 13:48 UTC | |
|
Re: hash assignment using map with multiple statements
by GrandFather (Saint) on Sep 19, 2008 at 21:14 UTC | |
|
Re: hash assignment using map with multiple statements
by repellent (Priest) on Sep 19, 2008 at 22:48 UTC | |
by diomedea (Sexton) on Sep 22, 2008 at 09:48 UTC | |
|
Re: hash assignment using map with multiple statements
by lamp (Chaplain) on Sep 19, 2008 at 09:14 UTC | |
by chromatic (Archbishop) on Sep 19, 2008 at 15:52 UTC |