--wmhq21yAGFMoSpeN
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

* Jim Bob (invalid / invalid.com) wrote:
> I'm hoping someone can jog my memory here. Say I've got a file which
> contains the keywords "START" and "END", with several lines in between.
> Suppose I want to operate on everything between START and END (inclusive
> or not, doesn't really matter, I don't think).
>=20
> Naively, I would do one of a couple things: either use a multiline
> regexp, or read the file until START is encountered, and set some sort
> of "readthis" flag which signals the program to operate on the lines
> until END is encountered, at which point the flag is unset.

Why not something like this?

parsing =3D false
File::open('path/to/file').readlines.each { |line|
  next unless parsing || parsing =3D (line =3D~ /^START$/)
  break if line =3D~ /^END$/
 =20
  # handle parsing
  # ...
}

It doesn't use a range, but it's relatively concise.

> *However*.... I'm pretty sure that, somewhere, sometime, I saw some much
> more elegant way of doing this in ruby. I said "neat!", and promptly
> forgot about it. Something involving ranges, maybe? Anybody have an idea
> what I might have been thinking of, or am I misremembering?
>=20
> Any help would be much appreciated. This is a great newsgroup and
> mailing list; I only wish I had time to read it all.

--=20
Paul Duncan <pabs / pablotron.org>        pabs in #gah (OPN IRC)
http://www.pablotron.org/               OpenPGP Key ID: 0x82C29562

--wmhq21yAGFMoSpeN
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+97W8zdlT34LClWIRAnbeAKDTUIjBapuHhd1fXZlg7DE7pxwyngCdGFNm
bJtUi2Jb3vqbDo6HzRca+ZU=
=fYPA
-----END PGP SIGNATURE-----

--wmhq21yAGFMoSpeN--

* Jim Bob (invalid / invalid.com) wrote:
> I'm hoping someone can jog my memory here. Say I've got a file which
> contains the keywords "START" and "END", with several lines in between.
> Suppose I want to operate on everything between START and END (inclusive
> or not, doesn't really matter, I don't think).
>=20
> Naively, I would do one of a couple things: either use a multiline
> regexp, or read the file until START is encountered, and set some sort
> of "readthis" flag which signals the program to operate on the lines
> until END is encountered, at which point the flag is unset.

Why not something like this?

parsing =3D false
File::open('path/to/file').readlines.each { |line|
  next unless parsing || parsing =3D (line =3D~ /^START$/)
  break if line =3D~ /^END$/
 =20
  # handle parsing
  # ...
}

It doesn't use a range, but it's relatively concise.

> *However*.... I'm pretty sure that, somewhere, sometime, I saw some much
> more elegant way of doing this in ruby. I said "neat!", and promptly
> forgot about it. Something involving ranges, maybe? Anybody have an idea
> what I might have been thinking of, or am I misremembering?
>=20
> Any help would be much appreciated. This is a great newsgroup and
> mailing list; I only wish I had time to read it all.

--=20
Paul Duncan <pabs / pablotron.org>        pabs in #gah (OPN IRC)
http://www.pablotron.org/               OpenPGP Key ID: 0x82C29562
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+97W8zdlT34LClWIRAnbeAKDTUIjBapuHhd1fXZlg7DE7pxwyngCdGFNm
bJtUi2Jb3vqbDo6HzRca+ZU=
=fYPA
-----END PGP SIGNATURE-----