sidney04 has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone, I've been looking at this particular code for 20 minutes already and I don't seem to get what "qq/ /" mean:

$key=substr ($input,0, index($input,qq/ /,-1));

can somebody please help me?

Sidney™

Retitled by davido from 'Help me understand i'm a newbie'.

Replies are listed 'Best First'.
Re: Help me understand what qq// means
by ikegami (Patriarch) on Jul 06, 2005 at 22:31 UTC
Re: Help me understand what qq// means
by Corion (Patriarch) on Jul 06, 2005 at 22:33 UTC

    Read perldoc perlop (or perlop), specifically the section about qq. It is the "double quote" operator, that is, it allows you to specify the delimiters for a double-quoted string.

    Often, it also helps to let Perl tell you how it sees some code:

    perl -MO=Deparse -e " $key=substr ($input,0, index($input,qq/ /,-1));"

    gives me

    C:\>perl -MO=Deparse -e " $key=substr ($input,0, index($input,qq/ /,-1 +));" $key = substr($input, 0, index($input, ' ', -1)); -e syntax OK

    The qq/ / is seen by Perl as a simple string, just that it was delimited by slashes.

Re: Help me understand what qq// means
by tlm (Prior) on Jul 07, 2005 at 02:50 UTC

    As others have already pointed out qq() is basically the same as double quotes. But I wonder about that code you have there. The -1 argument to to index is ignored, so basically what that line is doing is: IF $input contains at least one space, then $key is set to the beginning of $input up to (but excluding) the first space. If, on the other hand, $input contains no spaces, then $key is set to $input minus its last character (or the empty string, if $input is empty); this is because in this case index returns -1, and therefore substr removes the last character.

    It looks like pretty nutty code to me.

    the lowliest monk

      Thank you all :) I really appreciated all the answers you provided :)
Re: Help me understand what qq// means
by jacques (Priest) on Jul 06, 2005 at 22:56 UTC
    perldoc -f qq
Re: Help me understand what qq// means
by tphyahoo (Vicar) on Jul 07, 2005 at 16:36 UTC
    Use the perl index: qq

    This Index should contain pointers to all the available things you wil +l find or expect in Perl 5 such as: * built in variables * function names * operators * flow control structures * special characters of regular expressions * exported functions of standard modules * names of functions in other languages with the corresponding nam +es in Perl.....
    Real good thing to know about, ++ to szabgab :)