in reply to recursive join

You'd be better off (and more efficient) to code that as

$LINE = ''; ... $LINE .= $_ if /^DATA\:/;

Examine what is said, not who speaks.

Replies are listed 'Best First'.
Re: Re: recursive join
by Anonymous Monk on Dec 21, 2002 at 14:47 UTC
    Thanks for the tip

    While we're on the subject of efficiency, how could I make this a little more efficient?

    if ($_ =~ /^FOO \=/) { $_ =~ s/^FOO \=\s//; $_ =~ s/\\$//; push @array, $_; }

      Firstly, you don't need to reference $_ for the m// or the s///, as it is the default. Second, you can capture the bit you want in the m//. It's also better to use a different delimiter if you have /'s in your regex

      push @array, $1 if m[^FOO\s=\s(.*?)/$];
      should capture everything after the first space after the '=' and before the trailing '/'. If the number of spaces might vary then

      push @array, $1 if m[^FOO\s+=\s+(.*?)/$];

      This wouldn't harm if there is only one space before and after.


      Examine what is said, not who speaks.

        Thanks again, you have been a great help. I always learn something new when I come here.

        One last thing, shouldn't I have a slash after the match character?

        push @conf, $1 if m[^SSLOGGER FILE\s+=\s+(.*?)/$]; #before push @conf, $1 if m/[^SSLOGGER FILE\s+=\s+(.*?)/$]; #after
        I'm using VIM for windows and it doesn't like that string for some reason
      if (s/^FOO =\s//){ s/\\$//; push @array, $_; }
      Basically, the only real change for efficiency is to do the replace once instead of twice. The rest is style, though style counts. I might suggest, though, making the first one a bit less strict, something like
      if (s/^FOO\s*=\s*//){
      So it doesn't matter if there's more than one space, or a tab, or...whatever. But that's for your code to do with as it will.