On 12-06-05 08:31 PM, Steve Bertrand wrote:
On 05/06/2012 3:49 PM, Shawn H Corey wrote:
On 12-06-05 05:43 PM, Bill Stephenson wrote:
Maybe this is what you need?
#!/usr/bin/perl
use warnings;
use strict;
my @array;
while ( my $line =<DATA> ) {
chomp $line;
push (@array = split(/\s+/, $line,-1));
push @array, [ split /\s+/, $line, -1 ];
I'm not on a box I can test this with, but won't that push an array ref
into the hash? Do you mean to surround it with parenthesis instead, or
am I missing something?
If you use parenthesis, it will push the list onto the end of the array.
This may be what you want but you will lose all idea of the each item
came from. It all depends on what you want to do with the data.
Here's the difference:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
# Set maximum depth for Data::Dumper, zero means unlimited
local $Data::Dumper::Maxdepth = 0;
my @lines = <DATA>;
my @array = ();
for my $line ( @lines ){
push @array, [ split /\s+/, $line, -1 ];
}
print Dumper \@array;
@array = ();
for my $line ( @lines ){
push @array, ( split /\s+/, $line, -1 );
}
print Dumper \@array;
__DATA__
Line1 c 2 3 4 5 C 7 8 9
Line2 1 2 3 4 5 6 7 8 9
Line3 1 2 3 4 5 D 7 8 9
Line4 1 2 3 4 5 aDC6 7 8 9
Line5 1 2 3 4 5 D 7 8 9
Line6 1 2 3 4 5 dcDC 7 8 9
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
_Perl links_
official site : http://www.perl.org/
beginners' help : http://learn.perl.org/faq/beginners.html
advance help : http://perlmonks.org/
documentation : http://perldoc.perl.org/
news : http://perlsphere.net/
repository : http://www.cpan.org/
blog : http://blogs.perl.org/
regional groups : http://www.pm.org/
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/