Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Substitution query

by Anonymous Monk
on Nov 20, 2014 at 05:00 UTC ( [id://1107873]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks I'm having some issues with trying to get a substitution working or to think of another method to do what I need done. I have the following code

find(\&all, @allpaths); open (LIST, ">$filepath/Paths.bak") or die "$! error trying to ove +rwrite"; foreach my $p (@allpathlisting) { print LIST "$p\n"; } close LIST; copy $allpatholdfile, $allpathnewfile or die "$! error trying to c +opyfile"; sub all { return unless -d; $File::Find::prune = 1 if /[IPDLMY]\d{8}$/; (my $fn = $File::Find::name) =~ tr#/#\\#; push @allpathlisting, $fn if /[IPDLMY]\d{8}$/; print "$fn\n" if /[IPDLMY]\d{8}$/; foreach (@allpathlisting) { s/gpfs_data/nas\/rdds/; } }

I want to replace /gpfs_data/ with /nas/rdds/ I'm wondering if the code below

foreach (@allpathlisting) { s/gpfs_data/nas\/rdds/; }

Could be added somehow to

(my $fn = $File::Find::name) =~ tr#/#\\#;

Because my script is taking a bit longer to run now and I can't get Perl to replace the / with \ in this bit /nas\/rdds/

Sorry for the formatting, I had comments at the ends of lines but pasting it here made the code all weird

Replies are listed 'Best First'.
Re: Substitution query
by Loops (Curate) on Nov 20, 2014 at 05:11 UTC

    Yeah, it can be done on the next line after your tr:

    $fn =~ s/gpfs_data/nas\/rdds/;

    You definitely don't want to loop through the entire @allpathlisting array every time you add a single new file to it.

      Thanks for that it fixed the speed, I get the reason now.

      However this bit

      $fn =~ s/gpfs_data/nas\/rdds/;

      is still producing a rogue forward slash in my path

      \\nas/rdds\open\

        Then change the substitution text to nas\\rdds instead.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1107873]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found