Hello Friends,
i am putting some problem here. can anybody know where i am wrong in this code. actully i am spliting string in this format as a sample.s37 file.here some format below -
Stnnaaaadddddddddddddddddddddddddddddddd ... cc
-
S = 'S' indicates a Motorola S record
-
t = Record type, '0' = Header, '1'=data, '9'=end of file.
-
nn = Count of number of bytes in record. (in ASCII/HEX)
-
aaaa = Load address of data record. (in ASCII/HEX)
-
dd = Actual data bytes in record. (in ASCII/HEX)
-
cc = Checksum of count, address, and data. (in ASCII/HEX)
-
-
input file:sample.37
-
-
S1130000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC
-
-
use warnings;
-
use strict;
-
{
-
my ($rd_file_handle) = @_;
-
my @file_contents;
-
open (INPUT, "sample.s37"); #| die ("Couldn't open file $rd_file_handle: $!\n");
-
{
-
@file_contents = <INPUT>;
-
}
-
close(INPUT);
-
my $Length= @file_contents;
-
my $s = substr(@file_contents,($Length-1));
-
my $t = substr(@file_contents,($Length-2));
-
my $nn = substr(@file_contents,2,($Length-4));
-
my $aaaa = substr(@file_contents,4,($Length-8));
-
my $cc = substr(@file_contents,($Length),-2);
-
#my $file_contents = split (// , $rd_file_handle);
-
printf("Text:@file_contents\n$s\n$t\n$nn\n$aaaa\n$cc\n");
-
}
-
expected output:
s S
t 1
nn 13
aaaa 0000
cc FC
can anybody try it out..
bye......
8 1262
substr() does not work on arrays.
substr() does not work on arrays.
thank you kelvin.
can give me any alternative for this code. -
use warnings;
-
use strict;
-
{
-
my $file_contents;
-
open (INPUT, "sample.s37");
-
{
-
$file_contents = <INPUT>;
-
}
-
close(INPUT);
-
my @index = split (//, $file_contents);
-
my $Length= @index;
-
my $s = substr($file_contents,$Length-1);
-
#my $t = substr(@file_contents,($Length-2));
-
#my $nn = substr(@file_contents,2,($Length-4));
-
#my $aaaa = substr(@file_contents,4,($Length-8));
-
#my $cc = substr(@file_contents,($Length),-2);
-
printf("Text:$file_contents\n@index\n$Length\nS:$s");
-
}
-
this also not working... please give me some better solution.
Regards
Lokesh...
thank you kelvin.
can give me any alternative for this code.
Code:
use warnings;
use strict;
{
my $file_contents;
open (INPUT, "sample.s37");
{
$file_contents = <INPUT>;
}
close(INPUT);
my @index = split (//, $file_contents);
my $Length= @index;
my $s = substr($file_contents,$Length-1);
#my $t = substr(@file_contents,($Length-2));
#my $nn = substr(@file_contents,2,($Length-4));
#my $aaaa = substr(@file_contents,4,($Length-8));
#my $cc = substr(@file_contents,($Length),-2);
printf("Text:$file_contents\n@index\n$Length\nS:$s ");
}
this also not working... please give me some better solution.
Regards
Lokesh...
Sorry ! kevin i wrote wrong name
my @index = split (//, $file_contents);
my $s = $index[0];
my @index = split (//, $file_contents);
my $s = $index[0];
thank you Kevin... i am getting proper output not getting some data... -
use warnings;
-
use strict;
-
{
-
#my ($rd_file_handle) = @_;
-
my $file_contents;
-
open (INPUT, "sample.s37"); #| die ("Couldn't open file $rd_file_handle: $!\n");
-
{
-
$file_contents = <INPUT>;
-
}
-
close(INPUT);
-
my @index = split (//, $file_contents);
-
my $Length= @index;
-
my $last = scalar($Length-3);
-
printf("\nType:@index[0..1]\nCount:@index[2..4]\nAddress:@index[4..8]\nCheckSum:@index[$last..$Length]\n,Text:@index");
-
-
}
-
output;
Type:S 1
Count:1 3 0
Address:0 0 0 0 F
CheckSum:F C
,Text:S 1 1 3 0 0 0 0 F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F C
but i need data part also...can you help me how can i try for this..
Data: F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F
thank you Kevin... i am getting proper output not getting some data... -
use warnings;
-
use strict;
-
{
-
#my ($rd_file_handle) = @_;
-
my $file_contents;
-
open (INPUT, "sample.s37"); #| die ("Couldn't open file $rd_file_handle: $!\n");
-
{
-
$file_contents = <INPUT>;
-
}
-
close(INPUT);
-
my @index = split (//, $file_contents);
-
my $Length= @index;
-
my $last = scalar($Length-3);
-
printf("\nType:@index[0..1]\nCount:@index[2..4]\nAddress:@index[4..8]\nCheckSum:@index[$last..$Length]\n,Text:@index");
-
-
}
-
output;
Type:S 1
Count:1 3 0
Address:0 0 0 0 F
CheckSum:F C
,Text:S 1 1 3 0 0 0 0 F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F C
but i need data part also...can you help me how can i try for this..
Data: F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F
Ok, that is twice in the same posting that I have added code tags to your code. Please refer to the "REPLY GUIDELINES" to the right of the Message window when posting for the proper way to add code tags. They are not "Code:". Instead, the start with a "[", have the word "code" in the middle, and end with a "]".
Please use them in all future posts.
Thank you!
Regards,
Jeff
Ok, that is twice in the same posting that I have added code tags to your code. Please refer to the "REPLY GUIDELINES" to the right of the Message window when posting for the proper way to add code tags. They are not "Code:". Instead, the start with a "[", have the word "code" in the middle, and end with a "]".
Please use them in all future posts.
Thank you!
Regards,
Jeff
============================ -
===========================
-
use warnings;
-
use strict;
-
{
-
-
my @file_contents;
-
open (INPUT, "sample.s37");
-
{
-
@file_contents = <INPUT>;
-
-
}
-
close(INPUT);
-
my $i;
-
for($i=0;$i<@file_contents-1;$i++)
-
{
-
my $Type = substr ($file_contents[$i], 0,-41);
-
my $Count = substr ($file_contents[$i], 2,-38);
-
my $Address = substr ($file_contents[$i], 4,-35);
-
my $Data = substr ($file_contents[$i], 8,-3);
-
my $CSum = substr ($file_contents[$i], 40);
-
printf("\nType:$Type\nCount:$Count\nAddress:$Address\ndata:$Data\nCheckSum:$CSum");
-
}
-
}
-
-
Output:
-
===========
-
Type:S1
-
Count:130
-
Address:0000
-
data:FFFFFFFFFFFFFFFFFFF1111FFFFFFFFF
-
CheckSum:FC
-
-
Type:S1
-
Count:130
-
Address:0000
-
data:FFFFFFFFFFFFFFFFFFF2222FFFFFFFFF
-
CheckSum:FC
-
-
Type:S1
-
Count:130
-
Address:0000
-
data:FFFFFFFFFFFFFFFFFFF3333FFFFFFFFF
-
CheckSum:FC
-
-
==============================================
thank you jeff....
Regards
Lokesh....
============================ -
===========================
-
use warnings;
-
use strict;
-
{
-
-
my @file_contents;
-
open (INPUT, "sample.s37");
-
{
-
@file_contents = <INPUT>;
-
-
}
-
close(INPUT);
-
my $i;
-
for($i=0;$i<@file_contents-1;$i++)
-
{
-
my $Type = substr ($file_contents[$i], 0,-41);
-
my $Count = substr ($file_contents[$i], 2,-38);
-
my $Address = substr ($file_contents[$i], 4,-35);
-
my $Data = substr ($file_contents[$i], 8,-3);
-
my $CSum = substr ($file_contents[$i], 40);
-
printf("\nType:$Type\nCount:$Count\nAddress:$Address\ndata:$Data\nCheckSum:$CSum");
-
}
-
}
-
-
Output:
-
===========
-
Type:S1
-
Count:130
-
Address:0000
-
data:FFFFFFFFFFFFFFFFFFF1111FFFFFFFFF
-
CheckSum:FC
-
-
Type:S1
-
Count:130
-
Address:0000
-
data:FFFFFFFFFFFFFFFFFFF2222FFFFFFFFF
-
CheckSum:FC
-
-
Type:S1
-
Count:130
-
Address:0000
-
data:FFFFFFFFFFFFFFFFFFF3333FFFFFFFFF
-
CheckSum:FC
-
-
==============================================
thank you jeff....
Regards
Lokesh....
Well, you got the starting code tag good, but as per the example in the REPLY GUIDELINES, you completely missed the ending tag that is required. The ending tag is between the same "[" and "]" but has the text "/code". If you look at your posting (do a reply to it), you will see I have added the ending code tag.
Regards,
Jeff
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
8 posts
views
Thread by Gerrit Holl |
last post: by
|
2 posts
views
Thread by Cigdem |
last post: by
|
16 posts
views
Thread by Terry |
last post: by
|
reply
views
Thread by Pentti |
last post: by
|
9 posts
views
Thread by ankitdesai |
last post: by
|
5 posts
views
Thread by randy |
last post: by
|
3 posts
views
Thread by toton |
last post: by
|
13 posts
views
Thread by Chris Carlen |
last post: by
|
7 posts
views
Thread by Daniel Fetchinson |
last post: by
| | | | | | | | | | | |