Hendrik Maryns <> wrote:
: 
: I'm writing a little script for removing "rustle" from a log file from
: chat channels, in order to do linguistic research on them.  I took the
: file and tied it with Tie::File, in order to easily acces it.  This
: probably isn't all necessary here, but I want to modify the file
: itself, not writing the output to a new one.
: 
: The first thing is stripping of a date and time at the beginning of
: each line.  My re seems to be correct, as it works.  I do not
: understand why I need the /g modifier though.  If I remove it, only
: the first line that matches gets stripped.  I thought the
: substitution was started all over again for every line?

    In my test the date stamp was removed for the first time from each
line in the file. This:

Lao Tzu [3/6/2005 10:55] Tao
[3/6/2005 10:55] Taoism [3/6/2005 10:55] Taoism
[3/6/2005 10:55] Tao
[3/6/2005 10:55] Taoism
[3/6/2005 10:55] Taoism
Taoism


    Became this:

Lao Tzu Tao
Taoism [3/6/2005 10:55] Taoism
Tao
Taoism
Taoism
Taoism


     What you might add is the beginning of the line anchor '^'.

s{^\[\d+/\d+/\d+\s\d+:\d+\]\s}{};


    I tested with this.

foreach my $lijn ( @bestand ) {
    $lijn =~ s{^\[\d+/\d+/\d+\s\d+:\d+\]\s}{};
}

: Well, in writing this, I solved half of my problem, but one still
: remains: how can I remove a line?  I tried with delete, as you see
: below, but (of course) this does not work, as $lijn is no array
:   element. How can I totally remove that line from my file?

    You need to 'splice' it out. I'm not sure that Tie::File is the
best solution for that. It is not wise to operate on an array while
stepping through it with a for block. You'll need to track through
the current index to splice the array. Can you get by with just
deleting the line contents?

$lijn = '' unless $lijn =~ /^<.*>/;


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to