Ritu has asked for the wisdom of the Perl Monks concerning the following question:

Hi i dont no anything about PERL, only read a beginners online tutorial. There are output data files which some simulation runs are generating. I need a simple perl script to extract results from the files using perl script and use it to plot graphs in gnuplot. Can anybody please help me.

Replies are listed 'Best First'.
Re: pattern match in text file
by matija (Priest) on Apr 04, 2004 at 05:50 UTC
    You didn't tell us what the results that you need look like, so it's a bit hard for us to tell you how to match for them.

    In general, the script should look something like this:

    while (<ARGV>) { print if /some_regexp/; }
    Or, if you don't need the whole line, just parts of it,
    print "$1 $2 (..etc)\n" if /some regexp with captures/;
    To see how to construct the regular expressions, look at perldoc perlre.
Re: pattern match in text file
by neniro (Priest) on Apr 04, 2004 at 09:18 UTC
    Please give us some sample input data, and describe the expected output with an example, based on your input data.
    neniro
Re: pattern match in text file
by Happy-the-monk (Canon) on Apr 04, 2004 at 22:07 UTC

    Ritu says: Hi i dont no anything about PERL, only read a beginners online tutorial.

    You might want to continue reading this site's Tutorials to learn some more?

    There are output data files which some simulation runs are generating. I need a simple perl script to extract results from the files using perl script and use it to plot graphs in gnuplot. Can anybody please help me.

    my @output_data_files = qw( filename1 filename2 more_filenames... ); my $pattern = qr/result/; # a regular expression that will find "resul +t" my @results_found; # here goes everything that was found. foreach my $file ( @output_data_files ) { open ( FILE, "< $file" ) or die qq(could not open file "$file" for reading: $!); while ( <FILE> ) { # on every line of the file if ( my @matches = m/$pattern/g ) { # matches of the pattern push @results_found, @matches; # add them to @results_fou +nd } } close FILE; }

    Now you have got the results in the array   @results_found.
    Tell us how gnuplot expects the data and we might know how to proceed from here.

    Cheerio, Sören