Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Perl newbie question.

by kiruthika.bkite (Scribe)
on Mar 19, 2010 at 09:24 UTC ( #829576=note: print w/replies, xml ) Need Help??


in reply to Re: Perl newbie question.
in thread Perl newbie question.

my $nr = split (/\s+/, $_[0]);

We can get the number of elements by simply assigning the return value of split into a scalar variable.

Example
$str="1:3:4:5"; my $num=split(':',$str); print "Num:$num";

$num will contain '4'.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://829576]
help
Chatterbox?
[Corion]: Nicholas Clark++ # read for a multichar block-delimiter by scanning for the last char, and only then check whether the whole delimiter was read.
[Corion]: At least if you're appending the data read to a larger buffer, this means you avoid the situation of "a delimiter was found but the other half has not been read yet"
choroba misses the context
[Corion]: choroba: Optimizing how Perl reads source code on startup (and then processes it line-by-line)
[Corion]: But in general, it seems to be an interesting approach I should think about - whenever I'm searching for something, to consider if I could search for the end of the token instead of the start of the token

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2016-12-06 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (107 votes). Check out past polls.