On May 11, 7:25 pm, siegfr...@heintze.com wrote:
> Darn -- I forgot to switch to plain text again. I hope this does not
> appear twice -- I apologize if it does!
>
> This works and produces the desired result (I've simplified it a bit):
>
> $default= ((((`grep pat file-name`)[0])=~/[0-9]+/)[0]);
>
> Why does it take so many parentheses?
>
> I don't think it should work, however.
>
> (1) Why cannot I just index the results of the sub-process directly and
> say `grep pat file-name`[0]? If Perl is confused I would think I might
> need to explicitly convert it like this:
>   @{`grep pat file-name`}[0]
> but that does not work. I think it should.
>
> (2) I have the same question about the =~ operator -- it returns an
> array too. So why cannot I just type
> print @{$a=~/([0-9]+)/}[0] ?
>
> Instead I have to type
>  print (($a=~/([0-9]+/)[0]);
>
> Why are the extra outer parens required?

This requires a fair amount of background about
list vs array context. Here's a good introduction:

     perldoc -q array

See:  'What is the difference between a list and an array?'
in the above output.

This may answer some of the questions and/or
at least give you some background for a better
understanding of the issues.

HTH,
Charles DeRykus


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to