Jenda Krynicky wrote:
> From: Rob Dixon <[EMAIL PROTECTED]>
> > oldgeezer wrote:
> > > foreach my $entry (uniq @IK){
> > >   foreach my $line(@DATA) {
> > >     # Note /;$entry;/ takes longer than
> > >     # /$entry;/ and that takes longer than /$entry/
> > >     # But /$entry/ also splits remarks_entries.
> > >     # So I need the trailing ';' because they
> > >     # are not in the remarks_entries
> > >     # Appending the i, like: /$entry/i slows
> > >     # down too. I don't need it.
> > >     # Prepending m, like m/$entry/
> > >     # does not change anything (timewise).
> > >     # For the average person /$entry;/ is fastest
> > >     if($line=~ /$entry;/) {
> > >      splitline($line); [EMAIL PROTECTED] changes when I splitline
> > >      #next; don't do this. It makes it slower
> > >     };
> > >   };
> > > };
> >
> > Your comments are fine, but they have obscured your code structure. How 
> > about
> >
> > # Note /;$entry;/ takes longer than /$entry;/ and that takes
> > # longer than /$entry/ But /$entry/ also splits
> > # remarks_entries. So I need the trailing ';' because they
> > # are not in the remarks_entries.
> > #
> > # Appending the i, like: /$entry/i slows down too. I don't
> > # need it. Prepending m, like m/$entry/ does not change
> > # anything (timewise). For the average person /$entry;/ is
> > # fastest
> > #
> > foreach my $entry (uniq @IK) {
> >
> >   foreach my $line (@DATA) {
> >
> >     if ($line=~ /$entry;/) {
> >
> >       splitline($line);  # @IK changes when I splitline
> >       #next; don't do this. It makes it slower
> >     }
> >   }
> > }
> >
> > But even then I have issues with what your comments say. First of all you 
> > are
> > obsessed with speed over function. A programmer's primary duty is to make 
> > things
> > that work, and look like they work; it is only a secondary consideration to 
> > make
> > things faster if they turn out to be too slow.
>
> Agreed. OTOH, in this case one might actually make it even quicker
> using qr//:
>
>  foreach my $entry (uniq @IK) {
>    my $entry_re = qr/$entry;/;
>    foreach my $line (@DATA) {
>
>      if ($line=~ $entry_re) {
>
>        splitline($line);  # @IK changes when I splitline
>        #next; don't do this. It makes it slower
>      }
>    }
>  }
>
> Another thing ... if splitline($line) indeed does change @IK (which
> is a bad thing, it should not modify something behind the scenes) do
> you expect the outer foreach to note that? I hope not, in any case,
> it doesn't.
Correct.
But it is a task of splitline to change (add data) to @IK. This is
not 'behind the scene'.
The outer foreach should operate on not changing data of an array that
at entry of the foreach happens to be the same as the (at that
moment current) @IK (stripped of double entries)
I should have written it like:
my @SUBSET=uniq (@IK);
foreach my $entry in (@SUBSET) { do_something}

But your remark is very valid.

> Especially if the $entry is long and is actually a regexp and not a
> string of letters. Of course if it's not meant to be a regexp you
> should use
>    my $entry_re = qr/\Q$entry\E;/;
Ahhh. This qr// is new to me. I've read the perlop now completely
(needed to understand your line anyway). Until now I did read
only the beginning of perlop because I thought it only handled
about operator precedence.

$entry can be many characters. I am not on Linux at the moment,
because the phone of my daughter breaks in at IP adresses
and causes my linux browser to run away. I still got to figure out
what happens there.
So I cannot give you the max line length that a unity
data base allows, neither can I calculate what the longest line
is in my DB. I reckon that to be around 300 to 400 characters.
The lines are latin1 to be precise and closed with LF. On the
web it may also be CRLF. That depends on the server.
It is not a regexp.

>
> Jenda
> ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
> When it comes to wine, women and song, wizards are allowed
> to get drunk and croon as much as they like.
>       -- Terry Pratchett in Sourcery
Thanks.
Rob.


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


Reply via email to