I'm not sure what you actually want to do, but I do my fixed-length data munging using unpack and/or substr.
| [reply] |
HI from another former FORTRAN programmer.
EQUIVALENCE was really great when you had a language that couldn't directly convert types worth anything, but you've got Perl, and it can manage this way better and simpler.
You do indeed want to use unpack for this one. I'm guessing that your fixed-length data is in some binary format rather than in ASCII. unpack will let you take that in chunks and convert it - it's very like a FORMAT statement in that regard. However, it's a good bit more powerful, as it lets you have a lot of control as to how you want to manipulate the data.
Take a look at unpack and pack for the lowdown on what you can do - it's quite a lot. I'm certain your need will be met.
| [reply] [d/l] [select] |
Yet another former FORTRAN programmer here! You might find some useful ideas in this node by BrowserUk.
| [reply] |
I've programmed Fortran for about thirty-five years (I started before the existence of Fortran-77, when FORTRAN didn't have a character data type). I've found the EQUIVALENCE statement to be a major source of buggery and non-portability. Indeed, it was banned in most of the shops in which I worked. I did use it a lot in PLM (product life-cycle management) programming using the Catia CDM/CDS API, and have used it for when I've needed to twiddle bits (yeah, I've done it in Fortran), but I've also had to maintain code where EQUIVALENCEd variables were used to read ASCII flat files, a practice which I believe is hideous, and completely unnecessary.
Use pack and unpack. It's the closest you'll get to Fortran's FORMATted I/O
Information about American English usage here and here. Floating point issues? Please read this before posting. — emc
| [reply] |
Dear Corion, pemungkah, johngg, swampyankee,
Thank you all so much for the replies.. I guess what I'm after is simply code simplification, the data is all character-based, no binary, i just wanted to do either EQUIVALENCE, or use the VMS Fortran's capability to do STRUCTUREs, so the the first 10 chars of INREC mapped directly to COLUMN1, the next 10 mapped directly to COLUMN2, and so forth. I've already done it with the following snippets..
$CDXCODE = NibbleItOff(8);
where NibbleItOff is defined as:
######################################################################
+###############
sub NibbleItOff {
my $Field_Length = shift;
my $Output_String;
#print "NibbleItOff>>inrec->$inrec<\n"; print "NibbleItOff>>Field_Leng
+th->$Field_Length<\n";
$Output_String = substr( $inrec, 0, $Field_Length );
$inrec = substr( $inrec, $Field_Length );
#print "NibbleItOff>>inrec->$inrec<\n"; print "NibbleItOff>>Output_Str
+ing->$Output_String<\n";
return $Output_String;
}
######################################################################
+###############
using either EQUIVALENCE, or appropiate STRUCTUREs, that could be eliminated..
Just a passing thought... I'll gladly look up the UNPACK, but it seems to be for binary data, tho..
Thanks for all the hints!!!
Jim | [reply] [d/l] |
Also Kudos to all the FORTRAN programmers (Or ex-FORTRAN)!!!
It was and still is a wonderful language for math as well as whatever else it could do with extensions.. My flavor we used for the longest time was the DEC VAX line.. When we left the VAXen, after a long time of searching, I choose Perl for the next language, as it ran on VAX, PC, Unix, Linux, etc.. (no CP/M, tho! ;-) But that first computer is long gone...) Guess I just dated my self.. Now I've just written my first interface with MS-SQL Server..
| [reply] |