From owner-freebsd-questions@FreeBSD.ORG Mon Jul 26 07:18:34 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8276816A4CE for ; Mon, 26 Jul 2004 07:18:34 +0000 (GMT) Received: from sthav01.proact.se (sthav01.proact.se [212.214.215.130]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0A84343D53 for ; Mon, 26 Jul 2004 07:18:34 +0000 (GMT) (envelope-from mathias.samuelson@proact.se) Received: from sthav01.proact.se (localhost [127.0.0.1]) by localhost.proact.se (Postfix) with ESMTP id 24BFE18E5F; Mon, 26 Jul 2004 09:18:01 +0200 (CEST) Received: from semail01.proact.se (semail01.proact.se [192.168.168.234])by s thav01.proact.se (Postfix) with ESMTPid 05BC418E48; Mon, 26 Jul 2004 09:18: 01 +0200 (CEST) Received: by semail01.proact.se with Internet Mail Service (5.5.2653.19)id < N5CHBTR7>; Mon, 26 Jul 2004 09:18:55 +0200 Message-ID: <4104B03E.3080102@proact.se> From: Mathias Samuelson To: iaccounts@ibctech.ca Date: Mon, 26 Jul 2004 09:18:22 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset=iso-8859-1 X-imss-version: 2.0 X-imss-result: Passed X-imss-scores: Clean:33.05235 C:20 M:1 S:5 R:5 X-imss-settings: Baseline:1 C:1 M:1 S:1 R:1 (0.0000 0.0000) cc: freebsd-questions@freebsd.org Subject: Re: Perl split() question (OT)... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Jul 2004 07:18:34 -0000 Steve Bertrand wrote: > Perl hackers -- Figured someone would have a reasonably quick, easy answer > for this: > > 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: > > if ($logLine =~ /$struct$structStart/) { > @lineArray = split (/[/, $logLine); > > 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. > > 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? > > An example of the line I'm trying to get the contents out of is this: > > | "LRED[Conversation started on 03 Feb 21:51:11] > > and I need the data between [ ... ]. > > I know it's OT, but hopefully someone can help me out. > > Tks! > > Steve Something like this perhaps: while(<>) { /.*\[(.*)\].*/; $text = $1; } Rgds Mathias