in reply to Java Repackager...

Looks like a job for this one liner:
perl -i -pe 's/^(import\s+)OldPackage/$1NewPackage/' *.java

Replies are listed 'Best First'.
Re: Re: Java Repackager...
by belg4mit (Prior) on Nov 27, 2001 at 23:11 UTC
    If you care about your java, which one might assume based upon your poem, you might want to do:
    perl -i~ -pe 's/^(import\s+)OldPackage/$1NewPackage/' *.java

    --
    perl -p -e "s/(?:\w);([st])/'\$1/mg"

Re: Re: Java Repackager...
by rje (Deacon) on Nov 27, 2001 at 21:56 UTC
    So is it reasonable to replace the foreach loop with
    a call to perl, containing:

    `perl -i -pe 's/^(import\s+)$oldPackage/$1NewPackage/' *.java`; print "Updated:\n"; print join( "\n", <*.java> );

    I'm wary of calling perl inside perl, because I have
    no idea what really happens (is a new perl interpreter
    spawned? Are there Really Bad side effects? etc.)
    So tell me! Inquiring minds want to know...

    Rob

      My point was that you can replace whole script with this one-liner.

      If you will embed it into some bigger script than it will do cause new perl interpreter to spawn. As for Really Bad side effects: it will be perfomance hit (but you should not care about it in this case) and probably it is not very good style. At least I would not embed such one-liner in my Perl code myself because IMHO embedding Perl code inside Perl code looks somewhat ugly.

      Probably foreach loop could be written slightly shorter but in general your original script is ok. I just wanted to show fast dirty way to do the same.

        Thanks for the clarification.

        The script was written for a colleague who knows neither
        perl nor regexps; therefore, the outer scaffolding is
        necessary. However, your comment stands: the performance
        hit just doesn't matter in this case, it's true.

        Rob