Shawn Milochik wrote:
>
> I am working on a project which involves downloading files via FTP from an
> AS/400, and I had to write a couple of functions because of the weird way
> IBM does things.
>
> The first function takes a value, and dependent upon the final character,
> does something to it.
>
> Rules:
> 1. If it is a letter, the letter represents a specific decimal amount, and
> the number is negative.
> example: 4L = -3.7, or 6R = -6.3 <-- Note: these are not the actual
> numbers corresponding to the letters, I have the sub figure that out.
>
> 2. The close curly-brace '}' denotes that the value is negative.
> example: 4} = -4
>
> 3. All numeric means that the final character is the decimal amount.
> example 43 = 4.3
>
> The second function checks to see if the final character is numeric. If it
> is not, the final character is a stand-in for a digit, and the entire
> statement is negative. Otherwise, the number stays as is.
> examples: 345M = -3452, 5634 = 5634
>
> Hope this is useful to someone. If not, maybe someone already has a
> resource for converting "mainframe" data types. If they do, I'd like to
> know about it.
>
> sub parseFrom400 {
> my $value = @_[0];
^^^^^
You want a scalar here, not an array slice.
my $value = $_[0];
> my $delimiter = substr($value, 3, 1);
> if ($delimiter =~ /[0-9]./){
^
Do you want to match any character except newline here or a literal
dot? Since $delimiter only contains one character trying to match two
characters will never work.
if ( $delimiter =~ /\d/ ) {
> $value = substr($value, 0, 3);
> }
> if ($delimiter =~ /[J-R]/){
> my $tempChar = ord($delimiter) - 73;
> $value += ($tempChar/10);
> $value = 0 - $value;
^^^
No need for the zero here.
$value = -$value;
> }else{
> if ($delimiter eq "}"){
> $value = 0 - $value;
$value = -$value;
> }else{
> $value = $value/10;
Can be shortened to:
$value /= 10;
> }
> }
>
> return $value;
> }
>
> sub parseFrom400_2 {
> my $value = @_[0];
my $value = $_[0];
> my $delimiter = substr($value, 7, 1);
>
> if ($delimiter =~ /[J-R]/){
> my $tempChar = ord($delimiter) - 73;
> $value *= 10;
> $value += $tempChar;
> $value = 0 - $value;
$value = -$value;
> }
>
> return $value;
> }
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]