Chris Stinemetz wrote:
I am trying to split the first element of an array by white space then
continue reading the rest of the file.
Thus far I am having trouble figuring out how to split the first line.
I would like the first line to be split so it looks like the following
with the "=" sign added.
Thank you in advance!
Chris
csno=
rfpi=
header_1=
header_2=
header_3=
header_4=
header_5=
header_6=
header_7=
header_8=
header_9=
I am getting the error:
Use of implicit split to @_ is deprecated at ./xxxxx.pl line 6.
perldoc -f split
split /PATTERN/,EXPR,LIMIT
split /PATTERN/,EXPR
split /PATTERN/
split Splits the string EXPR into a list of strings and returns
that list. By default, empty leading fields are preserved,
and empty trailing ones are deleted. (If all fields are
empty, they are considered to be trailing.)
In scalar context, returns the number of fields found. In
scalar and void context it splits into the @_ array. Use
of split in scalar and void context is deprecated, however,
because it clobbers your subroutine arguments.
#!/usr/bin/perl
use warnings;
use strict;
while (my @line =<DATA>) {
You don't need a while loop if you are just going to read the whole file
into an array.
my $header = split " ",$line[0];
You are using split in scalar context which means that $header will now
contain the number 11 because there are 11 fields in $line[0].
print $header;
}
__DATA__
csno rfpi header_1 header_2 header_3
header_4 header_5 header_6 header_7 header_8
header_9
1 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5
5.5 5.5
1 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5
5.5 5.5
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/