in reply to newbie attempting to extract

I believe that you are looking for the split function.

#!/usr/bin/perl use strict; use warnings; while(<DATA>) { my @a = split; # split record into fields print "Value = $_\n" for @a; # print out all fields print "\n"; # blank line between "records" } __DATA__ 1234567890123456 2004-07-10 14:47:39 51.12345 -1.12345
That will produce
Value = 1234567890123456 Value = 2004-07-10 Value = 14:47:39 Value = 51.12345 Value = -1.12345

Hope that helped,
-v
"Perl. There is no substitute."

Replies are listed 'Best First'.
Re^2: newbie attempting to extract
by jamaas (Novice) on Oct 03, 2004 at 07:30 UTC
    It helped a whole bunch!! And so elegant.
    OK, next challenge!
    Thanks and Regards
    Jim
    jamaas btinternet com
Re^2: newbie attempting to extract
by jamaas (Novice) on Oct 03, 2004 at 15:11 UTC
    Thanks Velaki,


    Obviously this works beautifully. I've tried reading the perldoc info on split.... and tried to put in an incrementing loop to give the values unique names such that these can then be passed to php code for insertion into mysql. It appears that split does all this in one pass so incrementing a loop counter doesn't work. Can this @_array be used to directly insert into mysql table?


    Thanks a bunch

    Jim
    jamaas btinternet com

      This provides a unique value for each data item. It combines a row ID ($.) and a field ID ($i).

      # data_read use strict; use warnings; while (<DATA>) { chomp; my @data = split; for (my $i = 0; $i <= $#data; ++$i) { print "$._$i = $data[$i]\n"; } } __DATA__ qwerty qwerty qwerty asdf zxcv 1234 qwerty qwerty qwerty asdf zxcv

      Here's the output:

      [ ~/tmp ] $ perl data_read 1_0 = qwerty 1_1 = qwerty 1_2 = qwerty 1_3 = asdf 1_4 = zxcv 1_5 = 1234 2_0 = qwerty 2_1 = qwerty 2_2 = qwerty 2_3 = asdf 2_4 = zxcv [ ~/tmp ] $

      Here's a perl.com article which describes $. and other special variables.

      Regards,

      PN5