Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Perl on the command line

Expand Messages
  • Nicholas Robinson
    Hi Jenda, Thanks for getting back. This build script isnt part of a batch file. However, the code you have provided is perfect apart from the - i section.
    Message 1 of 5 , Mar 31, 2003
    • 0 Attachment
      Hi Jenda,

      Thanks for getting back. This build script isnt part of a batch
      file. However, the code you have provided is perfect apart from the -
      i section. You need to give it an extension otherwise Perl wont do
      an in-place edit. But it works once you do that.

      Thanks,

      Nick.
      --- In perl-beginner@yahoogroups.com, "Jenda Krynicky" <Jenda@K...>
      wrote:
      > From: "Nicholas Robinson" <nicholasrobinson@y...>
      > > I need to invoke Perl from the command line as part of a build
      > > environment. The following is what I have ended up with, but it
      > > doesnt work:
      > >
      > > perl -e "use File::Copy;" -e "copy(\"input.sql\",
      > > \"input.sql.work\");" p -i -e "s/username/nrobin/;" input.sql.work
      > >
      > > The idea is that I first copy input.sql to input.sql.work. With
      that
      > > output file, I execute the regex. The error reported is "Can't
      open
      > > input.sql.work".
      >
      > You seems to be missing a - in front of the p option.
      >
      > You have this in a batch file, right? Why don't you use two
      commands
      > like this:
      >
      > copy input.sql input.sql.work
      > perl -p -i -e "s/username/nrobin/;" input.sql.work
      >
      > Another thing that might work is this:
      >
      > perl -MFile::Copy -p -i -e "BEGIN {copy 'input.sql',
      > 'input.sql.work'}; s/username/nrobin/;" input.sql.work
      >
      >
      > Jenda
      > ===== Jenda@K... === http://Jenda.Krynicky.cz =====
      > When it comes to wine, women and song, wizards are allowed
      > to get drunk and croon as much as they like.
      > -- Terry Pratchett in Sourcery
    • lgl12356
      Hi. I need to add a space or character at the end of each line in a file. From a couple of books (and jumping on another thread) I ve come up with... perl -p
      Message 2 of 5 , Jul 29, 2003
      • 0 Attachment
        Hi.

        I need to add a space or character at the end of each line
        in a file. From a couple of books (and jumping on another
        thread) I've come up with...

        perl -p -i -e "s/[$]/ [$]/;" file.dat


        ideas? will the second [$] do an infinite loop?
        whuttabout "..../g" ?

        (guess I need to do something like a -p [$] to
        see what the actual last character is?)

        I need to load Perl up on the machine in question, but
        on another MS2000 machine, the -i whines about not
        working without a backup file, and if I -i .bak (as
        in book), it bitches even more. ???

        Thanks for any help,

        Lowell
      • Damien Carbery
        ... One thing you don t mention is whether you ve tried the code you list and what results you got. The $ is for matching, not replacing. It is redundant on
        Message 3 of 5 , Jul 30, 2003
        • 0 Attachment
          --- In perl-beginner@yahoogroups.com, "lgl12356" <lamb@M...> wrote:
          >
          > Hi.
          >
          > I need to add a space or character at the end of each line
          > in a file. From a couple of books (and jumping on another
          > thread) I've come up with...
          >
          > perl -p -i -e "s/[$]/ [$]/;" file.dat
          >
          >
          > ideas? will the second [$] do an infinite loop?
          > whuttabout "..../g" ?
          >
          > (guess I need to do something like a -p [$] to
          > see what the actual last character is?)
          >
          > I need to load Perl up on the machine in question, but
          > on another MS2000 machine, the -i whines about not
          > working without a backup file, and if I -i .bak (as
          > in book), it bitches even more. ???
          >
          > Thanks for any help,
          >
          > Lowell

          One thing you don't mention is whether you've tried the code you list
          and what results you got.

          The '$' is for matching, not replacing. It is redundant on the second
          half of the 's///' construct.
          If you put the code in single quotes the '$' should not be modified
          and you'd remove the need for the square brackets - haven't tried this.
          perl -p -i -e 's/$/ /;' file.dat

          You don't need the 'g' modifier because on each line there is only one
          occurance of the end of the line.

          Does it make any difference if you remove the space after '-i'?
          In 'perl --help' there is no space after any option except '-e'
        Your message has been successfully submitted and would be delivered to recipients shortly.