in reply to text sorting question, kinda

For what it's worth, here's my take on the situation:
#!/usr/bin/perl -w use strict; my (@data, $i); my @logfile = <DATA>; for (@logfile) { /blahblah/? splice @data, $i++, 0, $_:push @data, $_; } print @data; __DATA__ foo 1 zot foo 2 blahblah bar 1 zot bar 2 zot bat 1 blahblah bat 2 baz 1 baz 2 zot
It works fine and only needs one array.

Cheers,
Ovid

Update: Clearly, I am smoking crack. larsen pointed out that I kept an extra array. Here's what I meant to post:

#!/usr/bin/perl -w use strict; my (@data, $i); for (<DATA>) { /blahblah/? splice @data, $i++, 0, $_:push @data, $_; } print @data; __DATA__ foo 1 zot foo 2 blahblah bar 1 zot bar 2 zot bat 1 blahblah bat 2 baz 1 baz 2 zot
There. Only one array. (sigh)

Replies are listed 'Best First'.
RE: (Ovid) Re: text sorting question
by larsen (Parson) on Aug 03, 2000 at 01:05 UTC
    Yes, but there's @logfile that contains the entire file. And you have:
    $#logfile + $#data > $#toplines + $#otherlines


    see you
    Larsen