|Just another Perl shrine|
Re: regular expression and grep function questionsby 7stud (Deacon)
|on Mar 02, 2013 at 07:35 UTC||Need Help??|
What does "\z" mean in Perl?Some people use the flags /xms as the default starting point for every regex. If you do that, then:
\A \z --beginning and end of the entire string ^ $ --beginning and end of a "line" within the string
Then just forget about \Z, which is unnecessary.
I remember grep only takes two input variables, one is the expression and the other one is an array.
grep BLOCK LIST
A list is a series of comma separated values, e.g. 1, 'a', 2, 'b'. So if you give perl an array along with a scalar value in a spot where perl expects a list, then perl extracts the values from the array and adds the scalar value to the end, creating one list.
That phenomena happens in a lot of places in perl. As hippo explained, look what happens if you call a sub with two arrays:
What do you expect the output to be?
When you call the function perl 'unwinds' the first array into a list of comma separated values, and perl does the same with the second array, creating one big list--as if you called the function like this:
That list then gets assigned to the array named @_. So when you shift one value from @_ and assign the value to the array @x, it's as if you wrote:
And in that line, because there is an array on the left, which expects a list on the right, perl converts the scalar 10 to the list (10) giving you this: