help w split and array of array plse 
Author Message
 help w split and array of array plse

Am trying to convert an array of strings (grep'd from a file) into an array
of arrays, ie, a 2 dimensioned matrix of numbers. I can't get the split to
work, so I haven't tried the array of arrays part.  I have so far:
=======code
use strict;

   'SPH 083000  111200  111300  111100  111280   503   959',
   'SPH 084000  111250  111380  111200  111370   354   115',
   'SPH 084500  111350  111390  111050  111100   353   747' );
#how to ignore the leading alphas?
#should yield  a matrix numbrs[dim 3][dim 7]
#the ",3" below was just for a test, really want all 7 of above number
groups

eventually

print "$#numbrs\n";

====output
2
SPH|083000|111200  111300  111100  111280   503   959
#                               ^
# where did all this print out from ^ onward come from?
#numbrs has only 3 entitites in it

THANKS
--
{*filter*} Penny



Mon, 07 Mar 2005 00:49:06 GMT  
 help w split and array of array plse

Quote:

> Am trying to convert an array of strings (grep'd from a file) into an array
> of arrays, ie, a 2 dimensioned matrix of numbers. I can't get the split to
> work, so I haven't tried the array of arrays part.  I have so far:
> =======code
> use strict;

>    'SPH 083000  111200  111300  111100  111280   503   959',
>    'SPH 084000  111250  111380  111200  111370   354   115',
>    'SPH 084500  111350  111390  111050  111100   353   747' );
> #how to ignore the leading alphas?
> #should yield  a matrix numbrs[dim 3][dim 7]
> #the ",3" below was just for a test, really want all 7 of above number
> groups

> eventually

> print "$#numbrs\n";

> ====output
> 2
> SPH|083000|111200  111300  111100  111280   503   959
> #                               ^
> # where did all this print out from ^ onward come from?
> #numbrs has only 3 entitites in it

You are doing more work than you need to:

#!/usr/bin/perl -w

use strict;
use Data::Dumper;


while (<DATA>) {
  # skip all but numbers... Note if you had SPH1 it
  # would grab the 1.        

Quote:
}


# to get individual entries in the line do the following:

  print $ra->[2], "\n"; # print out the 3rd value of each line

Quote:
}

__DATA__
SPH 083000  111200  111300  111100  111280   503   959
SPH 084000  111250  111380  111200  111370   354   115
SPH 084500  111350  111390  111050  111100   353   747

hth

-
Vinny



Sun, 06 Mar 2005 21:20:20 GMT  
 help w split and array of array plse
Thanks for your reply.  I've tried your suggested [ m/(\d+)/g ] and I keep
getting the "SHP" back in the match answer, why is that, cannot understand,
new code follows:

=====new code
use strict;
use Data::Dumper;


   'SPH 083000  111200  111300  111100  111280   503   959',
   'SPH 084000  111250  111380  111200  111370   354   115',
   'SPH 084500  111350  111390  111050  111100   353   747' );

print "$#numbrs\n";

====== new results
0
$VAR1 = [
          'SPH 083000  111200  111300  111100  111280   503   959'
        ];

#How can the "SPH" being sucked-up by m/\d+/g ??

Any ideas appreciated.
{*filter*} Penny


Quote:

> > Am trying to convert an array of strings (grep'd from a file) into an
array
> > of arrays, ie, a 2 dimensioned matrix of numbers. I can't get the split
to
> > work, so I haven't tried the array of arrays part.  I have so far:
> > =======code
> > use strict;

> >    'SPH 083000  111200  111300  111100  111280   503   959',
> >    'SPH 084000  111250  111380  111200  111370   354   115',
> >    'SPH 084500  111350  111390  111050  111100   353   747' );
> > #how to ignore the leading alphas?
> > #should yield  a matrix numbrs[dim 3][dim 7]
> > #the ",3" below was just for a test, really want all 7 of above number
> > groups

> > eventually

> > print "$#numbrs\n";

> > ====output
> > 2
> > SPH|083000|111200  111300  111100  111280   503   959
> > #                               ^
> > # where did all this print out from ^ onward come from?
> > #numbrs has only 3 entitites in it

> You are doing more work than you need to:

> #!/usr/bin/perl -w

> use strict;
> use Data::Dumper;


