[31344] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2589 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 8 14:09:45 2009

Date: Tue, 8 Sep 2009 11:09:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 8 Sep 2009     Volume: 11 Number: 2589

Today's topics:
        add a 3 lines of text in a file before "package" in fil <mikaelpetterson@hotmail.com>
    Re: add a 3 lines of text in a file before "package" in <ben@morrow.me.uk>
        FAQ 4.4 Does Perl have a round() function?  What about  <brian@theperlreview.com>
        In which memory area does Perl variables get store. <yaswanth.14@gmail.com>
    Re: IPC::Open2::open2() -- How to pass strings stdin, s <jerrykrinock@gmail.com>
    Re: IPC::Open2::open2() -- How to pass strings stdin, s <ben@morrow.me.uk>
    Re: IPC::Open2::open2() -- How to pass strings stdin, s <jerrykrinock@gmail.com>
        Need expert help matching a line <ramon@conexus.net>
    Re: Need expert help matching a line <ramon@conexus.net>
    Re: Need expert help matching a line <spamtrap@piven.net>
    Re: Need expert help matching a line <concordate@gmail.com>
    Re: Need expert help matching a line <cwilbur@chromatico.net>
    Re: Need expert help matching a line <cartercc@gmail.com>
    Re: Need expert help matching a line sln@netherlands.com
    Re: Need expert help matching a line sln@netherlands.com
        Perl regex expression to return values <ipellew@yahoo.com>
        XML::Parser <user@example.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 8 Sep 2009 05:09:04 -0700 (PDT)
From: mike <mikaelpetterson@hotmail.com>
Subject: add a 3 lines of text in a file before "package" in file
Message-Id: <3f131ea1-1992-40bb-b267-c5c621031234@y36g2000yqh.googlegroups.com>

Hi,

I am using perl and need to add some text lines before the word
"package" in the file. I have read about Tie::File
and I am trying to use it as below. But I am unable to see how I can
match the word "package" and add
/* ---- Insert text here ---- */
 on  the line before "package".

Any ideas?

//mike

sub modify {
	my @line_array;
	my $line;
	my ($file) = @_;
	print "Modifying file, $file\n";
	tie @line_array, 'Tie::File', $file or die "Can not tie file:$!";
	for $line(@line_array) {
	//
	}
	untie @line_array;

}


------------------------------

Date: Tue, 8 Sep 2009 15:42:40 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: add a 3 lines of text in a file before "package" in file
Message-Id: <047in6-0bj1.ln1@osiris.mauzo.dyndns.org>


Quoth mike <mikaelpetterson@hotmail.com>:
> 
> I am using perl and need to add some text lines before the word
> "package" in the file. I have read about Tie::File
> and I am trying to use it as below. But I am unable to see how I can
> match the word "package" and add
> /* ---- Insert text here ---- */
>  on  the line before "package".
> 
> Any ideas?

Is the file likely to be large (which probably means several hundred MB,
nowadays)? If not, it would be easier to use File::Slurp and do a simple
s/// on the whole file before writing it out again.

Otherwise, you want to start with

    my $ix = 0;

    for (my $ix = 0;
         defined( my $line = $line_array[$ix] );
         $ix++
    ) {
        $line =~ /package/ or next;
        splice @line_array, $ix - 1, 0, @new_lines;
        last;   # if you only want to edit the first occurence
    }

