N
Niall Macpherson
I need to read a line which contains a [ and a ] and then capture the
data between these symbols. I then need to split the captured data
using the open parenthesis as the separator.
The following code does exactly what I want
use strict;
use warnings;
while(<DATA>)
{
if(/.*\[(.*)\]/)
{
my $second_bit = $1;
while ( $second_bit =~ /
\( # match open paren
([^\(]*) # match anything up to next opening paren
/gx )
{
print $1, "\n";
}
}
else
{
print "\n", 'No match';
}
}
__END__
(lose this stuff[(process(this(stuff(bit(by(bit]
And produces the following output
H:\Perl Scripts>splitnoarray.pl
process
this
stuff
bit
by
bit
H:\Perl Scripts>
Which is fine for a short line of input.
However the real data is very large - each line may be up to 1Gb and
the memory usage and performance is terrible.
I had a look at getting rid of the '$second_bit' variable to avoid
doing a very large assignment but if I use $1 directly in the while
loop I get the following
H:\Perl Scripts>splitnoarray.pl
process
H:\Perl Scripts>
Can anyone suggest a better way of doing this which would minimise the
memory usage ?
Thanks in advance
Niall
data between these symbols. I then need to split the captured data
using the open parenthesis as the separator.
The following code does exactly what I want
use strict;
use warnings;
while(<DATA>)
{
if(/.*\[(.*)\]/)
{
my $second_bit = $1;
while ( $second_bit =~ /
\( # match open paren
([^\(]*) # match anything up to next opening paren
/gx )
{
print $1, "\n";
}
}
else
{
print "\n", 'No match';
}
}
__END__
(lose this stuff[(process(this(stuff(bit(by(bit]
And produces the following output
H:\Perl Scripts>splitnoarray.pl
process
this
stuff
bit
by
bit
H:\Perl Scripts>
Which is fine for a short line of input.
However the real data is very large - each line may be up to 1Gb and
the memory usage and performance is terrible.
I had a look at getting rid of the '$second_bit' variable to avoid
doing a very large assignment but if I use $1 directly in the while
loop I get the following
H:\Perl Scripts>splitnoarray.pl
process
H:\Perl Scripts>
Can anyone suggest a better way of doing this which would minimise the
memory usage ?
Thanks in advance
Niall