Terry,

You can grab each line and use pattern or substr operations.
eg:-

> positions 5-10, 50-100, and 280-300 in each line
replacing '## What would go here??' with:-

/.{4}(.{6}).{39}.({51}).{179}(.{21})/ && do {
  @fields = ($1,$2,$3);
};

to give $fields[0] = positions 5-10 ...

or with:-

$f1 = substr($_, 4, 6); # Substring - skip 4, grab 6
$f2 = substr($_, 49, 51);
$f3 = substr($_, 179, 21);

Either will work. I'm not sure which would give best performance, though.
Are you reading a file you have any control of ?
Are the lines always 300 characters ?

I'm not sure what you're trying to achieve, but if you're looking for the
second and third fields by matching on the first, then you could :-

/.{4}\Q$matchfield1\E.{39}.({51}).{179}(.{21})/ && do {
  @fields = ($1,$2);
};

This will give $fields[0] = second field ...

HTH
Tim

----- Original Message -----
From: "Terry Franklin" <[EMAIL PROTECTED]>
To: "'[EMAIL PROTECTED]'"
<[EMAIL PROTECTED]>
Sent: Tuesday, April 03, 2001 5:13 PM
Subject: reading portions of a line from a file


> All,
>
> I am in need of doing the following in a perl/tk app i am writing ... I
have
> very large text files, about 300 characters per line, and thousands of
lines
> long.
>
> I need to be able to assign variables to, for example, the characters in
> positions 5-10, 50-100, and 280-300 in each line
>
> There is no common delimiter to split each line.
>
> So how can I open a file and process each line in such a way?
>
> i.e.
>
> open(CURRENTFILE, "$source_directory/$file") or die "Cannot open $file:
$!";
>
> ## What would go here??
>
> close CURRENTFILE;
>
> Thx
> Terry
> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/activeperl
>

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to