Hi Monks, I'm new in Perl, I mean very limited know-how in Perl as of now. I hope you can help me with my problem formatting my multiple line data below:

Arrival Time: May 2, 2013 10:37:50.813000000

From: <sip:639gwhuaping01-14@119.38.228.43>;tag=70c8b229-1c

To: <sip:639gwhuaping01-14@119.38.228.43>

Arrival Time: May 2, 2013 10:38:05.274000000

From: <sip:639gwhuaping01-01@119.38.228.43>;tag=70c8b229-2

To: <sip:639gwhuaping01-01@119.38.228.43>

Arrival Time: May 2, 2013 10:38:05.451000000

From: <sip:639gwhuaping01-11@119.38.228.43>;tag=70c8b229-16

To: <sip:639gwhuaping01-11@119.38.228.43>

User-Agent: Quintum/1.0.0 SN/0030E130409A SW/P108-09-10

to this

Arrival Time|From|To|User-Agent

May 2, 2013 10:37:50.813000000|<sip:639gwhuaping01-14@119.38.228.43>;tag=70c8b229-1c|<sip:639gwhuaping01-14@119.38.228.43>|--

May 2, 2013 10:38:05.274000000|<sip:639gwhuaping01-01@119.38.228.43>;tag=70c8b229-2|<sip:639gwhuaping01-01@119.38.228.43>|--

May 2, 2013 10:38:05.451000000|<sip:639gwhuaping01-11@119.38.228.43>;tag=70c8b229-16|<sip:639gwhuaping01-11@119.38.228.43>|Quintum/1.0.0 SN/0030E130409A SW/P108-09-10

my code:
use strict; my $infile = $ARGV[0]; my $outfile = $ARGV[1]; open my $in, "<", $infile or die $!; open my $out, ">", $outfile or die $!; print $out "Arrival Time|From|To|User-Agent\n"; my $line; while ( <$in> ) { s/ //; s/ //; s/ Malay Peninsula Standard Time//; s/From:/\|From:/; s/To:/\|To:/; s/User-Agent:/\|User-Agent:/; $line .= $_ if ($_ =~ m/Arrival Time:|\|From:|\|To:|\|User-Agent:/); chomp $line if /^Arrival Time:|\|From:/; if ($line =~ m/User-Agent:/) { $line =~ s/^\n//; } $line =~ s/Arrival Time: //; $line =~ s/From: //; $line =~ s/To: //; $line =~ s/User-Agent: //; if (eof){chomp $line} } print $out $line; close $in; close $out;

It's a sequence of lines beginning with "Arrival Time", "From:", "To:" and sometimes but not always "User-Agent". In such cases, I need to substitute "--"

I'm using 5.18 for windows.

Your response is very much appreciated.

Thank you in advance

r2ro

In reply to Arranging multiple lines by r2ro

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.