Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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?


In reply to Re: How can I use 'split' with unknown amount of variables? by marmot
in thread How can I use 'split' with unknown amount of variables? by bladx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2023-01-31 09:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?