in reply to Simple parse of file - getting started

Sounds like homework to me. Anyway, here's a program (reading from DATA) that will do what you want. Requires 5.8.1 with the defined-or patch.
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { last if /AGF30/; } exit unless defined; unless (/%/) { while (<DATA>) { last if /%/; } } exit unless defined; my $ir_value = substr $_ => -10; for my $c (1 .. 2) { no warnings 'misc'; $_ = <DATA> err exit; } my $ysp_value = substr $_ => -10; print "\$ir_value = $ir_value"; print "\$ysp_value = $ysp_value"; __DATA__ one line two line three line bla AGF30 foor four line feeble % 0123456789 one more two more ABCDEFGHIJ end

Running this gives:

$ir_value = 123456789 $ysp_value = BCDEFGHIJ
(That's 10 characters, including the newline).

Abigail

Replies are listed 'Best First'.
Re: Re: Simple parse of file - getting started
by RickF71 (Initiate) on Sep 30, 2003 at 18:36 UTC
    Abigail, thank you SO much. I'm a Perl newb, but experienced programmer of Java, VB (ugh), C and a hack at half a dozen other languages. I have received a number of projects where I need to do a lot of text parsing of data files and figured maybe it's time to learn some Perl. Thanks again for your help. Rick