Forum Moderators: coopster & phranque

Message Too Old, No Replies

perl file/array problem

         

tehekaj

12:36 am on Apr 11, 2003 (gmt 0)

10+ Year Member



greetings,
I have a perl problem...
I'm trying to assign a line from a file to a separate array, consider the following code:
---
open(FILE, "./something") or die "$!\n";
@file = <FILE>;
close(FILE);
$line = $file[2]; #this would be line 3 of $file
@myline = $line; # .... :(
---

now I have the line I want in $line, I want to be able to read each character separately, but I if I try and assign $line to another array, it doesn't work.
Does anyone know of a way to solve this? I would greatly appreciate the help.

netcommr

10:04 am on Apr 11, 2003 (gmt 0)

10+ Year Member




@myline = split //, $line;

Brett_Tabke

10:44 am on Apr 11, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



ditto. Most often written:

@myline = split(//,$line);

tehekaj

3:00 pm on Apr 11, 2003 (gmt 0)

10+ Year Member



Thank you both for your replies.
This has accomplished one part of the problem, reading the line into a separate array,
but I can't access each character of the array like $myarray[0] etc.
This is what I want to be able to do.
Would I be better off writing my script in C++ to achieve this?
Also, could some explain why the split(/ /, $line) works?
Thank you for your time.

tehekaj

3:08 pm on Apr 11, 2003 (gmt 0)

10+ Year Member



Sorry for the above post, I didn't see there was no space in the // of split(//, $line) - Damn X11 fonts! :)
Thank you very much, you're lifesavers.