in reply to Re: recursive join
in thread recursive join

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, $_; }

Replies are listed 'Best First'.
Re: Re: Re: recursive join
by BrowserUk (Patriarch) on Dec 21, 2002 at 14:56 UTC

    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

        No. I was using m[...] as an alternative to m/.../

        If your editor doesn't like it, then try m!...!


        Examine what is said, not who speaks.

Re: Re: Re: recursive join
by Eimi Metamorphoumai (Deacon) on Dec 22, 2002 at 17:58 UTC
    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.