Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > join lines - perl command

Reply
Thread Tools

join lines - perl command

 
 
julia
Guest
Posts: n/a
 
      09-07-2009
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
 
Reply With Quote
 
 
 
 
Nathan Keel
Guest
Posts: n/a
 
      09-07-2009
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?
 
Reply With Quote
 
 
 
 
sln@netherlands.com
Guest
Posts: n/a
 
      09-07-2009
On Mon, 7 Sep 2009 06:52:54 -0700 (PDT), julia <(E-Mail Removed)> 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";
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using xargs perl to join lines charissaf@gmail.com Perl Misc 4 07-12-2007 04:35 PM
Using Perl to join lines in a file nickli Perl Misc 3 11-08-2006 10:07 PM
perl -pe for blocks of lines instead of single lines Markus Dehmann Perl Misc 1 09-26-2006 07:28 PM
You must join New York Paid To Read !!!!!!! NewYork PTR is online!!! JOIN NOW!!!!!! Alan Silver ASP .Net 0 06-05-2006 03:27 PM
Pull out only first field of ps command ( in Perl ) PERL RUN COMMAND tweetiebirds@gmail.com Perl Misc 2 03-26-2005 06:03 AM



Advertisments