timothy adigun wrote:
Hi Chris,
   Please check added code to yours, in addition to what John 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.

#!/usr/bin/perl
use warnings;
use strict;

#while (my @line =<DATA>) {
while (my $line =<DATA>) {
       chomp $line;
   # my $header = split " ",$line[0];
      if($. == 1){   #$. =>  Current line number for the last filehandle
accessed
        print $_,"=\n" for split/\s+/=>$line;

Don't change split " " to split/\s+/, it does something different. And you don't need to use chomp as both split " " and split/\s+/ remove ALL whitespace, including the newline.


      }
     else{print $line,"\n";}
   #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/


Reply via email to