Thanks, one of those days again (which I seem to be having more of). Just needed to change the print statement a bit.

Final version:

#!/usr/bin/perl -w #===================================================================== +========== # # FILE: create_seq_test.pl # # USAGE: ./create_seq_test.pl # # DESCRIPTION: Test script to "create sequences" from backup sql fil +e # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Gavin Henry (GH), <ghenry@suretecsystems.com> # COMPANY: Suretec Systems Ltd. # VERSION: 1.0 # CREATED: 29/12/05 14:42:44 GMT # REVISION: --- #===================================================================== +========== use strict; use warnings; use Carp; use Readonly; use Regexp::DefaultFlags; # Adds xms to the end of all Regexp use diagnostics; # More helpful error messages, comment out l +ater $| = 1; # Set the autoflush flag to on Readonly my $import_seqs => 'dbexp.sql'; Readonly my $create_seqs => 'cre_seq.sql'; open my $CREATE_SEQS, '+>', $create_seqs # using indirect filehand +les, r/w or croak "Can't open '$create_seqs': $!"; open my $SQL_TO_GREP, '<', $import_seqs # three-argument form is +more robust or croak "Can't open '$import_seqs': $!"; while ( <$SQL_TO_GREP> ) { if ( /\A SELECT [ ] pg_catalog [.] setval [(]/ ) { s{\A # Substitute from + start of line SELECT [ ] pg_catalog [.] setval [(] ['] # Replace this, w +hich uses singular # Character class +es to escape # metacharacters, + including spaces } {CREATE SEQUENCE imp.}; s{ ['] [,] [ ] }{ INCREMENT BY 1 START WITH }; s{ [,] [ ] false [)] ; }{;}; s{ [,] [ ] true [)] ; }{;}; print $CREATE_SEQS $_; } } close $SQL_TO_GREP or croak "Couldn't close '$import_seqs': $!"; close $CREATE_SEQS or croak "Couldn't close '$create_seqs': $!"; print "Create Sequence statements file complete.\n"

Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!

In reply to Re^2: Regexp Substitution on previously opened filehandle by ghenry
in thread Regexp Substitution on previously opened filehandle by ghenry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.