> while (<DATA>) {
>   # skip all but numbers... Note if you had SPH1 it
>   # would grab the 1.

> }


> # to get individual entries in the line do the following:

>   print $ra->[2], "\n"; # print out the 3rd value of each line
> }

> __DATA__
> SPH 083000  111200  111300  111100  111280   503   959
> SPH 084000  111250  111380  111200  111370   354   115
> SPH 084500  111350  111390  111050  111100   353   747

> hth

> -
> Vinny



Mon, 07 Mar 2005 04:32:52 GMT  
 help w split and array of array plse

Quote:

> Am trying to convert an array of strings (grep'd from a file) into an array
> of arrays, ie, a 2 dimensioned matrix of numbers. I can't get the split to
> work, so I haven't tried the array of arrays part.  I have so far:
> =======code
> use strict;

>    'SPH 083000  111200  111300  111100  111280   503   959',
>    'SPH 084000  111250  111380  111200  111370   354   115',
>    'SPH 084500  111350  111390  111050  111100   353   747' );


John
--
use Perl;
program
fulfillment



Mon, 07 Mar 2005 04:46:46 GMT  
 help w split and array of array plse
[Please don't top-post.  I have put your reply in context]


[...]

Quote:
> > #!/usr/bin/perl -w

> > use strict;
> > use Data::Dumper;


> > while (<DATA>) {
> >   # skip all but numbers... Note if you had SPH1 it
> >   # would grab the 1.

> > }


> > # to get individual entries in the line do the following:

> >   print $ra->[2], "\n"; # print out the 3rd value of each line
> > }

> > __DATA__
> > SPH 083000  111200  111300  111100  111280   503   959
> > SPH 084000  111250  111380  111200  111370   354   115
> > SPH 084500  111350  111390  111050  111100   353   747
> Thanks for your reply.  I've tried your suggested [ m/(\d+)/g ] and I keep
> getting the "SHP" back in the match answer, why is that, cannot understand,
> new code follows:

> =====new code
> use strict;

You haven't switched on warnings.  Big mistake.

Quote:
> use Data::Dumper;


>    'SPH 083000  111200  111300  111100  111280   503   959',
>    'SPH 084000  111250  111380  111200  111370   354   115',
>    'SPH 084500  111350  111390  111050  111100   353   747' );


How did you derive *that* from Vinny's suggestion?  It is wrong in
a number of ways.

The right-hand side of the assignment is an anonymous list, hence
a scalar.  You are assigning that to an array.  While this is legal

better, to $numbers).

What you have inside the [] on the right side will be the content
of the anonymous list.  To do that, you have to bind the regular
expression to $lines[0], using the =~ operator.  You have written a
comma, which gives the expression a different meaning entirely.
The pattern match is applied to the default $_, which is undefined
at this point.  Warnings would have told you so.  The result of
that is an empty list, which contributes nothing.  So, in effect,
you are saying



an anonymous list of (again) a single element, the original
$lines[0].  That is what your output shows.

Quote:
> print "$#numbrs\n";

> ====== new results
> 0


Quote:
> $VAR1 = [
>           'SPH 083000  111200  111300  111100  111280   503   959'
>         ];

...which is a listref to a list containing a single string.

Quote:

> #How can the "SPH" being sucked-up by m/\d+/g ??

    my $numbers = [ /\d+/g =~ $lines[0] ];

Anno



Mon, 07 Mar 2005 09:24:14 GMT  
 help w split and array of array plse


Wed, 18 Jun 1902 01:00:00 GMT  
 help w split and array of array plse
Vinny, Anno, & John,

Your replies appreciated. I understand your points & my mistakes.
{*filter*} Penny



Mon, 07 Mar 2005 16:17:12 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. splitting an array into two arrays

2. splitting array, each element holding multiple values into array with single values

3. splitting an array into two arrays

4. splitting an array into a hash of sub-arrays

5. URGENT: Hash in Hash, Array in Array, Array in Hash, Hash in Array

6. Help: Splitting/Inserting Array

7. Help with Assignment of Split Value from STDIN to Hash Values (As Arrays)

8. Help using split and arrays

9. Help with Embedding and Arrays of Arrays?

10. Help with Embedding and Arrays of Arrays?

11. Variable length array of arrays into tree structure - help

12. help with arrays of arrays

 

 
Powered by phpBB® Forum Software