Date: Fri, 23 Jul 2004 11:02:28 -0500 From: "Carmichael, Lee" <Lee.Carmichael@savvis.net> To: "Steve Bertrand" <iaccounts@ibctech.ca>, <freebsd-questions@freebsd.org> Subject: RE: Perl split() question (OT)... Message-ID: <3B33FD3ADBD7054DB410CD9DA314133E02E73D2D@sl6exch4>
next in thread | raw e-mail | index | archive | help
Convert the /[/ to /\[/ and see if that works. Generally brackets mean a character class in perl regexs. You could also use single quotes. E.g. split('[', $line). Good luck, Lee > -----Original Message----- > From: Steve Bertrand [mailto:iaccounts@ibctech.ca] > Sent: Friday, July 23, 2004 10:32 AM > To: freebsd-questions@freebsd.org > Subject: Perl split() question (OT)... >=20 > Perl hackers -- Figured someone would have a reasonably quick, easy answer > for this: >=20 > I am trying to read through a file, line-by-line, and I want to extract > the text in between the [ and ] characters. I would normally half the line > by split() - ing the line first by [ as follows: >=20 > if ($logLine =3D~ /$struct$structStart/) { > @lineArray =3D split (/[/, $logLine); >=20 > and then further, half again later using the ]. However, Perl does not > like it when I search for [, as it thinks I am trying to use a regex. I > have tried to escape the pattern, to no avail. >=20 > Is there a 'special' escape for this, and more importantly, is there an > easier way to extract data from a line of a file without having to split > it up twice? >=20 > An example of the line I'm trying to get the contents out of is this: >=20 > | "LRED[Conversation started on 03 Feb 21:51:11] >=20 > and I need the data between [ ... ]. >=20 > I know it's OT, but hopefully someone can help me out. >=20 > Tks! >=20 > Steve >=20 > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions- > unsubscribe@freebsd.org"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B33FD3ADBD7054DB410CD9DA314133E02E73D2D>