join lines - perl command

Discussion in 'Perl Misc' started by julia, Sep 7, 2009.

  1. julia

    julia Guest

    What is the perl command to join lines ? I appreciate your help.

    linelineline\newline (line1)
    lineline\newline (line2)
    linelinelineline\newline (line3)
    &
    rowrowrow\newline (line1)
    rowrow\newline(line2)
    row\newline(line3)
    &
    whateverwhatever(line1)
    whateverwhatever(line2)
    whatever(line3)

    Result
    linelineline&rowrowrow&whateverwhatever\newline
    lineline&rowrow&whateverwhatever\newline
    linelinelineline&row&whatever\newline
     
    julia, Sep 7, 2009
    #1
    1. Advertising

  2. julia

    Nathan Keel Guest

    julia wrote:

    > What is the perl command to join lines ? I appreciate your help.
    >
    > linelineline\newline (line1)
    > lineline\newline (line2)
    > linelinelineline\newline (line3)
    > &
    > rowrowrow\newline (line1)
    > rowrow\newline(line2)
    > row\newline(line3)
    > &
    > whateverwhatever(line1)
    > whateverwhatever(line2)
    > whatever(line3)
    >
    > Result
    > linelineline&rowrowrow&whateverwhatever\newline
    > lineline&rowrow&whateverwhatever\newline
    > linelinelineline&row&whatever\newline


    How are you gathering the lines of data, from input on the command, via
    a form/web page, or reading from a file, or?
     
    Nathan Keel, Sep 7, 2009
    #2
    1. Advertising

  3. julia

    Guest

    On Mon, 7 Sep 2009 06:52:54 -0700 (PDT), julia <> wrote:

    >What is the perl command to join lines ? I appreciate your help.
    >
    >linelineline\newline (line1)
    >lineline\newline (line2)
    >linelinelineline\newline (line3)
    >&
    >rowrowrow\newline (line1)
    >rowrow\newline(line2)
    >row\newline(line3)
    >&
    >whateverwhatever(line1)
    >whateverwhatever(line2)
    >whatever(line3)
    >
    >Result
    >linelineline&rowrowrow&whateverwhatever\newline
    >lineline&rowrow&whateverwhatever\newline
    >linelinelineline&row&whatever\newline


    Indirect adressing will interleave.
    -sln

    use strict;
    use warnings;

    my @ar = [];
    my $i = 0;

    while (<DATA>) {
    chomp; next if !length();
    if (/^\s*&\s*$/) {
    $i = 0; next;
    }
    push @{$ar[$i]}, @{$ar[$i++]} ? '&'.$_ : $_;
    }
    for my $ar (@ar) {
    print @{$ar},"\n";
    }
     
    , Sep 7, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Silver
    Replies:
    0
    Views:
    889
    Alan Silver
    Jun 5, 2006
  2. googleboy
    Replies:
    1
    Views:
    929
    Benji York
    Oct 1, 2005
  3. Markus Dehmann
    Replies:
    1
    Views:
    136
    Tad McClellan
    Sep 26, 2006
  4. nickli

    Using Perl to join lines in a file

    nickli, Nov 7, 2006, in forum: Perl Misc
    Replies:
    3
    Views:
    90
    John Bokma
    Nov 8, 2006
  5. Replies:
    4
    Views:
    144
    Clenna Lumina
    Jul 12, 2007
Loading...

Share This Page