Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2023-01-29 15:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?