#!/usr/bin/perl use strict; use warnings; use File::Basename; # Ivan Novick # map.pl # demonstrate the perl map function to create a new array which is # a transformation of the members of the original array my @paths = ('/home/novick/mynotes.txt', '/var/log/messages', '/proc/cpuinfo'); # use perl map function to transform each member of @paths into just the filename, without the path # for each member of the original array, the last statement in the map block will be what gets pushed into the new array my @files = map { my($filename, $path) = fileparse($_); $filename } @paths; # print out the filenames that are the result of the transformation of the original array for my $f (@files) { print "file: $f\n"; } # print out the orignal data to prove it is not modified for my $p (@paths) { print "path: $p\n"; }