Re: search and replace on an array
- From: David Squire <David.Squire@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 30 Jun 2006 16:37:31 +0100
ebm wrote:
I'm looking for a quick way to do a search and replace on an array of
values.
for instance I can do it this way, but is there a better way?
my @files = ("File1","File2");
my $path = ("c:\\path\\to\\");
@PathFile = map { [ $path . $_ ] } @files;
Why do you want to do this? Why not just interpolate the directory path and filename into a string at the time it is needed, e.g.:
for my $Dir ('c:/path/to', 'd:/new/path') { # note you don't need to use Windows style slashes
for my $File ('File1', 'File2') {
open my $FileHandle, "$Dir/$File", '<' or die "Can't open $Dir/$File:$!";
# ... do stuff
}
}
$newPath = "D:\\new\\place";.
# now I have my path and file names combined and
#I can do some stuff with this. after I've done my work
# with it, is there an easy way to change my path name in
# my @newPath array?
# I can do it this way but is there a better way?
foreach(@newPath){
$_ =~ s/C:\\/D:\\/;
push ( @newArray, $_ );
}
# I want to do something like
# this @newPath =~ s/\Q$path\E/\Q$newPath\E/;
Can somebody give me a hand?
- Follow-Ups:
- Re: search and replace on an array
- From: David Squire
- Re: search and replace on an array
- References:
- search and replace on an array
- From: ebm
- search and replace on an array
- Prev by Date: search and replace on an array
- Next by Date: Re: search and replace on an array
- Previous by thread: search and replace on an array
- Next by thread: Re: search and replace on an array
- Index(es):