Re: Use of initialized value in pattern match



mike.wilson8@xxxxxxxxxxx wrote:


if ($firstline =~/JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC/)
{
$tktnum = substr ($line,3,8);
$userid = substr ($line,14,5);
$pri = substr ($line,29,1);
$status = substr ($line,38,4);
$type = substr ($line,48,12);
$opened = substr ($line,62,7);
$lastupdated = substr ($line,74,6);
}

}

Are you familiar with unpack ?

If you are matching fixed size fields within a string you might find it
easer to use 'unpack' rather than substr.

(untested)

($tktnum, $userid, $pri, $status, $type, $opened, $lastupdated) =
unpack ( "x3 A8 x3 A5 x10 A1 x8 A4 x6 A12 x2 A7 x5 A6", $line);

This translates to
Ignore 3 bytes, grab 8 Alphanumeric bytes, Ignore 3 bytes, grab 5
Alphanumeric bytes,
Ignore 10 bytes, grab 1 Alphanumeric bytes, Ignore 8 bytes, grab 4
Alphanumeric bytes,
etc etc etc.

HTH

.



Relevant Pages