Hi,
  This is my first perl program..I'm getting wired errors.Please take a
look.


#!persist/pkg/bin/perl
use diagnostics;
use warnings;

open(MYINPUTFILE ,"/net/fallsroot/export/d100/m4/input_file");
open(MYOUTFILE, "> output_file");

foreach $line (<MYINPUTFILE>){

    chomp($line);                    # remove the newline from $line.
                                     # do line-by-line processing.
    my @column1 = split("/\\/",$line);
    print MYOUTFILE $column1[5] ,"\t" ;
    my @column2 = split("=",$line);
    print MYOUTFILE $column2[1]  ,"\n" ;

    }

close(MYOUTFILE);
Regards,
Shanmugam





On Wed, Mar 7, 2012 at 10:58 AM, Rob Dixon <rob.di...@gmx.com> wrote:

> On 07/03/2012 16:18, mailing lists wrote:
>
>> Hello,
>>
>> is there any way to extract the queued ID (7BC5A446) from the first
>> line and also match the second with only one regex??
>>
>>
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>> use 5.010;
>>
>> while(<DATA>){
>>     if (/^(?<Month>\S+?)\s+?(?<Day>\**S+?)\s+?(?<Time>\S+?)\s+?(?<**
>> Host>\S+?)\s+?(?<Program>\S+?)**:\s+?(?<QueueNumber>\S+?):\s+?**
>> to=(?<To>\S+?),\s+?relay=(?<**relay>\S+?),\s+?delay=(?<**
>> delay>\S+?),\s+?delays=(?<**delays>\S+?),\s+?dsn=(?<dsn>\**
>> S+?),\s+?status=(?<status>\S+?**)\s+?(?<statusMsg>(?:queued as
>> (?<NextQueueID>.*))?.*)$/i) {
>>         my $nextQueueID = $+{NextQueueID} || "None";
>>         say "LineType: \"To\" 1: $+{Month} 2: $+{Day} 3: $+{Time} 4:
>> $+{Host} 5: $+{Program} 6: $+{QueueNumber} 7: $+{To} 8: $+{relay} 9:
>> $+{delay} 10: $+{delays} 11: $+{dsn} 12: $+{status} 13: $+{statusMsg} 14:
>> $nextQueueID";
>>     } else {
>>         say "ERROR with line: ".$_
>>     }
>> }
>>
>> __DATA__
>> Mar  5 10:05:45 antispam3 postfix/smtp[1595]: 4CE0081: to=<
>> user...@example.com>, relay=clamav.example.com[1.1.**1.1]:25,
>> delay=0.31, delays=0.14/0/0.01/0.16, dsn=2.0.0, status=sent (250 2.0.0 Ok:
>> queued as 7BC5A446)
>> Mar  5 10:06:37 antivir1 postfix/smtp[8193]: 7BC5A446: to=<
>> user...@example.com>, relay=mail.example.com[2.2.2.**2]:25, delay=52,
>> delays=0.15/50/0.03/2.1, dsn=2.5.0, status=sent (250 2.5.0 Ok.)
>>
>
> What do you mean by "and also match the second"? This looks very much as
> if you should be using split rather than a regex. There is certainly no
> point in all the non-greedy matching - /\s+/ and /\S+/ will do fine.
>
> Rob
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to