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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Reformating pathname
by davorg (Chancellor) on Jun 07, 2001 at 18:47 UTC
Re: Reformating pathname
by mirod (Canon) on Jun 07, 2001 at 18:50 UTC

    Considering the little information you give you might be looking for:

    $file=~ s/input01/output61/;

    Or maybe something like:

    $file=~ s/input(\d+)/my $nb=$1+60;"output$nb"/e;

    where the code inside the right part of the substitution is eval'ed thanks to the /e modifier

Re: Reformating pathname
by Hofmator (Curate) on Jun 07, 2001 at 19:15 UTC

    To make it a one-liner - providing your source file names are in the file source.dat

    perl -pi.bak -e 's/input01/output61/' source.dat

    This assumes that the file names in source.dat are stored one per line. And a backupfile source.dat.bak is created with the original version of source.dat
    -- Hofmator

Re: Reformating pathname
by Jouke (Curate) on Jun 07, 2001 at 18:57 UTC
    I would do something like this:
    #!/usr/bin/perl -w use strict; #assume the filelist comes from STDIN while (<>) { print $1."output61".$2."\n" if /(.*?\/)input01(.*)/; }


    Jouke Visser, Perl 'Adept'
    Using Perl to help the disabled: pVoice and pStory
Re: Reformating pathname
by tachyon (Chancellor) on Jun 07, 2001 at 18:59 UTC

    You may like this:

    # assuming that $path contains the path to be changed my $old = 'input01'; my $new = 'output61'; $path =~ s/$old/$new/;

    tachyon