Hi,
This is an interesting thing about perl. The array vs scalar context.
If you put parenthesis around the variable, you change the "context" of the right side from scalar, to array.
For:
Code:
$a = "author.234098333abc" ;
($userid) = split (/\./, $a);
'split' returns an array of the 'splits', so to pull off the first term, you'd use it as above (I just assumed that's all you cared about. 'join' is the reverse of split.
This:
Code:
$a = "author.234098333abc" ;
$userid = split (/\./, $a);
is one of the quirks of perl. By not putting the () around the $a, you are forcing a scalar context of the right side, which wants to return an array. So, perl does the next best thing, it returns the number of elements _in_ the array, which would be two -- since there is one period, the split returns 'author' and '234098333abc' which is two elements (0 and 1) in the array.
Regexes work the same way....
($a) =~ regex
will put the first result of the regex into $a.
$a =~ regex
will give '0' if the regex fails, or '1' if it succeeds.
That's why perl books usually start with discussions of 'context' even before operations <G>.
FWIW: the best perl book I've found is Perl Power! A jump start guide to programming with perl 5 - by Michael Schilli - pub: addison-wesley. For just language references "Perl Core Language Little Black Book" by Steven Holzner pub:coriolis is pretty good. There is also a pretty good book on RegEx's "Mastering Regular Expressions" by Jeffrey EFFriedl pub:OReilly.
www.postcards.com/infodir/amazon/perl_books.html I'm starting a list of the books in my collection with reviews, but it's still in production. The above link has those books in clickable format -- and as always as a free site, we appreciate any orders from our site
[This message has been edited by pugdog (edited August 27, 1999).]