(I would normally have written that

    for my $ix (0..$#linearray) {

but that would require reading the entire file to count the lines. TBH,
I'm not sure Tie::File helps you much here.)

Ben



------------------------------

Date: Tue, 08 Sep 2009 16:00:03 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 4.4 Does Perl have a round() function?  What about ceil() and floor()?  Trig functions?
Message-Id: <7cvpm.144651$sC1.140149@newsfe17.iad>

This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to 
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

--------------------------------------------------------------------

4.4: Does Perl have a round() function?  What about ceil() and floor()?  Trig functions?

    Remember that "int()" merely truncates toward 0. For rounding to a
    certain number of digits, "sprintf()" or "printf()" is usually the
    easiest route.

            printf("%.3f", 3.1415926535);   # prints 3.142

    The "POSIX" module (part of the standard Perl distribution) implements
    "ceil()", "floor()", and a number of other mathematical and
    trigonometric functions.

            use POSIX;
            $ceil   = ceil(3.5);   # 4
            $floor  = floor(3.5);  # 3

    In 5.000 to 5.003 perls, trigonometry was done in the "Math::Complex"
    module. With 5.004, the "Math::Trig" module (part of the standard Perl
    distribution) implements the trigonometric functions. Internally it uses
    the "Math::Complex" module and some functions can break out from the
    real axis into the complex plane, for example the inverse sine of 2.

    Rounding in financial applications can have serious implications, and
    the rounding method used should be specified precisely. In these cases,
    it probably pays not to trust whichever system rounding is being used by
    Perl, but to instead implement the rounding function you need yourself.

    To see why, notice how you'll still have an issue on half-way-point
    alternation:

            for ($i = 0; $i < 1.01; $i += 0.05) { printf "%.1f ",$i}

            0.0 0.1 0.1 0.2 0.2 0.2 0.3 0.3 0.4 0.4 0.5 0.5 0.6 0.7 0.7
            0.8 0.8 0.9 0.9 1.0 1.0

    Don't blame Perl. It's the same as in C. IEEE says we have to do this.
    Perl numbers whose absolute values are integers under 2**31 (on 32 bit
    machines) will work pretty much like mathematical integers. Other
    numbers are not guaranteed.



--------------------------------------------------------------------

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in 
perlfaq.pod.


------------------------------

Date: Tue, 8 Sep 2009 04:08:32 -0700 (PDT)
From: Yash <yaswanth.14@gmail.com>
Subject: In which memory area does Perl variables get store.
Message-Id: <f09be681-b753-42f1-84a4-b662d17f5782@f20g2000prn.googlegroups.com>

I would like to know in which memory area all the perl variables
( scalars, arrays, hashes) will get store.

Can any one explain me in breif how Perl stores the data.


------------------------------

Date: Tue, 8 Sep 2009 05:04:28 -0700 (PDT)
From: Jerry Krinock <jerrykrinock@gmail.com>
Subject: Re: IPC::Open2::open2() -- How to pass strings stdin, stdout?
Message-Id: <190a3f9d-ca0c-4bf7-91aa-e71ad0881155@v15g2000prn.googlegroups.com>

First, I tried Uri's code, but it has the same problem as mine.  That
is, it waits forever, on the line
       my $out = <$chld_out> ;

Apparently my first problem was believing that something so simple
could be so hard.  Having crossed that hurdle, as Uri suggested, I re-
read the section on open2() in perldoc perlipc.

Indeed, the single example that they give in there works, but, as
explained there, only because the 'cat' command they invoke is one of
the few which supports a 'unbuffered' or '-u' parameter.  In that
example, if I change
    $pid = open2(*Reader, *Writer, "cat -u -n" );
to simply
    $pid = open2(*Reader, *Writer, "cat -n" );
then, again, it waits forever, on $got = <Reader>;.  Arghhhh.

So, reading down further, I see that they recommend using the 'Expect'
module.  Fortunately, 'Expect' and all of its prerequisites seem to
already be on my system for some reason.  So, I try this code:

#!/usr/bin/perl

use Expect ;

my $stdin = "*Hello* **World**\n" ;
my $cmd = '/Users/jk/Downloads/Markdown_1.0.1/Markdown.pl';
my @parameters = () ;  # No arguments to Markdown.pl

my $exp = new Expect;
$exp->raw_pty(1);
$exp->spawn($cmd, @parameters)
or die "Cannot spawn $command: $!\n";
$exp->send($stdin);
print "Waiting for output.\n" ;
my $stdout = $exp->expect(undef);
print "stdout: $stdout\n" ;

Result: Still the same problem -- "Waiting for output" -- forever.  If
I give the expect() function a timeout parameter, then it times out
after the given time, but no returns no data.

Does anyone know how to use the Expect module in the simple case of
spawning a command with stdin to get stdout? The following quote from
Expect documentation  poo-poos this usage:
   Question: "I just want to read the output of a process without
              expect()ing anything. How can I do this?"
   Answer: "[ Are you sure you need Expect for this? How about qx() or
open("prog|")? ]

My answer: Yes, I've already been there!

Had I known this was going to be so hard, I would have written my
input to a temporary file instead.  I know that Markdown.pl can read
from a file.  Is that the only way to do this?




------------------------------

Date: Tue, 8 Sep 2009 15:31:57 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: IPC::Open2::open2() -- How to pass strings stdin, stdout?
Message-Id: <tf6in6-0bj1.ln1@osiris.mauzo.dyndns.org>


Quoth Jerry Krinock <jerrykrinock@gmail.com>:
> First, I tried Uri's code, but it has the same problem as mine.  That
> is, it waits forever, on the line
>        my $out = <$chld_out> ;
> 
> Apparently my first problem was believing that something so simple
> could be so hard.  Having crossed that hurdle, as Uri suggested, I re-
> read the section on open2() in perldoc perlipc.
> 
> Indeed, the single example that they give in there works, but, as
> explained there, only because the 'cat' command they invoke is one of
> the few which supports a 'unbuffered' or '-u' parameter.  In that
> example, if I change
>     $pid = open2(*Reader, *Writer, "cat -u -n" );
> to simply
>     $pid = open2(*Reader, *Writer, "cat -n" );
> then, again, it waits forever, on $got = <Reader>;.  Arghhhh.

Have you tried IPC::Run? It will let you pass a string for input and
return an output string, and deal with running a select loop and
closeing the input pipe and so on for you.

> So, reading down further, I see that they recommend using the 'Expect'
> module.  Fortunately, 'Expect' and all of its prerequisites seem to
> already be on my system for some reason.  So, I try this code:
> 
> #!/usr/bin/perl
> 
> use Expect ;
> 
> my $stdin = "*Hello* **World**\n" ;
> my $cmd = '/Users/jk/Downloads/Markdown_1.0.1/Markdown.pl';
> my @parameters = () ;  # No arguments to Markdown.pl
> 
> my $exp = new Expect;
> $exp->raw_pty(1);
> $exp->spawn($cmd, @parameters)
> or die "Cannot spawn $command: $!\n";
> $exp->send($stdin);
> print "Waiting for output.\n" ;
> my $stdout = $exp->expect(undef);
> print "stdout: $stdout\n" ;
> 
> Result: Still the same problem -- "Waiting for output" -- forever.  If
> I give the expect() function a timeout parameter, then it times out
> after the given time, but no returns no data.

Almost certainly what is happening here is that Markdown has read all
the data you've written, written the results into its output buffer, and
is sat there waiting for more input. The way to get it to exit and flush
its output buffer is to close the writing filehandle. (It looks like
Markdown doesn't put its filehandles into line-buffered mode when it's
writing to a tty; either that, or that output from that input doesn't
include a newline.)

For this simple example, Expect isn't helping you. You could make it
work simply by closing *Writer after writing the data. However, this is
only because the data you are writing is less than one pipe-buffer-ful.
If you had more data to write than that, you would need a proper select
loop, with nonblocking filehandles. This is what IPC::Run will do for
you.

> Had I known this was going to be so hard, I would have written my
> input to a temporary file instead.  I know that Markdown.pl can read
> from a file.  Is that the only way to do this?

No, but if you don't need true interaction (that is, if you know what
input you're going to send before you start) then it's often easier.
It's also likely to be *much* more portable to non-Unix systems, if
that's a concern.

Ben



------------------------------

Date: Tue, 8 Sep 2009 09:58:08 -0700 (PDT)
From: Jerry Krinock <jerrykrinock@gmail.com>
Subject: Re: IPC::Open2::open2() -- How to pass strings stdin, stdout?
Message-Id: <2d70181f-50a3-483b-9688-09785d1c3ed0@v37g2000prg.googlegroups.com>

On Sep 8, 7:31=A0am, Ben Morrow <b...@morrow.me.uk> wrote:

> ...if you don't need true interaction (that is, if you know what
> input you're going to send before you start) then it's often easier.
> It's also likely to be *much* more portable to non-Unix systems, if
> that's a concern.

Thank you, Ben.  That's what I'm doing now -- writing my stdin to a
temporary file and getting stdout using backticks.  Works great.
Here's a little function to help archive readers get started...

=3Dcom
Execute a given external program (command).  The program must
take input from a file specified as the last parameter on
its command line.  This function takes input you provide and passes
it to the program in a temporary file.  The program's stdout is
returned.

Provide the command, with any command-line options, as the
first parameter, and the input data as the second parameter.

Use this in lieu of open2() and the methods of Expect.pm, both
of which will hang indefinitely unless the program supports
unbuffered I/O, typically a -u option.
=3Dcut
sub getStdoutWithInputFromCmd {
	my $cmd =3D shift ;
	my $stdin =3D shift ;

	# Write stdin to temp file
	my $tempFilePath =3D File::Temp->tmpnam() ;
	my $didWriteOK =3D open (TEMP,">$tempFilePath") ;
	print TEMP $stdin ;
	close (TEMP) ;

	# Execute command
	my $stdout =3D `$cmd \"$tempFilePath\"` ;

	# Clean up temporary file
	unlink($tempFilePath) ;

	return $stdout ;
}



------------------------------

Date: Tue, 8 Sep 2009 05:23:32 -0700 (PDT)
From: Ramon F Herrera <ramon@conexus.net>
Subject: Need expert help matching a line
Message-Id: <50e784f2-5d52-4861-9e32-ba9d60a5cd73@o9g2000yqj.googlegroups.com>


This is really a parsing question, but I figure that nobody knows more
about regex and pattern matching than Perl programmers.

I have many files which contain multiple lines of variable-value pair
assignments. I need to break down each lines into its 3 constituent
components.

Variable Name = Variable Value

IOW, each line contains 3 parts:

VariableName
Equal Sign
VariableValue

As opposed to the variable names used by many programming languages,
my variable names accept embedded space.

Here's some examples of the lines I am trying to match:

My Favorite Baseball Player = George Herman "Babe" Ruth
What did your do on Christmas = I rested, computed the % mortgage and
visited my brother + sister.
Favorite Curse = That umpire is a #&*%!

What I need is a way to specify valid characters.

VariableName: Alphanumeric (and perhaps underscore), blank space.
VariableValue: Pretty much anything is valid on the RHS except an '='
sign (I guess)

Thanks for your kind assistance.

-Ramon



------------------------------

Date: Tue, 8 Sep 2009 06:02:11 -0700 (PDT)
From: Ramon F Herrera <ramon@conexus.net>
Subject: Re: Need expert help matching a line
Message-Id: <9ba1bd6b-2fe4-40bb-989b-8df2cd9c5aa6@h13g2000yqk.googlegroups.com>

On Sep 8, 8:23=A0am, Ramon F Herrera <ra...@conexus.net> wrote:
> This is really a parsing question, but I figure that nobody knows more
> about regex and pattern matching than Perl programmers.
>
> I have many files which contain multiple lines of variable-value pair
> assignments. I need to break down each lines into its 3 constituent
> components.
>
> Variable Name =3D Variable Value
>
> IOW, each line contains 3 parts:
>
> VariableName
> Equal Sign
> VariableValue
>
> As opposed to the variable names used by many programming languages,
> my variable names accept embedded space.
>
> Here's some examples of the lines I am trying to match:
>
> My Favorite Baseball Player =3D George Herman "Babe" Ruth
> What did your do on Christmas =3D I rested, computed the % mortgage and
> visited my brother + sister.
> Favorite Curse =3D That umpire is a #&*%!
>
> What I need is a way to specify valid characters.
>
> VariableName: Alphanumeric (and perhaps underscore), blank space.
> VariableValue: Pretty much anything is valid on the RHS except an '=3D'
> sign (I guess)
>
> Thanks for your kind assistance.
>
> -Ramon

Just to make the exercise a little harder -and fun- the assignment
syntax should be able to support continuation lines, where the RHS is
very long:

Describe your summer vacation =3D Well, we traveled to the beach
  and to the mountains, and debated whether we
  should go to the Grand Canyon and Niagara falls.
  The GPS you gave me turned out to be very useful!

A continuation line always starts with blank space.

TIA,

-Ramon



------------------------------

Date: Tue, 08 Sep 2009 08:28:15 -0500
From: Don Piven <spamtrap@piven.net>
Subject: Re: Need expert help matching a line
Message-Id: <qMWdnRqMUM1yxjvXnZ2dnUVZ_vidnZ2d@speakeasy.net>

Ramon F Herrera wrote:
> This is really a parsing question, but I figure that nobody knows more
> about regex and pattern matching than Perl programmers.

perlre (the manpage for Perl regular expressions) is your friend. 
Seriously.  It will answer all the questions you raised.


------------------------------

Date: Tue, 8 Sep 2009 08:02:18 -0700 (PDT)
From: Lucius Sanctimonious <concordate@gmail.com>
Subject: Re: Need expert help matching a line
Message-Id: <ea98101a-9769-4e90-ab59-32f1289335b8@o41g2000yqb.googlegroups.com>

On Sep 8, 9:28=A0am, Don Piven <spamt...@piven.net> wrote:
> Ramon F Herrera wrote:
> > This is really a parsing question, but I figure that nobody knows more
> > about regex and pattern matching than Perl programmers.
>
> perlre (the manpage for Perl regular expressions) is your friend.
> Seriously. =A0It will answer all the questions you raised.


Thanks Don, seriously.

You are essentially telling me to RTFM. I have already RTFM.

The question remains open...

Thx,

-Ramon



------------------------------

Date: Tue, 08 Sep 2009 12:20:17 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Need expert help matching a line
Message-Id: <86y6opjtmm.fsf@mithril.chromatico.net>

>>>>> "LS" == Lucius Sanctimonious <concordate@gmail.com> writes:

    LS> You are essentially telling me to RTFM. I have already RTFM.

Your question shows no evidence of this.

    LS> The question remains open...

Post what you've already tried, and let us know what you're having
problems with.

Also, review the posting guidelines that are posted here frequently, or
online at http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html --
they're a summary of what works best if you really want to get help,
instead of just wanting to stir up drama.

Charlton



-- 
Charlton Wilbur
cwilbur@chromatico.net


------------------------------

Date: Tue, 8 Sep 2009 09:58:56 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Need expert help matching a line
Message-Id: <f36b4534-58a5-4c01-8bec-b2d2f7a6df05@x37g2000yqj.googlegroups.com>

CODE:
use strict;
use warnings;

my ($var, $val);
my %variables;
while (<DATA>)
{
	chomp;
	if (/=/) { ($var, $val) = split /=/; }
	elsif (/^ +\w+/) { $val .= $_; }
	else { next; }
	$var =~ s/^\s+//;
	$var =~ s/\s+$//;
	$variables{$var} = $val;
}

foreach my $key (keys %variables) { print "$key => $variables{$key}
\n"; }
exit(0);

__DATA__
My Favorite Baseball Player = George Herman "Babe" Ruth
What did your do on Christmas = I rested, computed the % mortgage and
visited my brother + sister.
Describe your summer vacation = Well, we traveled to the beach
  and to the mountains, and debated whether we
  should go to the Grand Canyon and Niagara falls.
  The GPS you gave me turned out to be very useful!
Favorite Curse = That umpire is a #&*%!

OUTPUT:
My Favorite Baseball Player =>  George Herman "Babe" Ruth
Describe your summer vacation =>  Well, we traveled to the beach  and
to the mountains, and debated whether we  should go to the Grand
Canyon and Niagara falls.  The GPS you gave me turned out to be very
useful!
Favorite Curse =>  That umpire is a #&*%!
What did your do on Christmas =>  I rested, computed the % mortgage
and visited my brother + sister.


------------------------------

Date: Tue, 08 Sep 2009 10:34:51 -0700
From: sln@netherlands.com
Subject: Re: Need expert help matching a line
Message-Id: <125da59nv5vh1ni7jhveeu9m6slal415u9@4ax.com>

On Tue, 8 Sep 2009 09:58:56 -0700 (PDT), ccc31807 <cartercc@gmail.com> wrote:

>CODE:
>use strict;
>use warnings;
>
>my ($var, $val);
                = ('','');
>my %variables;
>while (<DATA>)
>{
>	chomp;
>	if (/=/) { ($var, $val) = split /=/; }
>	elsif (/^ +\w+/) { $val .= $_; }
>	else { next; }
>	$var =~ s/^\s+//;
>	$var =~ s/\s+$//;
>	$variables{$var} = $val;
>}
>
>foreach my $key (keys %variables) { print "$key => $variables{$key}
>\n"; }
>exit(0);
>
Looks good. I like the way you did this.
Might need initial condition check
 elsif (/^ +\w+/ and length($var)) { $val .= $_; }

-sln


------------------------------

Date: Tue, 08 Sep 2009 10:35:57 -0700
From: sln@netherlands.com
Subject: Re: Need expert help matching a line
Message-Id: <1e5da5ptvd15ma3c0gnvg85q3npq6bsdr1@4ax.com>

On Tue, 8 Sep 2009 05:23:32 -0700 (PDT), Ramon F Herrera <ramon@conexus.net> wrote:

>
>This is really a parsing question, but I figure that nobody knows more
>about regex and pattern matching than Perl programmers.
>
>I have many files which contain multiple lines of variable-value pair
>assignments. I need to break down each lines into its 3 constituent
>components.
>
>Variable Name = Variable Value
>
>IOW, each line contains 3 parts:
>
>VariableName
>Equal Sign
>VariableValue
>
>As opposed to the variable names used by many programming languages,
>my variable names accept embedded space.
>
>Here's some examples of the lines I am trying to match:
>
>My Favorite Baseball Player = George Herman "Babe" Ruth
>What did your do on Christmas = I rested, computed the % mortgage and
>visited my brother + sister.
>Favorite Curse = That umpire is a #&*%!
>
>What I need is a way to specify valid characters.
>
>VariableName: Alphanumeric (and perhaps underscore), blank space.
>VariableValue: Pretty much anything is valid on the RHS except an '='
>sign (I guess)
>
>Thanks for your kind assistance.
>
>-Ramon

-sln

use strict;
use warnings;

my $buf  = '';

while (<DATA>)
{
	if (/=/ or eof)	{
		if ($buf =~ /\s*([\w ]+)\s*=\s*((?:.+(?:\n .+)*)|)/)
		{
			my ($var,$val) = ($1,$2);
			$val =~ s/\n +/\n/g;
			print "$var => $val\n\n";
		}
		$buf = '';
	}
	$buf .= $_;	
}
__DATA__

My Favorite Baseball Player = George Herman =  "Babe" Ruth
What did your do on Christmas = I rested, computed the % mortgage and
 visited my brother + sister.
 asdfasdf=
Favorite Curse = That umpire is a #&*%!
errnngsf
sngdnsdg
Describe your summer vacation = Well, we traveled to the beach
  and to the mountains, and debated whether we
  should go to the Grand Canyon and Niagara falls.
  The GPS you gave me turned out to be very useful!



------------------------------

Date: Tue, 8 Sep 2009 10:04:34 -0700 (PDT)
From: ian <ipellew@yahoo.com>
Subject: Perl regex expression to return values
Message-Id: <75f22455-7522-4a90-bb4f-46204469c92c@t2g2000yqn.googlegroups.com>

Cut un paste and you will see the problem
Code comment shows what I can't do !!
NOTE! DATA is 2 (TWO) lines only.

#!/usr/bin/perl
my $n = "\n";
while ( <DATA> ) {
    chomp;
        my ( @bu ) = $_ =~ m{
                              .*
                              (\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d)
                              .\d*\s
                              ([\w]*)[\W]
                              (.*-\s*)
                              (Returning\sfrom|Entering)\s*       #
Should be able to get 1 or n words
                              ([\w._]+)
                                                    # Problem Area !!
                              (?:
                                  (\(.*\))
                                |
                                  (\(.*\))
                                  (,\s+[\w]+:\s+)
                                  (.*)
                              )
                            }x;
        my $c = 0;
        for my $q ( @bu ) {
            $c++;
            printf "%2s '%s'\n", $c, $q;
        }
    print $n;
    next;
}
print "-----------".$n;


#  RETURNS:-
#
# 1 '2009-09-01 15:58:51'
# 2 'INFO'
# 3 ' [ com.manager ]  - '
# 4 'Entering'
# 5 'get.Prod_Codes'
# 6 '( id:017661, date: Tue Sep 01 15:58:51 CEST 2009, instance:TEST)'
# 7 ''
# 8 ''
# 9 ''
#
# 1 '2009-09-01 15:58:51'
# 2 'INFO'
# 3 ' [ com.manager ]  - '
# 4 'Returning from'
# 5 'get.Prod_Codes'
# 6 '( id:017661, date: Tue Sep 01 15:58:51 CEST 2009, instance:TEST),
result: id:017661, productCodes: [GEAR | BOX | TARGET (2000)]
, Descn: [Mechan     | Type 1 (2000)'
# 7 ''
# 8 ''
# 9 ''
#
#-----------


# BUT WANT the return from to look like:-
# . . . . . .
# 6 '( id:017661, date: Tue Sep 01 15:58:51 CEST 2009, instance:TEST)
# 7 ', result: '
# 8 '(id:017661, productCodes: [GEAR | BOX | TARGET (2000)], Descn:
[Mechan  | HARDENED  | Type 1 (2010) ])'
#

__DATA__
Server.log:2009-09-01 15:58:51,513 INFO  [ com.manager ]  - Entering
get.Prod_Codes( id:017661, date: Tue Sep 01 15:58:51 CEST 2009,
 instance:TEST)
Server.log:2009-09-01 15:58:51,531 INFO  [ com.manager ]  - Returning
from get.Prod_Codes( id:017661, date: Tue Sep 01 15:58:51 CEST
 2009, instance:TEST), result: id:017661, productCodes: [GEAR | BOX |
TARGET (2000)], Descn: [Mechan  | HARDENED  | Type 1 (2010)  ]
)


------------------------------

Date: Tue, 08 Sep 2009 13:48:19 -0400
From: monkeys paw <user@example.net>
Subject: XML::Parser
Message-Id: <zsKdnZZq8cFCBTvXnZ2dnUVZ_q6dnZ2d@insightbb.com>

How can self ending elements be detected using
the parser?

Such as <br/> will fire both a start handler and
an end handler. I need to know that it differs from
a normal tag such as <start>text</start>.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2589
***************************************


home help back first fref pref prev next nref lref last post