Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: How can I use 'split' with unknown amount of variables?

by marmot (Novice)
on Dec 30, 2001 at 23:02 UTC ( #135265=note: print w/replies, xml ) Need Help??

in reply to How can I use 'split' with unknown amount of variables?

It's hard to tell exactly what you're asking. Do you just want to know how many elements are returned to you? Easy. Do as others have suggested: split to an array and then find the number of elements it contains. You don't necessarily need to assign variables; just use the array elements directly.
@list = split /\|/, FuncThatGivesData(); print "Found ", scalar(@list), " elements\n"; $i = 0; foreach $e (@list) { print "Element $i: $list[$i]\n"; $i++; }
Do you need to know which variables came back? Your example, "key|title|date|author|news", could be interpreted as a regular expression (i.e., "key OR title OR date...") or as a literal string, where '|' is the separator. If '|' is the separator, follow the example above. If you really are asking how to tell which pieces of data were returned, you need some kind of header to idenfity the fields, and it's a somewhat more complex problem.

Can you be more specific with your question?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://135265]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2023-03-31 13:02 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (75 votes). Check out past polls.