get rid of whitespace around pipes??

Ask a Question related to PERL Beginners, Design and Development.

  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 parsed 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]japhy@pobox.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. Similar Questions and Discussions

    1. Bidirectional pipes
      Hi all, I wonder how can I open pipe to STDIN and STDOUT of a process ? Tnx. Mehmet
    2. How do I set up bidirectional pipes over a network connection?
      I have 2 Linux boxes I want to talk to each other over the local network using a Perl script. Is it possible to set up a bidirectional pipe so...
    3. problem connecting pipes in Expect.pm
      Here is a script I'm working on to connect to various lpars that are connected to my local HMC. The script creates the proper magic string and is...
    4. bi-directional IPC / pipes / when to close??
      Hi, I'm writing a C program that needs to bi-directionally communicate with with a forked/execvp'd process. Here is a sample program that...
    5. Hanging pipes in CGI Perl
      Christophe Baegert wrote: .... h--^ *please* copy/paste working code, don't just type it in!!!
  3. #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 parsed 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

  4. #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 parsed 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

  5. #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 parsed 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

Posting Permissions

  • You may not post new threads
  • You may 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