As ikegami has mentioned, you have to remember what "map" returns - as the docs say, it's an evaluation of each operation within the block as a list (in my experience, the "s///" inside a "map" is one of the most common mistakes that new users of "map" make.)
Incidentally, since you're already using a regex inside your block, you don't really need that "split":
#!/usr/bin/perl -w use strict; my @teststr = ( "32977186 4 -rw-r--r-- 1 owner mygrp 65 Aug 4 13:16 /long/pa +th/to/my/file/file1.txt", "32977186 4 -rw-r--r-- 1 owner mygrp 65 Aug 4 13:16 /long/pa +th/to/my/file/file2.txt", "32977186 4 -rw-r--r-- 1 owner mygrp 65 Aug 4 13:16 /long/pa +th/to/my/file/file3.txt", "32977186 4 -rw-r--r-- 1 owner mygrp 65 Aug 4 13:16 /long/pa +th/to/my/file/file4.txt", ); my %testhash = map { m{(([^/]+)\.[^/]+)$}; $2, $1 } @teststr; print "$_ => $testhash{$_}\n" for sort keys %testhash;
Output:
file1 => file1.txt file2 => file2.txt file3 => file3.txt file4 => file4.txt
In reply to Re: hash assignment using map with multiple statements
by oko1
in thread hash assignment using map with multiple statements
by diomedea
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |