Re: Use of initialized value in pattern match
- From: niall.macpherson@xxxxxxxxxxxx
- Date: 19 May 2006 02:50:25 -0700
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
.
- Follow-Ups:
- Re: Use of initialized value in pattern match
- From: Brian McCauley
- Re: Use of initialized value in pattern match
- References:
- Use of initialized value in pattern match
- From: mike . wilson8
- Use of initialized value in pattern match
- Prev by Date: Re: PB with euro sign and checkbox in multipart/form-data
- Next by Date: Text parsing and substitution
- Previous by thread: Re: Use of initialized value in pattern match
- Next by thread: Re: Use of initialized value in pattern match
- Index(es):
Relevant Pages
|