in reply to Push the each group item into array

I've re-read your post a few times trying to make sure I was understanding the description of the problem. I may be way off in my interpretation, and if so, I'll apologize in advance.

It seems like you're saying that your records are separated by a > character. We get so used to thinking of files in terms of lines that it's easy to forget that the input record separator can be other values aside from '\n' or undef. Try setting it like this: local $/ = ">";

use strict; use warnings; use Data::Dumper; my $InputFile = "sample_log_file.txt"; my @all_metrics; open my $IN, '<', $InputFile or die $!; { local $/ = ">"; while( my $record = <$IN> ) { chomp; # Removes trailing '>' push @all_metrics, $record; } close $IN; } print Dumper @all_metrics;

I also noticed that your 'die' error message says something about not being able to open the file for writing. Everything else we've been discussing deals with opening for reading, not writing. So it might save you future headaches to fix the error message.


Dave

Replies are listed 'Best First'.
Re^2: Push the each group item into array
by senthil_v (Sexton) on Jun 07, 2011 at 07:04 UTC

    Great Thanks Davido. it works fine. and also i know about local $/;

      i learned local $/.