1)  Wrong list.  This list is for the folks who are currently
implementing the new language Perl 6.
  You want [EMAIL PROTECTED]  Send a message to
[EMAIL PROTECTED] to subscribe, and please send any
followups there rather than here.

2) Strings in Perl are not objects, and there is no "String" class -
Perl 5 is simply not that object-oriented. You don't say  $str = new
String("blah") (which would be redundant even in Java and Javascript,
since the literal already constructs an object); you just say $str =
"blah". Anyway, it looks like you already have a string variable in
your example, namely $line[0].

3) Since strings aren't objects, you don't call methods on them; you
use functions instead.  So it's not $str->length, but length($str).

4) There's no distinction between characters and strings in Perl;
strings are not considered to be a collection of characters, but
rather a fundamental type.  So you can't index into the string.
Instead, use the substr() function to pull out a substring of length
1:

  printf "The first character of the string is '%s'\n", substr($str,0,1);

Also, since print() takes multiple arguments and concatenates them,
and you can interpolate variables in strings, you don't need printf
most of the time:

   print "The first character of the string is '", substr($str,0,1), "'\n";

...although it is arguably clearer in this case.




-- 
Mark J. Reed <[EMAIL PROTECTED]>

Reply via email to