Professional Web Applications Themes

Pattern Matching records from a table query. - PERL Beginners

I want to eliminate the ". " (periord) or "," (comma) from records that I return from a query, but I cannot figure out how to approach it. Does Perl have a way that I can match a string that from an array, remove a character or characters? For example say I have array records that contain the following: Myrecord1 Myrecord2 Myrecord3 Myrecord4 Myrecord5, inc. Myrecord6, LP Myrecord7, LLC I want to send this query out to persons in a .csv file but the join(",", record) statement that I am using causes the and extra cell to be created at ...

  1. #1

    Default Pattern Matching records from a table query.

    I want to eliminate the ". " (periord) or "," (comma) from records that I return from a query, but I cannot figure out how to approach it. Does Perl have a way that I can match a string that from an array, remove a character or characters?


    For example say I have array records that contain the following:

    Myrecord1 Myrecord2 Myrecord3 Myrecord4 Myrecord5, inc. Myrecord6, LP Myrecord7, LLC

    I want to send this query out to persons in a .csv file but the join(",", record) statement that I am using causes the and extra cell to be created at Myrecord5, inc. Myrecord6, LP Myrecord7, LLC.


    What I am thinking is to scan records $record[4, 5, 6] by using regex matching, and if a comma exists, delete it or replace it with ";" . I am looking for some commands to do this, or at least point me in the right direction. Any suggestions?



    Jason Guest

  2. #2

    Default Re: Pattern Matching records from a table query.

    On Jul 16, 2004, at 3:46 PM, jason corbett wrote:
     

    How about?

    tr/.,//d foreach records;

    James

    James Guest

  3. #3

    Default RE: Pattern Matching records from a table query.

    jason corbett <com> wrote:

    : I want to eliminate the ". " (periord) or "," (comma) from
    : records that I return from a query, but I cannot figure out
    : how to approach it. Does Perl have a way that I can match a
    : string that from an array, remove a character or characters?
    :
    :
    : For example say I have array records that contain the
    : following:
    :
    : Myrecord1 Myrecord2 Myrecord3 Myrecord4
    : Myrecord5, inc. Myrecord6, LP Myrecord7, LLC
    :
    : I want to send this query out to persons in a .csv file but
    : the join(",", record) statement that I am using causes the
    : and extra cell to be created at Myrecord5, inc. Myrecord6, LP
    : Myrecord7, LLC.
    :
    : What I am thinking is to scan records $record[4, 5, 6] by
    : using regex matching, and if a comma exists, delete it or
    : replace it with ";" . I am looking for some commands to do
    : this, or at least point me in the right direction.
    :
    : Any suggestions?

    You mention an extra cell. If you are using this for
    import to a spreadsheet, you should be able to wrap suspect
    fileds with double quotes. Try this.

    $_ = qq("$_") foreach record[4, 5, 6];
    my $record_list = join ',', record;


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328

    Charles Guest

  4. #4

    Default [This is what I needed]Pattern Matching records from a table query.

    Thanks. I was using the Pipe thing, but the fact is my client wants it in Excel and to be able to open it immediately and not "click around with the parameters" as they are not Excel friendly (go figure). I appreaciate your willingness to carry the question out to a solution/example and not a quick fix!

    JC

    "Charles K. Clarkson" <net> wrote:
    jason corbett wrote:

    : I want to eliminate the ". " (periord) or "," (comma) from
    : records that I return from a query, but I cannot figure out
    : how to approach it. Does Perl have a way that I can match a
    : string that from an array, remove a character or characters?
    :
    :
    : For example say I have array records that contain the
    : following:
    :
    : Myrecord1 Myrecord2 Myrecord3 Myrecord4
    : Myrecord5, inc. Myrecord6, LP Myrecord7, LLC
    :
    : I want to send this query out to persons in a .csv file but
    : the join(",", record) statement that I am using causes the
    : and extra cell to be created at Myrecord5, inc. Myrecord6, LP
    : Myrecord7, LLC.
    :
    : What I am thinking is to scan records $record[4, 5, 6] by
    : using regex matching, and if a comma exists, delete it or
    : replace it with ";" . I am looking for some commands to do
    : this, or at least point me in the right direction.
    :
    : Any suggestions?

    You mention an extra cell. If you are using this for
    import to a spreadsheet, you should be able to wrap suspect
    fileds with double quotes. Try this.

    $_ = qq("$_") foreach record[4, 5, 6];
    my $record_list = join ',', record;


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328


    Jason Guest

  5. #5

    Default Re: Pattern Matching records from a table query.

    Thanks James. I am going to try this method also. Your input is very much appreciated.

    JC

    James Edward Gray II <net> wrote:
    On Jul 16, 2004, at 3:46 PM, jason corbett wrote:
     

    How about?

    tr/.,//d foreach records;

    James


    --
    To unsubscribe, e-mail: org
    For additional commands, e-mail: org




    Jason Guest

Similar Threads

  1. pattern matching
    By Tad McClellan in forum PERL Beginners
    Replies: 30
    Last Post: June 23rd, 07:42 PM
  2. pattern matching
    By Lex in forum PERL Miscellaneous
    Replies: 13
    Last Post: October 11th, 09:14 AM
  3. Delete from one table with matching records in another table
    By Dale Fye in forum Microsoft SQL / MS SQL Server
    Replies: 4
    Last Post: July 1st, 01:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139