Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: split as immediate array?

by Rydor (Scribe)
on Aug 11, 2001 at 19:43 UTC ( [id://104149] : note . print w/replies, xml ) Need Help??


in reply to Re: split as immediate array?
in thread split as immediate array?

That's odd. what you say works in every instance except when trying to print it immediately. Fortunately i don't need to, but that's just an odd twist. I had been trying to print it right away for my testing, which is why it didn't work, i'd say. thanks

@:::::::((==========Rydor====>

Replies are listed 'Best First'.
(bbfu) (function vs "operator") Re: Re: Re: split as immediate array?
by bbfu (Curate) on Aug 11, 2001 at 19:49 UTC

    ...works in every instance except when trying to print it immediately.

    You're probably running afoul of the function vs. "list operator" nature of builtin's when called with and without parentheses, respectively. Specifically, perl sees that first parenthesis and says to itself, "Oh! That must be a function call," when, really, you want those parentheses to create a list that you can then subscript. So you end up subscripting the return value of print (ie, a list containing a single element: (1)) Try:

    print +(split(...))[3]; # force "list operator" mode, or... print( (split(...))[3] ); # make the whole thing a function call.

    Update: Elucidated exactly what I meant by "running afoul". :-)

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.

      yeah, i see how those paranthesis mess that up. thanks.

      @:::::::((==========Rydor====>