in reply to different return type for split
It's probably a good idea to check out 7 Stages of Regex Users as well. Oh yeah, Don't be confused by the =~. It's not only an assignment, it's also a function that returns something, just like when it acts on $_. See perldoc, illustrated by:$txt = "This is a string"; $count = $txt =~ tr/ //; #counts all spaces $count = () = $txt =~ m/\s/g; #counts all whitespace characters $count = () = $txt =~ m/\s+/g; #counts whitespace occurences (default + [split] behavior)
Does exactly the same, but now the match is done on $_. $_ is assigned to by for. Don't assign to $_ yourself (or use local). A complete different approach still is the use of index, which may be handy under certain circumstances.$count = tr/ // for ($txt);
Hope this helps,
Jeroen
"We are not alone"(FZ)
Update: I must have been sleeping.... read merlyn's
reply... code is working now.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: different return type for split
by merlyn (Sage) on Mar 19, 2001 at 19:46 UTC |