Well, I am landing from C and this is all so intriguing, but at this time I'd like to load part of the file(binary) as array of chars. Like: read(FILE,$s,$I,$J); @s=split//, $s; however, It seems to me that much computer power are used in vain. Is there any other way that does the job directly without string variable $s?
"Paul Johnson" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > On Sun, Dec 16, 2001 at 06:19:40AM -0800, John W. Krahn wrote: > > "I.J." wrote: > > > > > > If I have a string > > > $s='ABC'; > > > how can I split it into one-char-long-element-array like > > > @s=('A','B','C'); > > > and, generally how can I access individual characters of a string variable? > > substr() > > But might I suggest that if you can get into a Perl way of thinking that > you probably won't want to access the individual characters. I know it > can be difficult if you are coming from C for example, but in Perl there > are usually better ways of doing whatever you are doing. (Of course, I > have no idea what you are doing.) The better ways usually involve > regular expressions. > > > my @s = split //, $s; > > > > my @s = unpack 'a' x length $s, $s; > > > > my @s = $s =~ /./gs; > > > > push @s, substr $s, $_, 1 for 0 .. length $s - 1; > > > > push @s, chr vec $s, $_, 8 for 0 .. length $s - 1; > > Fine, but please consider the sanity of whoever will be maintaining this > code and stick to the first suggestion. You never know, it might even > be you. > > -- > Paul Johnson - [EMAIL PROTECTED] > http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]