On Tue, 25 Feb 2003, cc wrote:

> Hi,
> 
> I'm a beginner at PERL.  I've used it on and off, but only
> just recently got myself back into the picture.  I figured
> that if you forget something in PERL, it'd be easy to take
> it up again.  So far, I'm not too sure of the ease
> of taking up PERL again.  Before, I made a few perl scripts.
> Now, when I look back, I find the whole thing overwhelming.
> Even with comments...Anyway, I digress..

You might want to read through these docs too
perldoc perllol
perldoc perldsc
perldoc perlreftut
perldoc perlref

> 
> I have a text file with each line of the following format:
> 
> string1  string2  val1 val2 val3
> 
> I'm trying to read it into an array of arrays so I can
> stick it in the creategraph() function to create a  line
> graph.
> 
> So far, if I specifically create an array constant:
> 
> ie.
> 
> my(@data) = ( ["test 1",0.34,0.56,0.33],
>                  ["test 2",0.44,0.55,0.22],
>                   ["final test",0.67,0.22,0.54])
> 
> my($grp) = new GD::Graph::linespoints();
> 
> and then put that in the $grp->plot([EMAIL PROTECTED]) function, I get
> a graph.
> 
> But, if I use the following code:

I guess you have enabled the strict and warnings pragmas, if not enable 
them.
perldoc perltrap

> 
> while (<MYFILE>){
>        chomp($_);

You don't have to chomp here, the split in the next line will take care of 
removing the newline too
perldoc -f split

>        @info = split(" ",$_);

better written as
        my @info = split;

>        my($strngval) = "\"$info[0] $info[1]\"";
>        $strval = "$strval,$strngval";
>        $m1vals = "$m1vals,$info[2]";
>        $m2vals = "$m2vals,$info[3]";
> }
> 
> my (@sv) = split(",",$strval);
> my(@m1) = split(",",$m1vals);
> my(@m2) = split(",",$m2vals);
> 
> my(@data) = (@sv,@m1,@m2);
> 
> Are @sv, @m1 and @m2 all arrays?  So, would @data be an
> array of arrays?  Or are the @sv, @m1 and @m2 arrays
> flattened out, making @data just an array?

Yes, @data is just an array not an array of arrays. 
Does this do what you want?

# CODE START #
my @data;
while (<MYFILE>) {
    my @info = split;
    push (@data, ["$info[0] $info[1]", @info[2..$#info]]);
}
# CODE END #

You might also want to take a look at the Data::Dumper module to make sure 
your array of arrays is formed correctly.
perldoc Data::Dumper

> 
> The thing is, with the fixed way of doing the graph,
> and when I print out @data, I get
> 
> ARRAY(....) ARRAY(....) ARRAY(...)
> 
> But with the 'dynamic' way, I just get
> ARRAY(...)
> 
> where (....) are memory locations in Hex, I believe.
> 
> Can someone point out what I'm doing wrong?
> 
> Thanks
> 
> E

hth,
Sudarshan


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to