Professional Web Applications Themes

get rid of whitespace around pipes?? - PERL Beginners

On Dec 17, LoneWolf said: >I am parsing a massive file line by line and cleaning it up. It has about >15 fields, all separated by | and I want to remove the white space from >before and after the pipes so that as the information is pd it gets rid >of external white spaces from the string and such. Then split on /\s*\|\s*/. That regex reads "zero or more whitespace, a |, then zero or more whitespace". fields = split /\s*\|\s*/, $line; -- Jeff "japhy" Pinyan [email]japhypobox.com[/email] [url]http://www.pobox.com/~japhy/[/url] RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url] <stu> what does y/// stand ...

  1. #1

    Default Re: get rid of whitespace around pipes??

    On Dec 17, LoneWolf said:
    >I am parsing a massive file line by line and cleaning it up. It has about
    >15 fields, all separated by | and I want to remove the white space from
    >before and after the pipes so that as the information is pd it gets rid
    >of external white spaces from the string and such.
    Then split on /\s*\|\s*/. That regex reads "zero or more whitespace, a |,
    then zero or more whitespace".

    fields = split /\s*\|\s*/, $line;

    --
    Jeff "japhy" Pinyan [email]japhypobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
    RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
    <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
    [ I'm looking for programming work. If you like my work, let me know. ]

    Jeff 'Japhy' Pinyan Guest

  2. #2

    Default Re: get rid of whitespace around pipes??

    On 12/17/2003 11:26 AM, LoneWolf wrote:
    > I am parsing a massive file line by line and cleaning it up. It has about
    > 15 fields, all separated by | and I want to remove the white space from
    > before and after the pipes so that as the information is pd it gets rid
    > of external white spaces from the string and such.
    >
    > Some fields are numbers, others are strings, and a couple are arrays.
    >
    > sample:
    > 1|AA-1202 |12in. X10.75 FOIL SHEETS 12/200| 70.96 | 46.40 | 45.24 | 44.13
    > |246|3| 55.000 | .000 | .000 |A |AA-1202
    > 2| AA-1205 |12in. x10in. FOIL POPUP SHEETS 6/500| 96.61 | 63.17 | 61.59 |
    > 60.09 |246|3| 25.000 | 6.000 | .000 |B | AA-1205
    my fields = split /\s*\|\s*/, $line;


    Randy W. Sims Guest

  3. #3

    Default Re: get rid of whitespace around pipes??

    On Dec 17, 2003, at 10:26 AM, LoneWolf wrote:
    > I am parsing a massive file line by line and cleaning it up. It has
    > about
    > 15 fields, all separated by | and I want to remove the white space from
    > before and after the pipes so that as the information is pd it
    > gets rid
    > of external white spaces from the string and such.
    Try something like:

    my fields = split /\s*\|\s*/, $line;

    Good luck.

    James

    James Edward Gray II Guest

  4. #4

    Default get rid of whitespace around pipes??

    I am parsing a massive file line by line and cleaning it up. It has about
    15 fields, all separated by | and I want to remove the white space from
    before and after the pipes so that as the information is pd it gets rid
    of external white spaces from the string and such.

    Some fields are numbers, others are strings, and a couple are arrays.

    sample:
    1|AA-1202 |12in. X10.75 FOIL SHEETS 12/200| 70.96 | 46.40 | 45.24 | 44.13
    |246|3| 55.000 | .000 | .000 |A |AA-1202
    2| AA-1205 |12in. x10in. FOIL POPUP SHEETS 6/500| 96.61 | 63.17 | 61.59 |
    60.09 |246|3| 25.000 | 6.000 | .000 |B | AA-1205


    TIA!!

    Robert
    Lonewolf Guest

Similar Threads

  1. Bidirectional pipes
    By Mehmet Ekici in forum PERL Beginners
    Replies: 4
    Last Post: January 28th, 10:45 PM
  2. How do I set up bidirectional pipes over a network connection?
    By Dan Anderson in forum PERL Beginners
    Replies: 12
    Last Post: December 10th, 11:31 PM
  3. problem connecting pipes in Expect.pm
    By Mike in forum PERL Modules
    Replies: 0
    Last Post: November 26th, 07:25 PM
  4. bi-directional IPC / pipes / when to close??
    By ixtahdoom in forum UNIX Programming
    Replies: 3
    Last Post: July 20th, 06:05 PM
  5. Hanging pipes in CGI Perl
    By Bob Walton in forum PERL Miscellaneous
    Replies: 3
    Last Post: July 10th, 09:36 AM

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