Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: I don't understand a piece of this code

by Albannach (Prior)
on Jun 18, 2012 at 03:40 UTC ( #976732=note: print w/replies, xml ) Need Help??


in reply to I don't understand a piece of this code

I rather think of qw as quote whitespace since what it does is break up the subject string using whitespace as separators. So the string inside the qw() is broken into 3 pieces, not 3 words as in this case each resulting piece contains 2 words and some square brackets. See perlop under Quote and Quote-like operators.

The next think you need to know is that \Q and \E are allowing you to use the content of the variable $what as literal text without interpreting any special characters, which in this case are the square brackets. Have a look at perlre to see what [box] means inside a regular expression.

So in summary it is looking for the string [box] including the square brackets, withing the 3 separate strings in[box], out[box], and white[sox], and prints matches.

--
I'd like to be able to assign to an luser

Replies are listed 'Best First'.
Re^2: I don't understand a piece of this code
by bitingduck (Chaplain) on Jun 18, 2012 at 03:49 UTC

    That's how I initially learned it as well, but perldoc.perl.org j ust says "quote a list of words" where you have to sort of liberally accept that a word is letters separated by whitespace. "Quote with whitespace" makes more sense to me than "quote whitespace", but it mostly just matters that it works as advertised.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://976732]
help
Chatterbox?
[shmem]: but the results of both operations are different.
[shmem]: result := the discarded result (what's leftmost of the statement)
[shmem]: push returns the number of elements in @foo, the assignment returns all the elements in the (renewed) @foo
[Lady_Aleena]: Sanity check please? push @line, ref($list_addition ) eq 'ARRAY' ? @$list_addition : $list_addiction; # so I don't have the change existing uses of the sub.
[shmem]: $list_addiction should be $list_addition
Discipulus loose the tozzetto party!
[shmem]: .oO( addition of cookies for addiction to cookies )
[Lady_Aleena]: Other than my typos shmem. 8)
[shmem]: otherwise fine
[Discipulus]: tozzetti & vinsanto

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2017-04-27 11:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (503 votes). Check out past polls.