Re: Doubt on Pattern Matching

2007-08-28 Thread Dharshana Eswaran
On 8/28/07, Chas Owens [EMAIL PROTECTED] wrote:

 On 8/28/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:
  When i write the condition
  my @m = $fullStruct =~ /$DLstatement/g;
  and try printing the array,
  print \nThe array is @m\n;
  It prints nothing This is the problem...
 
  Thanks and Regards,
  Dharshana
 snip
   That is not the behaviour I am seeing.  Please post a full example
   that demonstrates your problem.
 snip

 Again, please post the smallest complete program that exhibits the
 problem you are seeing as I cannot reproduce the problem you are
 talking about.




Actually, i was reading the input from a different location, and the input
was not being read properly. I found that out and corrected it. Thanks for
your suggestions. I am sorry that i was unable to produce a full program
regarding the issue.

Thanks and Regards,
Dharshana


Regex Issue

2007-08-28 Thread Dharshana Eswaran
Hi All,

I have written a program,

use strict;
use warnings;

my $Enum = typedef enum _SIGNAL_E
{
LEVEL_0_EV = 0,
LEVEL_1_EV,
LEVEL_2_EV,
LEVEL_3_EV,
LEVEL_4_EV,
LEVEL_5_EV
} SIGNAL_E;;

my $Enumidentifier = qr{ [A-Z0-9_]\w* }xs;
my $Enumstatement  = qr{
  \s*
($Enumidentifier)
 \s*
  =?
  \s*
 (\S+)?
,?
}xs;
 my @m = $Enum =~ /$Enumstatement/g;
 my $len = @m;
 for(my $i =0; $i$len; $i++) {
  print $m[$i]\n;
 }

The output for this program is

_SIGNAL_E
{
LEVEL_0_EV
0,
LEVEL_1_EV
,
LEVEL_2_EV
,
LEVEL_3_EV
,
LEVEL_4_EV
,
LEVEL_5_EV
}
SIGNAL_E
;

But i want to read only the elements of the Enum and the values assigned to
those elements. I dont want to read the Enum names and the extra characters.
I am unable to filter them.

The desired output is
LEVEL_0_EV
0
LEVEL_1_EV
LEVEL_2_EV
LEVEL_3_EV
LEVEL_4_EV
LEVEL_5_EV

Can anyone help me in correcting the regex?

Thanks and Regards,
Dharshana


Doubt on Pattern Matching

2007-08-27 Thread Dharshana Eswaran
Hi All,

I have a pattern, which reads as shown below:

my $comment= qr{\s* (?:/\* .*? \*/ \s*)*}xs;
my $identifier = qr{ [A-Za-z_]\w* }xs;
my $statement  = qr{
   \s*
   ($identifier)
   \s+
   ($identifier)
   \s*
   (?: \[ (.*?) \] )?
   \s*
   ;
   \s*
   $comment?
}xs;

my @m = $abc =~ /$statement/g;

My string reads as shown below:

$abc = typedef struct  _MSG_S
{
CALL_ID  callId; /** call id */
VOICE_STATUSstatus; /** Call status */
id_t   id;/** The id of process call */
} TAPI_VOICE_NOTIFY_CALL_STATUS_MSG_S;;


The condition $abc =~ /$statement/g; is not satisfied. The array @m is not
being filled.

I am unable to find out the mistake. Is the pattern regex wrong somewhere?

Thanks and Regards,
Dharshana


Re: Doubt on Pattern Matching

2007-08-27 Thread Dharshana Eswaran
When i write the condition
my @m = $fullStruct =~ /$DLstatement/g;
and try printing the array,
print \nThe array is @m\n;
It prints nothing This is the problem...

Thanks and Regards,
Dharshana
On 8/28/07, Chas Owens [EMAIL PROTECTED] wrote:

 On 8/28/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:
  Hi All,
 
  I have a pattern, which reads as shown below:
 
  my $comment= qr{\s* (?:/\* .*? \*/ \s*)*}xs;
  my $identifier = qr{ [A-Za-z_]\w* }xs;
  my $statement  = qr{
 \s*
 ($identifier)
 \s+
 ($identifier)
 \s*
 (?: \[ (.*?) \] )?
 \s*
 ;
 \s*
 $comment?
  }xs;
 
  my @m = $abc =~ /$statement/g;
 
  My string reads as shown below:
 
  $abc = typedef struct  _MSG_S
  {
  CALL_ID  callId; /** call id */
  VOICE_STATUSstatus; /** Call status */
  id_t   id;/** The id of process call */
  } TAPI_VOICE_NOTIFY_CALL_STATUS_MSG_S;;
 
 
  The condition $abc =~ /$statement/g; is not satisfied. The array @m is
 not
  being filled.
 
  I am unable to find out the mistake. Is the pattern regex wrong
 somewhere?
 
  Thanks and Regards,
  Dharshana
 


 That is not the behaviour I am seeing.  Please post a full example
 that demonstrates your problem.  The following code prints out:

 callId is of type CALL_ID
 status is of type VOICE_STATUS
 id is of type id_t

 as expected.

 #!/usr/bin/perl

 use strict;
 use warnings;


 my $comment= qr{\s* (?:/\* .*? \*/ \s*)*}xs;
 my $identifier = qr{ [A-Za-z_]\w* }xs;
 my $statement  = qr{
   \s*
   ($identifier)
   \s+
   ($identifier)
   \s*
   (?: \[ (.*?) \] )?
   \s*
   ;
   \s*
   $comment?
}xs;

 my $abc = typedef struct  _MSG_S
 {
CALL_ID  callId; /** call id */
VOICE_STATUSstatus; /** Call status */
id_t   id;/** The id of process call */
 } TAPI_VOICE_NOTIFY_CALL_STATUS_MSG_S;;

 while ($abc =~ /$statement/g) {
 my ($type, $name, $size) = ($1, $2, $3);
 $type = array of $type with $size elements if defined $size;
 print $name is of type $type\n;
 }



String Manipulation

2007-07-31 Thread Dharshana Eswaran
Hi All,

I have a string which reads
$str5 = DL_FEM_ADJ1 = DL_FEM_LINE_FIRST, /* Keep the adjacent ones
consecutive */;

Here i need to consider the variable and its value, ignoring the comment.

I have a pattern which reads

if($str5 =~ /\s*([A-Z_]+)\s=\s(\w+),*/) {
print $1 and $2\n;
}

The above works, if the string is DL_FEM_SCREEN_ADJ1 =
DL_FEM_SCREEN_NO_SECOND_LINE_FIRST, (without the comments)

I am unable to come up with a pattern which would ignore the comment and
gives me the substrings which i want. I need to read DL_FEM_SCREEN_ADJ1 and
DL_FEM_SCREEN_NO_SECOND_LINE_FIRST only.

The input string can either occur with comments or without comments, since
the input keeps changing. The input provided here is a sample input.

Can anyone please guide me in this?

Thanks and Regards,
Dharshana


Re: String Manipulation

2007-07-31 Thread Dharshana Eswaran
Oops!!! Sorry, It is ([A-Z0-9_]+). It was a typo in my mail.

And your suggestion worked. Thank you. But in the string which u had
suggested, [,\s*\/*]?, here \s* = tells spaces are optional, /\* sells the
beginning of the comment, I am unable to understand what these in a square
bracket along with a ? mean?

Thanks and Regards,
Dharshana

On 7/31/07, Andrew Curry [EMAIL PROTECTED] wrote:


 Try

 if($str5 =~ /\s*(\S+)\s*=\s*(\S+)[,\s*\/*]?/)

 I cant see how your

 ([A-Z_]+)
 Will match your DL_FEM_ADJ1 as this has a number on it?


 -Original Message-
 From: Dharshana Eswaran [mailto:[EMAIL PROTECTED]
 Sent: 31 July 2007 13:17
 To: Perl Beginners
 Subject: String Manipulation

 Hi All,

 I have a string which reads
 $str5 = DL_FEM_ADJ1 = DL_FEM_LINE_FIRST, /* Keep the adjacent ones
 consecutive */;

 Here i need to consider the variable and its value, ignoring the comment.

 I have a pattern which reads

 if($str5 =~ /\s*([A-Z_]+)\s=\s(\w+),*/) {
 print $1 and $2\n;
 }

 The above works, if the string is DL_FEM_SCREEN_ADJ1 =
 DL_FEM_SCREEN_NO_SECOND_LINE_FIRST, (without the comments)

 I am unable to come up with a pattern which would ignore the comment and
 gives me the substrings which i want. I need to read DL_FEM_SCREEN_ADJ1
 and
 DL_FEM_SCREEN_NO_SECOND_LINE_FIRST only.

 The input string can either occur with comments or without comments, since
 the input keeps changing. The input provided here is a sample input.

 Can anyone please guide me in this?

 Thanks and Regards,
 Dharshana


 This e-mail is from the PA Group.  For more information, see
 www.thepagroup.com.

 This e-mail may contain confidential information.  Only the addressee is
 permitted to read, copy, distribute or otherwise use this email or any
 attachments.  If you have received it in error, please contact the sender
 immediately.  Any opinion expressed in this e-mail is personal to the
 sender
 and may not reflect the opinion of the PA Group.

 Any e-mail reply to this address may be subject to interception or
 monitoring for operational reasons or for lawful business practices.







Re: String Manipulation

2007-07-31 Thread Dharshana Eswaran
Thanks Everyone for your suggestions. It really helped.

I shall freshen up from the documents  suggested to me.
But anyways, i would like to say, that unless any one works on any language,
mastering it is difficult. When i go through the tutorials or documents, i
seem to know. But practically, only when i work, i m getting to know more on
the language.

And I really thank the whole group for helping each other in learning Perl.

Thanks and Regards,
Dharshana

On 7/31/07, Paul Lalli [EMAIL PROTECTED] wrote:

 On Jul 31, 8:40 am, [EMAIL PROTECTED] (Dharshana Eswaran) wrote:
  And your suggestion worked. Thank you. But in the string which u had
  suggested, [,\s*\/*]?, here \s* = tells spaces are optional,

 No it doesn't.  The dirty dozen characters lose their special
 meaning inside of a character class.

  /\* tells the beginning of the comment,

 That's not what's in the pattern, and it wouldn't be correct even if
 it was.  The characters are \/*, not /\*.  The first is an escaped
 slash follwed by an asterisk, the second is a slash followed by an
 escaped asterisk.   The slash is still special because it's the regexp
 delimiter, and so needs to be escaped.  Your changing it is a syntax
 error.

  I am unable to understand what these in a square
  bracket along with a ? mean?

 The square brackets are a character class.  Essentially, a list of
 options.
 [,\s*\/*]?
 means 0 or 1 of either a comma, a space, an asterisk, a slash, or an
 asterisk.  Obviously, the two asterisks are redundant.

 You should freshen up on regular expressions:
 perldoc perlreref
 perldoc perlretut
 perldoc perlre

 Paul Lalli


 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/





Re: String Manipulation

2007-06-28 Thread Dharshana Eswaran

Thank you. But i am unable to understand the working of the code which you
have written. Can you please explain it?

Thanks and Regards,
Dharshana

On 6/28/07, Chas Owens [EMAIL PROTECTED] wrote:


On 6/27/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:
 On 6/28/07, Tom Phoenix [EMAIL PROTECTED] wrote:
 
  On 6/27/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:
 
   I am unable to get a generalised way in which it can extract them as
few
   structures have comments, few does not hav comments etc.
 
  Does the data have some defined grammar, or a definable one at least?



 The defined Grammer here is
 {
 xyz1 abc1; /*Comments*/
 xyz2 abc2;
 xyz3 abc3[req];
 xyz4 abc4[req]; /*Comments*/
 };

 Here, i have defined different possibility of occurences of the
structure
 elements. If i could get a regex for extracting xyz1, xyz2, xyz3, xyz4
and
 abc1, abc2, abc3[req], abc4[req] would be helpful. Here, the comments
are of
 no use, i just need to ignore them.

 If you are up to using Parse::RecDescent, it will probably do the job.

 I am restricted from using modules and i am unable to come up with a
regex
 or regexes to do this job.

   http://search.cpan.org/author/DCONWAY/Parse-RecDescent-1.94
 /lib/Parse/RecDescent.pod

 Hope this helps!

 --Tom Phoenix
 Stonehenge Perl Training

 Can anyone guide me in this?

 Thanks and Regards,
 Dharshana


It is fragile, but here are a set of regexes that parse the string you
mentioned.  I did notice that this string differs significantly from
the ones you gave earlier and this set of regexes will not correctly
handle them.

#!/usr/bin/perl

use strict;
use warnings;

my $comment= qr{\s* (?:/\* .*? \*/ \s*)*}xs;
my $identifier = qr{ [A-Za-z_]\w* }xs;
my $statement  = qr{
\s*
($identifier)
\s+
($identifier)
\s*
(?: \[ (.*?) \] )?
\s*
;
\s*
$comment?
}xs;

my $str = EOS;
{
xyz1 abc1; /*Comments*/
xyz2 abc2;
xyz3 abc3[req];
xyz4 abc4[req]; /*Comments*/
};
EOS

my @m = $str =~ /$statement/g;

my $iter = by_n(3, [EMAIL PROTECTED]);

while ((my ($type, $var, $elems) = $iter-()) == 3) {
if ($elems) {
$type = array of $type with $elems elements;
}
print type is $type and variable is $var\n;
}

sub by_n {
my ($n, $a) = @_;
my $i = 0;
sub {
return undef if $i  $#$a;
my @ret = @{$a}[$i .. $i + $n - 1];
$i += $n;
return @ret;
}
}



String Manipulation

2007-06-27 Thread Dharshana Eswaran

Hi All,

I have a string in which structures are stored. Each time i read a file,
different structure in stored in the string. The different possible
structures stored in the string is as shown:

$string = {
   STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_Tpp_reference_id;
   STACK_CC_SS_COMMON_TYPE_CM_LOCAL_CAUSE_T  generic_cause;
   STACK_CC_SS_COMMON_TYPE_CM_LOCAL_CAUSE_T  specific_cause;
   STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_Tchannel_info;
   STACK_REG_COMMON_TYPE_RAB_RB_INFO_T   rab_info;
   STACK_CC_SS_COMMON_TYPE_L3_MSG_UNIT_T pp_l3_msg;
} STACK_PRIMITIVE_MNCC_MESSAGE_T;
};;

or

$string = {
  UINT8  mms;  /* More messages to send */
  UINT8  transport_method;
  UINT8  mo_rpdu[STACK_MSG_COMMON_TYPE_TF_MAX_VAR_MSG_LEN];
} STACK_PRIMITIVE_MNSMS_EST_REQ_T;
};;

or

$string = {
   STACK_REG_COMMON_TYPE_REG_CAUSE_Tpp_reg_cause; /* Reason the
primitive was sent */
   STACK_REG_COMMON_TYPE_PLMN_T pp_plmn;  /* PLMN MS should
move to */
   STACK_REG_COMMON_TYPE_SIM_T  pp_sim_type;  /* Valid only on
BUTE */
   STACK_REG_COMMON_TYPE_NW_MENU_PARAMS_T   pp_nw_menu_params; /* Valid
only when pp_reg_cause is
* _CAUSE_NW_MENU_CHANGE,
_CAUSE_POWER_ON */
   BOOL  cingular_ens_sim_phone;  /* Valid when
pp_reg_cause is SIM_INSERT */
   BOOL  tty_enabled;/* Valid only on BUTE. This is
valid when the reg_cause
* is SIM_INSERT, POWERON
and BANDSWITCH.
* TRUE : restrict RAT to
GSM
* FALSE: Don't restrict RAT
to GSM
*/
} STACK_PRIMITIVE_MNMM_REG_REQ;
};,


From the above structures, i need to extract the data type and the variable

name of each structure seperately for further processing.
For Eg: Data Type is STACK_REG_COMMON_TYPE_REG_CAUSE_T
   Variable Name is  pp_reg_cause

I am unable to get a generalised way in which it can extract them as few
structures have comments, few does not hav comments etc.

I need to extract them and store that in a different variable for further
proccessing.

I kindly request all to guide me in this.

Thanks and Regards,
Dharshana


Re: String Manipulation

2007-06-27 Thread Dharshana Eswaran

On 6/28/07, Tom Phoenix [EMAIL PROTECTED] wrote:


On 6/27/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:

 I am unable to get a generalised way in which it can extract them as few
 structures have comments, few does not hav comments etc.

Does the data have some defined grammar, or a definable one at least?




The defined Grammer here is
{
xyz1 abc1; /*Comments*/
xyz2 abc2;
xyz3 abc3[req];
xyz4 abc4[req]; /*Comments*/
};

Here, i have defined different possibility of occurences of the structure
elements. If i could get a regex for extracting xyz1, xyz2, xyz3, xyz4 and
abc1, abc2, abc3[req], abc4[req] would be helpful. Here, the comments are of
no use, i just need to ignore them.


If you are up to using Parse::RecDescent, it will probably do the job.


I am restricted from using modules and i am unable to come up with a regex
or regexes to do this job.

 http://search.cpan.org/author/DCONWAY/Parse-RecDescent-1.94

/lib/Parse/RecDescent.pod



Hope this helps!



--Tom Phoenix
Stonehenge Perl Training


Can anyone guide me in this?

Thanks and Regards,
Dharshana


Regarding file handling

2007-06-21 Thread Dharshana Eswaran

Hi All,

I am reading a certain data from one file and writing to another file. In
the original file, there are few lines, which occur more than once in
different lines. When i am writing it to the second file, i don't want it to
be written more than once. I mean, it should not be repetitive. The file are
just two simple text files.

In achieving what i need, i thought simultaneous reading and writing to the
file is required, to know if the lines are being written for the second
time. But i don't know how to achieve this.

A sample of the text file is shown below:
STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
{
   STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
protocol_discriminator;
   STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;
} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;
};
STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T
{
   STACK_CC_SS_COMMON_TYPE_CHANNEL_TYPE_T channel_type;
   STACK_CC_SS_COMMON_TYPE_CHANNEL_MODE_T channel_mode;
} STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T;
};
STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
{
   STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
protocol_discriminator;
   STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;
} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;
};

Can anyone guide me in this?

Thanks and Regards,
Dharshana


Re: Regarding file handling

2007-06-21 Thread Dharshana Eswaran

On 6/21/07, Paul Lalli [EMAIL PROTECTED] wrote:


On Jun 21, 9:31 am, [EMAIL PROTECTED] (Dharshana Eswaran) wrote:
 Hi All,

 I am reading a certain data from one file and writing to another file.
In
 the original file, there are few lines, which occur more than once in
 different lines. When i am writing it to the second file, i don't want
it to
 be written more than once. I mean, it should not be repetitive. The file
are
 just two simple text files.

 In achieving what i need, i thought simultaneous reading and writing to
the
 file is required, to know if the lines are being written for the second
 time. But i don't know how to achieve this.

 A sample of the text file is shown below:
 STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
 {
 STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
 protocol_discriminator;
 STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T
transaction_id;} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;
 };

 STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T
 {
 STACK_CC_SS_COMMON_TYPE_CHANNEL_TYPE_T channel_type;
 STACK_CC_SS_COMMON_TYPE_CHANNEL_MODE_T channel_mode;}
STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T;
 };

 STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
 {
 STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
 protocol_discriminator;
 STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;

 } STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;
 };


It looks as though your data is delimited by };\n\n.  Is that
correct?  That is, each block of text ends with that string, and you
want to only print out the first instance of each block?  You can
control Perl's notion of what a line is via the $/ variable.  See
perldoc perlvar for more information.

To only print one instance of any given block, use a hash.  Each time
through your read loop, check to see if that block is in the hash.  If
it is, don't print it.  If it's not, do print it, and then add it to
the hash.  For example:

#!/usr/bin/perl
use strict;
use warnings;
open my $fh, '', infile.txt or die $!;
open my $ofh, '', outfile.txt or die $!;
local $/ = };\n\n;
my %printed;
while (my $record = $fh) {
   print $ofh $record unless $printed{$record}++;
}
__END__

Hope that helps,
Paul Lalli


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




I am unable to get the desired result. Its printing all the instances of the
block.

Thanks and Regards,
Dharshana


Re: Regarding file handling

2007-06-21 Thread Dharshana Eswaran

Actually my work is from the text file, i need to consider each entry in
every structure, and find its data type, to which its typedefed to and then
assign the values according to the value of the datatype. For eg:

A sample of the text file is shown below:
STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
{
   STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
protocol_discriminator;
   STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;
} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;
};
STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T
{
   STACK_CC_SS_COMMON_TYPE_CHANNEL_TYPE_T channel_type;
   STACK_CC_SS_COMMON_TYPE_CHANNEL_MODE_T channel_mode;
} STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T;
};
STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
{
   STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
protocol_discriminator;
   STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;
} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;
};



From the above text, i need to read

STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
and find to which data type this is type defed to and then asign the values
according to the value of the data type.

Here the basic data types are UINT8 and UINT16 which would read one and two
bytes respectively. All the other data types are type  defed to one of the
two.

My code in generating the file is as shown: this is just a module from the
original code

#!/usr/bin/perl
use strict;
use warnings;
$file = filename;
unless (open(INNER, $file)) {
   die(Cannot open file \n);
   }

unless (open(INN1, +outfile.txt)) {
   die(Cannot open file \n);
   }

   while ($innergrep = INNER) {
   chop($innergrep);
   while((($inn = index ($innergrep, typedef struct)) = 0)||(($inn =
index ($innergrep, typedef union)) = 0)) {
   $p = 0;
   while($inn = (index ($innergrep, }))  0) {
   $innergrep = INNER;
   chop($innergrep);
   $innerstore[$p] = $innergrep;
   $p++;
   }

   if($inn = (index ($innergrep, $innerB;)) = 0) {

   $innerlen = @innerstore;
   print INN1 $innerB\n;
   for(my $j=0; $j$p; $j++) {
   print INN1 $innerstore[$j]\n;

   }
   print INN1 };\n;


   }
   }
   }

The above code is just a small module from the original code. In the above
code, the file name is passed as an argument and it is stored in $file. From
the file which is specified, i need to search for the structure associated
with the primitive supplied in $innerB. As in the file the structure is
written as

STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
{
   STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
protocol_discriminator;
   STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;
} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;

The primitive name is found only at the end of the structure. So initially
read the contents, store it in a array and and then when the primitive name
in the structure matched with the primitive name passed here, then i write
it to the outfile.txt.
As, each time the primitive is passed through some variable, i am unable to
check the duplicate copies. That is, if the same primitive is passed again
and again, my code just gets the structure and stores it multiple times. I
want it to store only once. That is the problem.

I hope this describes the problem to all. I kindly request you to guide me
in this.

Thanks and Regards,
Dharshana


On 6/22/07, Tom Phoenix [EMAIL PROTECTED] wrote:


On 6/21/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:

 I am unable to get the desired result. Its printing all the instances of
the
 block.

Please post the smallest self-contained example program which other
people can use to see what you're doing, with what data. Ideally,
narrow things down to the one line of code or piece of data that does
something, or fails to do something, as appropriate. (For example, if
you're using the algorithm that Paul Lalli supplied, could two or more
very similar strings cause you mistakenly to think you're seeing
duplicate output?)

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training



Re: Regarding file handling

2007-06-21 Thread Dharshana Eswaran

My outfile should look like this:

STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T = UINT8,
   STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T = UINT8,
   STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T = UINT8,
   STACK_CC_SS_COMMON_TYPE_CHANNEL_TYPE_T = UINT8,
   STACK_CC_SS_COMMON_TYPE_CHANNEL_MODE_T = UINT8,
   STACK_CC_SS_COMMON_TYPE_CHANNEL_MODE_T = UINT8,
   STACK_REG_COMMON_TYPE_RAB_ID_T = UINT8,

But without repetitions


Thanks and Regards,
Dharshana

On 6/22/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:


Actually my work is from the text file, i need to consider each entry in
every structure, and find its data type, to which its typedefed to and then
assign the values according to the value of the datatype. For eg:

A sample of the text file is shown below:
STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
{
STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
protocol_discriminator;
STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;
} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;
};
STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T
{
STACK_CC_SS_COMMON_TYPE_CHANNEL_TYPE_T channel_type;
STACK_CC_SS_COMMON_TYPE_CHANNEL_MODE_T channel_mode;
} STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T;
};
STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
{
STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
protocol_discriminator;
STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;
} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;
};


From the above text, i need to read 
STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
and find to which data type this is type defed to and then asign the values
according to the value of the data type.

Here the basic data types are UINT8 and UINT16 which would read one and
two bytes respectively. All the other data types are type  defed to one of
the two.

My code in generating the file is as shown: this is just a module from the
original code

#!/usr/bin/perl
use strict;
use warnings;
$file = filename;
unless (open(INNER, $file)) {
die(Cannot open file \n);
}

unless (open(INN1, +outfile.txt)) {
die(Cannot open file \n);
}

while ($innergrep = INNER) {
chop($innergrep);
while((($inn = index ($innergrep, typedef struct)) = 0)||(($inn
= index ($innergrep, typedef union)) = 0)) {
$p = 0;
while($inn = (index ($innergrep, }))  0) {
$innergrep = INNER;
chop($innergrep);
$innerstore[$p] = $innergrep;
$p++;
}

if($inn = (index ($innergrep, $innerB;)) = 0) {

$innerlen = @innerstore;
print INN1 $innerB\n;
for(my $j=0; $j$p; $j++) {
print INN1 $innerstore[$j]\n;

}
print INN1 };\n;


}
}
}

The above code is just a small module from the original code. In the above
code, the file name is passed as an argument and it is stored in $file. From
the file which is specified, i need to search for the structure associated
with the primitive supplied in $innerB. As in the file the structure is
written as

STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
{
STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
protocol_discriminator;
STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;
} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;

The primitive name is found only at the end of the structure. So initially
read the contents, store it in a array and and then when the primitive name
in the structure matched with the primitive name passed here, then i write
it to the outfile.txt.
As, each time the primitive is passed through some variable, i am unable
to check the duplicate copies. That is, if the same primitive is passed
again and again, my code just gets the structure and stores it multiple
times. I want it to store only once. That is the problem.

I hope this describes the problem to all. I kindly request you to guide me
in this.

Thanks and Regards,
Dharshana


On 6/22/07, Tom Phoenix [EMAIL PROTECTED] wrote:

 On 6/21/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:

  I am unable to get the desired result. Its printing all the instances
 of the
  block.

 Please post the smallest self-contained example program which other
 people can use to see what you're doing, with what data. Ideally,
 narrow things down to the one line of code or piece of data that does
 something, or fails to do something, as appropriate. (For example, if
 you're using the algorithm that Paul Lalli supplied, could two or more
 very similar strings cause you mistakenly to think you're seeing
 duplicate output?)

 Good luck with it!

 --Tom Phoenix
 Stonehenge Perl Training





Regarding pattern matching

2007-05-24 Thread Dharshana Eswaran

Hi All,

I am trying to extract strings from few files. The content of the file reads
as shown

typedef struct
{
   REFID_T  pp_ref_id;  /* destination */
   CAUSE_T  pp_cause;/* Reason registered */
   STATE_T   pp_state; /* State for indicators */
   COMMON_TYPE_PLMN_Tpp_plmn_list[COMMON_TYPE_MAX];   /*
list for the user */
   TYPE_LAC_T pp_lac[COMMON_TYPE_MAX];
   TYPE_Tpp_cam;/* Cam for initiating only */
} NREG_IND;

I am extracting only the type and the variable names in different strings,
by using the command shown below:

..
...
$xyz = FILE;
$xyz =~ /\s*(\w+)\s+(\w+);/;
$a = $1; # type is stored here
$b = $2; #variable name is stored here

...

But the variables like pp_lac[COMMON_TYPE_MAX] and
pp_plmn_list[COMMON_TYPE_MAX] are not getting stored because of the special
character used inbetween the names.

Can i know what corrections to my regex would help me in extracting both
kinds of the variable names?

I kindly request to guide me in this.

Thanks and Regards,
Dharshana


Re: Regarding files

2007-05-21 Thread Dharshana Eswaran

Thank you all..

But i dont want to use any perl modules in the code. I am trying to get a
logic without any help from the additional modules.

Thanks and Regards,
Dharshana

On 5/21/07, Mumia W. [EMAIL PROTECTED] wrote:


On 05/20/2007 11:37 PM, Dharshana Eswaran wrote:
 Hi All,

 The below code helps in reading a file in reverse:

 use strict;
 use warning;

 open( FILE, $file_to_reverse )

  or die( Can't open file file_to_reverse: $! );

 @lines = reverse FILE;
 foreach $line (@lines) {
  # do something with $line
 }

 But i am trying to grep for a string in the file and once i get the
string,

 I need to read few lines which occurs before the string. For eg:

 typedef union
 {
TYPE_T type;
   MODE_T mode;
 } CHANNEL_INFO_T;

 Here, I grep for CHANNEL_INFO_T, once i get that, i need to read the
 elements defined in the union or structure.


 I have written a code but i am unable to achieve what i wanted.

 Can anyone guide me in this?

 Thanks and Regards,
 Dharshana


You could use Tie::File to treat the file's lines as an array:

 use strict;
 use warnings;
 use Fcntl 'O_RDONLY';
 require 'Tie/File.pm';

 tie my @file, 'Tie::File', 'anyfile.txt', mode = O_RDONLY
 or die(Tie::File failed: $!);

 for my $n (0 .. $#file) {
 local $\ = \n;
 $_ = $file[$n];
 if (/CHANNEL_INFO_T/) {
 print $file[$n-2];
 print $file[$n-1];
 print;
 }
 }

 untie @file;







--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





Re: Regarding files

2007-05-21 Thread Dharshana Eswaran

Keeping the classic (state machine) approach in mid, i tried writing a logic
for the same

But i am not able to retrieve the lines accurately,

Can you please help me with a small piece of code for the same logic which
you mentioned?

On 5/21/07, Dr.Ruud [EMAIL PROTECTED] wrote:


Dharshana Eswaran schreef:

 i am trying to grep for a string in the file and once i get the
 string, I need to read few lines which occurs before the string.

The classic (state machine) approach is to start storing strings from
the start marker, so typedef union here, and discard the stored lines
when the search string doesn't pop-up. Don't put the file in an array
first.

--
Affijn, Ruud

Gewoon is een tijger.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





Regarding files

2007-05-20 Thread Dharshana Eswaran

Hi All,

The below code helps in reading a file in reverse:

use strict;
use warning;

open( FILE, $file_to_reverse )

 or die( Can't open file file_to_reverse: $! );

@lines = reverse FILE;
foreach $line (@lines) {
 # do something with $line
}

But i am trying to grep for a string in the file and once i get the string,

I need to read few lines which occurs before the string. For eg:

typedef union
{
   TYPE_T type;
  MODE_T mode;
} CHANNEL_INFO_T;

Here, I grep for CHANNEL_INFO_T, once i get that, i need to read the
elements defined in the union or structure.


I have written a code but i am unable to achieve what i wanted.

Can anyone guide me in this?

Thanks and Regards,
Dharshana


Regarding pattern matching

2007-05-17 Thread Dharshana Eswaran

Hi All,

I am trying to extract few strings from a text file. The pattern of the text
stored in the file is as follows:

#define MNSS_FACILITY_IND_ID   (TF_MNSS_MESSAGE_CATEGORY + 0x01) /* @LOG
MNSS_MESSAGE_T */


I need to extract MNSS_FACILITY_IND_ID, TF_MNSS_MESSAGE_CATEGORY + 0x01 and
MNSS_MESSAGE_T.

I tried

next unless /#define\s+(\w+)\s+\(([^)]+)\s+\/[EMAIL PROTECTED](\w+)\*\//;

my $name = $1;
my ($base, $offset) = $2 =~ /\w+/g;
my $Struct = $3;

I am unable to find out the error.

Can anyone help m in this?

Thanks and Regards,
Dharshana


Re: Regarding pattern matching

2007-05-17 Thread Dharshana Eswaran

Thank you But i want to try without using any perl modules. Can you
suggest some way with no modules used in that?

Thanks and Regards,
Dharshana

On 5/17/07, Rob Coops [EMAIL PROTECTED] wrote:




On 5/17/07, Rob Coops [EMAIL PROTECTED] wrote:

 How about this?


 #!/usr/local/bin/perl

 use strict;
 use warnings;

 my $string = '#define MNSS_FACILITY_IND_ID
 (TF_MNSS_MESSAGE_CATEGORY + 0x01) /* @LOG MNSS_MESSAGE_T */';

 my @parts = $string =~ m/\s+?(\w+)\s+?\((\w+.*?)\)[EMAIL PROTECTED](\w+).*/;

 use Data::Dumper;

 print Dumper @parts;

 - Had to change that one \S to \s (oops) -

 OUTPUT
 -
 $VAR1 = 'NSS_FACILITY_IND_ID';
 $VAR2 = 'TF_MNSS_MESSAGE_CATEGORY + 0x01';
 $VAR3 = 'MNSS_MESSAGE_T';
 -



 On 5/17/07, Dharshana Eswaran [EMAIL PROTECTED]  wrote:
 
  Hi All,
 
  I am trying to extract few strings from a text file. The pattern of
  the text
  stored in the file is as follows:
 
  #define MNSS_FACILITY_IND_ID   (TF_MNSS_MESSAGE_CATEGORY + 0x01)
  /* @LOG
  MNSS_MESSAGE_T */
 
 
  I need to extract MNSS_FACILITY_IND_ID, TF_MNSS_MESSAGE_CATEGORY +
  0x01 and
  MNSS_MESSAGE_T.
 
  I tried
 
  next unless /#define\s+(\w+)\s+\(([^)]+)\s+\/[EMAIL PROTECTED](\w+)\*\//;
 
  my $name = $1;
  my ($base, $offset) = $2 =~ /\w+/g;
  my $Struct = $3;
 
  I am unable to find out the error.
 
  Can anyone help m in this?
 
  Thanks and Regards,
  Dharshana
 





Re: Regarding pattern matching

2007-05-17 Thread Dharshana Eswaran

Of Course Rob, i always use strict and warnings... Since i had to write a
pseudocode, i did not write them. But i wil lsurely keep this in mind. :-)
Thank you... :-)

On 5/17/07, Rob Coops [EMAIL PROTECTED] wrote:


Sure, though I do not see why you would not want to use strict and
warnings (you should should should or the people on this list will hunt you
down and ) anyway Data::Dumper was just there for convenience:


#!/usr/local/bin/perl

#use strict;
#use warnings;

my $string = '#define MNSS_FACILITY_IND_ID   (TF_MNSS_MESSAGE_CATEGORY
+ 0x01) /* @LOG MNSS_MESSAGE_T */';

my @parts = $string =~ m/\s+?(\w+)\s+?\((\w+.*?)\)[EMAIL PROTECTED](\w+).*/;

#use Data::Dumper;

#print Dumper @parts;

print $1 . \n . $2 . \n . $3 . \n;
print #- or -#\n;
foreach ( @parts ) { print $_ . \n; }



On 5/17/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:

 Thank you But i want to try without using any perl modules. Can you
 suggest some way with no modules used in that?

 Thanks and Regards,
 Dharshana

 On 5/17/07, Rob Coops [EMAIL PROTECTED] wrote:
 
 
 
  On 5/17/07, Rob Coops [EMAIL PROTECTED]  wrote:
  
   How about this?
  
  
   #!/usr/local/bin/perl
  
   use strict;
   use warnings;
  
   my $string = '#define MNSS_FACILITY_IND_ID
   (TF_MNSS_MESSAGE_CATEGORY + 0x01) /* @LOG MNSS_MESSAGE_T */';
  
   my @parts = $string =~ m/\s
   +?(\w+)\s+?\((\w+.*?)\)[EMAIL PROTECTED](\w+).*/;
  
   use Data::Dumper;
  
   print Dumper @parts;
  
   - Had to change that one \S to \s (oops) -
  
   OUTPUT
   -
   $VAR1 = 'NSS_FACILITY_IND_ID';
   $VAR2 = 'TF_MNSS_MESSAGE_CATEGORY + 0x01';
   $VAR3 = 'MNSS_MESSAGE_T';
   -
  
  
  
   On 5/17/07, Dharshana Eswaran [EMAIL PROTECTED]  wrote:
   
Hi All,
   
I am trying to extract few strings from a text file. The pattern
of the text
stored in the file is as follows:
   
#define MNSS_FACILITY_IND_ID   (TF_MNSS_MESSAGE_CATEGORY +
0x01) /* @LOG
MNSS_MESSAGE_T */
   
   
I need to extract MNSS_FACILITY_IND_ID, TF_MNSS_MESSAGE_CATEGORY +
0x01 and
MNSS_MESSAGE_T.
   
I tried
   
next unless
/#define\s+(\w+)\s+\(([^)]+)\s+\/[EMAIL PROTECTED](\w+)\*\//;
   
my $name = $1;
my ($base, $offset) = $2 =~ /\w+/g;
my $Struct = $3;
   
I am unable to find out the error.
   
Can anyone help m in this?
   
Thanks and Regards,
Dharshana
   
  
  
 




Regarding perl/tk programming

2007-05-15 Thread Dharshana Eswaran

Hi All,

I need to create a GUI and integrate my perl script to it. I decided to get
the GUI using perl/Tk programming. I searched in the net and i am unable to
get a good tutorial or any document regarding the perl/Tk programming.

If anyone knows any links or have any documents, can you please mail it to
me?

Thanks and Regards,
Dharshana


Query in pack and unpack functions

2007-05-03 Thread Dharshana Eswaran

Hi All,

My aim is to supply a hexadecimal value and print its binary value.

I have written a small piece of code for the same:

$input = 23; #any decimal value
$hex1 = sprintf (%x,$input);
$binary = unpack 'B*', pack 'H*', $hex1;
@fields1 = unpack 'A4A4', $binary;
print $fields1[1]   $fields1[0];# i need to print the Lower Nibble
first and then the Higher nibble

Output:
0111  0010

This works fine for any double digit number.

But this logic does not work with single digit number as input. When i give
a single digit number (for eg: 5) as input, it is stored as 0101 in
$binary variable instead of 0101.

Can anyone guide me in correcting this problem?

Thanks and Regards,
Dharshana


Re: Query in pack and unpack functions

2007-05-03 Thread Dharshana Eswaran

Thank you Dr.Ruud. It solved my problem. :-)

Thanks and Regards,
Dharshana

On 5/3/07, Dr.Ruud [EMAIL PROTECTED] wrote:


Dharshana Eswaran schreef:

 $input = 23; #any decimal value
 $hex1 = sprintf (%x,$input);
 $binary = unpack 'B*', pack 'H*', $hex1;
 @fields1 = unpack 'A4A4', $binary;
 print $fields1[1]   $fields1[0];# i need to print the Lower
 Nibble first and then the Higher nibble

 But this logic does not work with single digit number as input. When
 i give a single digit number (for eg: 5) as input, it is stored as
 0101 in $binary variable instead of 0101.

$hex1 = sprintf q{%02X}, $input ;

--
Affijn, Ruud

Gewoon is een tijger.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





Accessing packed data structures

2007-03-13 Thread Dharshana Eswaran

Hi all,

I was going thro the topic Accessing packed data structures in the Perl
Complete Reference Book. I came across this example:

struct utmp {
char ut_user[8]; /* User login name */
char ut_id[4]; /* /etc/inittab id */
char ut_line[12]; /* device name */
short ut_pid; /* process ID */
short ut_type; /* type of entry */
struct exit_status ut_exit; /* The exit status of a process */
/* marked as DEAD_PROCESS. */
time_t ut_time; /* time entry was made */
};

For the above structure:

The pack template given was a8a4a12l.

my $packstring = a8a4a12l;
my $reclength = length(pack($packstring));
my @ut_types = qw(EMPTY RUN_LVL BOOT_TIME OLD_TIME
NEW_TIME INIT_PROCESS LOGIN_PROCESS
USER_PROCESS DEAD_PROCESS ACCOUNTING);
open(D,/var/adm/wtmp) or die Couldn't open wtmp, $!;
while(sysread(D,my $rec,$reclength))
{
my ($user,$userid,$line,$pid,$type,$eterm,$eexit,$time)
= unpack($packstring,$rec);
print($user, $userid, $line, $pid, $ut_types[$type], ,
$eterm, $eexit, , scalar localtime($time),\n);
}
close(D) or die Couldn't close wtmp, $!;


I am, somehow, not able to understand how to generate the pack template from
the structure's data types. I understand that we need to refer to the table
in which each character in described (for eg: A - An ASCII string, will be
space padded)

Here, how does the pack and unpack play its role? What format should the
input be in? What are the possible formats it can accept here?

I kindly request anyone to explain me this concept.

Thanks and Regards,
Dharshana


Re: Accessing packed data structures

2007-03-13 Thread Dharshana Eswaran

On 3/13/07, Tom Phoenix [EMAIL PROTECTED] wrote:


On 3/13/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:

 I was going thro the topic Accessing packed data structures in the
Perl
 Complete Reference Book. I came across this example:

 struct utmp {
 char ut_user[8]; /* User login name */
 char ut_id[4]; /* /etc/inittab id */
 char ut_line[12]; /* device name */
 short ut_pid; /* process ID */
 short ut_type; /* type of entry */
 struct exit_status ut_exit; /* The exit status of a process */
 /* marked as DEAD_PROCESS. */
 time_t ut_time; /* time entry was made */
 };

 For the above structure:

 The pack template given was a8a4a12l.

 I am, somehow, not able to understand how to generate the pack template
from
 the structure's data types.

The pieces match up this way:

char ut_user[8]; /* User login name: a8 */
char ut_id[4]; /* /etc/inittab id: a4 */
char ut_line[12]; /* device name: a12 */
short ut_pid; /* process ID: s */
short ut_type; /* type of entry: s */
struct exit_status ut_exit; /* The exit status of a process */
/* marked as DEAD_PROCESS: s s */
time_t ut_time; /* time entry was made: l */

A char array becomes an a42, with the number being the length of the
array. A short becomes s, and a long becomes l. (You do need to know
something about how C stores data in memory. Note that exit_status and
ut_exit are two variables, even though they are declared on the same
line; that's why there are two s's in the comment.)

 Here, how does the pack and unpack play its role? What format should the
 input be in? What are the possible formats it can accept here?

Have you seen the documentation for pack and unpack? There is a large
table of format letters. Are you asking for something else?

Do you have a C struct that you can't translate to a pack/unpack
template? If so, feel free to post it here. Someone will know how to
deal with it.

Yes, you are right...


I have a structure and it is somethiung like this

typedef struct  _TAPI_VOICE_NOTIFY_INCOMING_CALL_MSG_S

   TAPI_CALL_ID_T  callId;
   TAPI_VOICE_INCOMING_CALL_TYPE_E type;
   TAPI_PHONE_NUMBER_A phoneNumber;
   TAPI_CALL_LINE_ElineNo;
   TAPI_PHONEBOOK_NAME_A   alpha;
   } TAPI_VOICE_NOTIFY_INCOMING_CALL_MSG_S;

Here the typedefs are:

TAPI_CALL_ID_T, TAPI_PHONE_NUMBER_A, TAPI_PHONEBOOK_NAME_A   = Unsigned int
8
TAPI_VOICE_INCOMING_CALL_TYPE_E = enum type
TAPI_CALL_LINE_E  = signed int 8

Now how do i come up with the pack template? I dont know how a enum should
be represented in the pack template. :-(

/I8(enum)I8i8I8/ = pack template

The above mentioned enum just contains two elements.

The data which i need to pack and unpack to these elements are in hex
format(0x0B 0x1C 0x34 etc). It is a string of hex bytes.

I kindly request anyone to guide me in this.

Thanks and Regards,
Dharshana


Re: Accessing packed data structures

2007-03-13 Thread Dharshana Eswaran

On 3/14/07, Chas Owens [EMAIL PROTECTED] wrote:


On 3/14/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:
snip
 Now how do i come up with the pack template? I dont know how a enum
should
 be represented in the pack template. :-(

 /I8(enum)I8i8I8/ = pack template

 The above mentioned enum just contains two elements.

 The data which i need to pack and unpack to these elements are in hex
 format(0x0B 0x1C 0x34 etc). It is a string of hex bytes.

 I kindly request anyone to guide me in this.

 Thanks and Regards,
 Dharshana


In ANSI C enums are of type int.






The data which i need to pack and unpack to these elements are in hex
format(0x0B 0x1C 0x34 etc). It is a string of hex bytes.



Can i know about the format in which i need to supply the input? Coz i am
unable to accept the hex string.

Thanks and Regards,
Dharshana


Query on pattern matching

2007-03-08 Thread Dharshana Eswaran

Hi all,

I need to extract few strings from one file and paste it to another file.

My source file, i.e., my .h file, contains statements like:

#define GMMREG_ATTACH_REQ_ID  (GMMREG_PRIM_ID_BASE)   /*
@LOG GMMREG_ATTACH_REQ   */
#define GMMREG_DETACH_REQ_ID  (GMMREG_PRIM_ID_BASE | 0x0001)  /*
@LOG GMMREG_DETACH_REQ   */
/* GMMREG primitives sent by the MM sub-layer to the MMI */
#define GMMREG_ATTACH_CNF_ID  (GMMREG_PRIM_ID_BASE | 0x0010)  /*
@LOG GMMREG_ATTACH_CNF   */
#define GMMREG_DETACH_CNF_ID  (GMMREG_PRIM_ID_BASE | 0x0011)  /*
@LOG GMMREG_DETACH_CNF   */
#define CCL2D_INIT_NCNF_ID  (L2D_PRIM_ID_BASE+5)  /* @LOG
CCL2D_INIT_NCNF  */
#define CCL2D_INIT_RESP_ID  (L2D_PRIM_ID_BASE+6)  /* @LOG
CCL2D_INIT_RESP  */

Basically it defines a set of message names(GMMREG_DETACH_CNF_ID) to its hex
values((GMMREG_PRIM_ID_BASE | 0x0011) ). here GMMREG_PRIM_ID_BASE is
initialized to some value.


From this file i need to extract three strings from each line. they are

1. GMMREG_ATTACH_REQ_ID
2. GMMREG_PRIM_ID_BASE
3. 0x0001 = this string can be of 2 digits or 4 digits or sometimes it can
be a 2 digit decimal number too.

the 3rd string is sometimes is not present.

Once these are extracted, i can process it further to the requirement.

I tried reading each line, splitting it using spaces, grouping them using
pattern matching and then displaying. The code, which i wrote for this, is
written at the end of this mail.

But i am facing a issue like, the header file need not have spaces as in
every line.
A line can read like: #define GMMREG_DETACH_IND_ID
(GMMREG_PRIM_ID_BASE
| 0x0030)  /* @LOG DETACH_IND  */

It can also read like: #define CCL2D_INIT_NCNF_ID
(L2D_PRIM_ID_BASE+5)  /* @LOG CCL2D_INIT_NCNF  */

So because of the same all the patterns are not getting identified.

Since i am using spaces as delimiters here, i am facing problems.

I tried using | or + or ( or ), but i am unable to get a proper
working logic with these delimiters.

Can anyone suggest any solution for this?

Thanks and Regards,
Dharshana


P.S:

My code reads:

#!/usr/bin/perl

unless (open(L3L4IN, tf_l3l4_message_ids.h )) {
   die(Cannot open input file \n);
}
while($in = L3L4IN) {
@array = split(/, $in);
$length = @array;

@final_result = split (/ +/, $array[0]);


$res_len = @final_result;
$entry1 = $entry2 = $entry3 = $entry4 = $entry5 = 0;

for($j=0; $j$res_len; $j++) {
   if($final_result[$j] =~ m/^ [A-Z]+ (?:_[A-Z]+)+ $/x) {
   $entry1 = $result[$j];
   }
   elsif($final_result[$j] =~ m/^ \( [A-Z]+ (?:_[A-Z]+)+ $/x) {
   $str1_length = length($result[$j]);
   $a1 = substr($result[$j], 1, $str1_length);
   $entry2 = $a1;
   }
   elsif($final_result[$j] =~ m/0x(\S{4})/g) {
   $str2_length = length($result[$j]);
   $a2 = substr($result[$j], 0, $str2_length-1);
   $val = hex($a2);
   $entry3 = $val;

   }
   elsif($final_result[$j] =~ m/0x(\S{2})/g) {
   $str4_length = length($result[$j]);
   $a4 = substr($result[$j], 0, $str4_length-1);
   $val2 = hex($a4);
   $entry5 = $val2;

   }
   elsif($final_result[$j] =~ m/(\d{2})/g) {
   $str3_length = length($result[$j]);
   $a3 = substr($result[$j], 0, $str3_length-1);
   $val1 = int($a3);

   $entry4 = $val1;

   }

}

if(($entry1 ne 0)($entry2 ne 0)($entry3 ne 0)) {
   $entry_value1 = ($hash{$entry2}|$entry3);
   $entry_value = sprintf(%x, $entry_value1);
   print $entry_value , $entry1\n;
}
elsif(($entry1 ne 0)($entry2 ne 0)($entry4 ne 0)) {
   $entry_value1 = ($hash{$entry2}|$entry4);
   $entry_value = sprintf(%x, $entry_value1);
   print $entry_value , $entry1\n;
}
elsif(($entry1 ne 0)($entry2 ne 0)($entry5 ne 0)) {
   #print $hash{$entry2} = $entry5\n;
   $entry_value1 = ($hash{$entry2}|$entry5);
   $entry_value = sprintf(%x, $entry_value1);
   print $entry_value , $entry1\n;
}
}


Re: Query on pattern matching

2007-03-08 Thread Dharshana Eswaran

On 3/9/07, John W. Krahn [EMAIL PROTECTED] wrote:


Chas Owens wrote:
 On 3/8/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:

 I need to extract few strings from one file and paste it to another
file.
 snip

 This doesn't seem like a good job for split.  The split function is
 good for parsing X separated records where X is either constant or
 simple.  What you have there a grammar.  Specifically a subset of the
 C grammar for #define.  With grammars you want to use either a regex
 or Parse::RecDescent depending on the complexity of the grammar.  In
 this case the grammar is simple enough that a regex does fine.  I have
 created a regex that parses your record into a name, base number,
 operator, and modifying number.  The last two values are optional.  I
 have used the x option on the regex to make it readable since it is so
 large (anything bigger than 80 characters should probably use the x
 option).  You can learn more about regexes in perldoc perlre and
 perldoc perlretut.

 #!/usr/bin/perl

 use strict;
 use warnings;

 while (DATA) {
my ($name, $base, $op, $mod) = m{
^ # start of string
\s*   # optional spaces
\#define  # the start of the macro

The C preprocessor allows whitespace between '#' and 'define'.

\# \s* define  # the start of the macro


\s+   # mandatory spaces
(\w+) # capture the name of the macro
\s*   # optional spaces

If the next token is a left parenthesis then the whitespace is not
optional
otherwise it would be a macro definition.  Also, if the next token is a
word
character then the whitespace is not optional.


\(# the open paren
\s*   # optional spaces
(
\w+ |
\d+ |
0x[a-fA-F0-9]

That only matches a single hexadecimal digit, you probably want
0x[a-fA-F0-9]+
instead.


) # capture a word, int, or hex
\s*   # optional spaces
(?:
( # capture the various int operators
[+-|^*/%] |

 [+-|^*/%] |


|

)

What about:

TOKEN  ~TOKEN

Or:

TOKEN * -TOKEN

:-)

\s*   # optional spaces
( # capture a word, int, or hex
\w+ |
\d+ |
0x[a-fA-F0-9])

 0x[a-fA-F0-9]+)


)?# but make the last two captures
 optional
\)# the close paren
}x;
$op = $mod = '' unless defined $op;
print;
print \tname is $name, base is $base, modified by $mod using
$op\n
if $name;
 }



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





Thank you for the suggestions. I tried both ways.



 0x[a-fA-F0-9]

That only matches a single hexadecimal digit, you probably want
0x[a-fA-F0-9]+
instead.

When i tried Chas's idea, without this correction itself i could get the hex
values more than a digit.

But i did not understand the below lines mentioned by John.
What about:

TOKEN  ~TOKEN

Or:

TOKEN * -TOKEN

:-)

Can you please explain it?

Thanks once again for the immediate response.


Thanks and Regards,
Dharshana


Working with files

2007-02-22 Thread Dharshana Eswaran

Hello All,

I need to search a particular string in a set of files in a directory. The
string appears only in one of the files in the directory.
I need to retrieve the file name and then access the line of that
particular file in which the string occurs.

NOTE: The perl script also resides in the same directory.

For Eg: I am in search of string $string = PERL_BEGINNER;
i have a directory = /Users/ and the files in that directory are:
1. Beginners.h
2. Learners.h
3. Experts.h
4. etc

Among these files $string occurs only in one of the files. If we assume that
it occurs in Beginners.h

then Beginners.h has to be opened and the $string has to be searched in that
file.

Can i know how i can go about this in Perl? What functions i might have to
use?

I kindly request to guide me in this.

Thanks and Regards,
Dharshana


Re: Working with files

2007-02-22 Thread Dharshana Eswaran

On 2/22/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:


Hello All,

I need to search a particular string in a set of files in a directory. The
string appears only in one of the files in the directory.
 I need to retrieve the file name and then access the line of that
particular file in which the string occurs.

NOTE: The perl script also resides in the same directory.

For Eg: I am in search of string $string = PERL_BEGINNER;
i have a directory = /Users/ and the files in that directory are:
 1. Beginners.h
 2. Learners.h
 3. Experts.h
 4. etc

Among these files $string occurs only in one of the files. If we assume
that it occurs in Beginners.h

then Beginners.h has to be opened and the $string has to be searched in
that file.

Can i know how i can go about this in Perl? What functions i might have to
use?

I kindly request to guide me in this.

Thanks and Regards,
Dharshana



I forgot to mention, First step is to Search for the file in which the
string occurs

Second step is to Open the file in which the string is present

Third Step is to Get the file pointer to the line in which the string
occurs.

NOTE: I might have to use the code both in Unix and Windows platform. I dont
have a problem if i have two different solutions for each of the platforms
or if one solution for both the platforms.

I kindly request to guide me in this.

Thanks and Regards,
Dharshana


Re: Pattern matching

2007-02-21 Thread Dharshana Eswaran

On 2/21/07, Dr.Ruud [EMAIL PROTECTED] wrote:


Dharshana Eswaran schreef:

 TAPI_VOICE_NOTIFY_OTHERAPP_JOINING_MSGID
 TAPI_TTY_NOTIFY_TTY_TONE_MSGID
 [...]
 Can anyone help me in getting a generalised pattern from these?

  m/^ TAPI (?:_[A-Z]+)+ $/x

--
Affijn, Ruud

Gewoon is een tijger.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Thank you Dr.Ruud.


I just noticed one problem here,

I have a few strings which is similar to those but starts with a #TAPI_
for eg: #TAPI_ACCE_NOTIFY_TIME_CHANGED_MSG_S
#TAPI_CPHS_NOTIFY_WAITTING_MSG_S
#TAPI_NETWORK_SIGNAL_E etc...

So i tried the same pattern as what you suggested with a little change in
it,

m/^ #TAPI (?:_[A-Z]+)+ $/x

But this is filtering both the strings starting from TAPI and the strings
starting from #TAPI.

Can i know how to filter the strings starting from #TAPI seperately and TAPI
seperately?

Thanks and Regards,
Dharshana


Re: Pattern matching

2007-02-21 Thread Dharshana Eswaran

On 2/21/07, Dharshana Eswaran [EMAIL PROTECTED] wrote:




On 2/21/07, Dr.Ruud [EMAIL PROTECTED] wrote:

 Dharshana Eswaran schreef:

  TAPI_VOICE_NOTIFY_OTHERAPP_JOINING_MSGID
  TAPI_TTY_NOTIFY_TTY_TONE_MSGID
  [...]
  Can anyone help me in getting a generalised pattern from these?

   m/^ TAPI (?:_[A-Z]+)+ $/x

 --
 Affijn, Ruud

 Gewoon is een tijger.

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/


 Thank you Dr.Ruud.

I just noticed one problem here,

I have a few strings which is similar to those but starts with a
#TAPI_
for eg: #TAPI_ACCE_NOTIFY_TIME_CHANGED_MSG_S
#TAPI_CPHS_NOTIFY_WAITTING_MSG_S
#TAPI_NETWORK_SIGNAL_E etc...

So i tried the same pattern as what you suggested with a little change in
it,

m/^ #TAPI (?:_[A-Z]+)+ $/x

But this is filtering both the strings starting from TAPI and the strings
starting from #TAPI.

Can i know how to filter the strings starting from #TAPI seperately and
TAPI seperately?

Thanks and Regards,
Dharshana



Sorry for this previous mail. That was a silly mistake in my code. That
works

Thanks for the help.

Regards,
Dharshana


Re: Is there any way to use C header files in perl program?

2007-02-20 Thread Dharshana Eswaran

On 2/20/07, Peter Scott [EMAIL PROTECTED] wrote:


On Tue, 20 Feb 2007 12:19:22 +0530, Dharshana Eswaran wrote:

 Hello All,

 I need to use a C header file in Perl program in Unix.

 Is it possible to use the header files from perl in any way? I do not
want
 to use any modules for the same.

 I do not want to enable the perl program to call a routine in C library
 through XS. I just want to use the values rather than any code.

If you were talking about just #define, I'd say

http://search.cpan.org/~gbarr/Include-1.02a/Include.pm

But:

 For example, Consider headerfile.h:

 struct sample {
 int x;
 };

 Then in my C program I might do the following:
 printf(The size of a headerfile is %d\n,sizeof(headerfile));
 Can i do the same in Perl?

I am having a hard time picturing what you might use this for in Perl.
You might look at h2ph, which comes with perl.  I also suggest reading
http://xrl.us/uzcs (Link to www.amazon.com).

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Thank you. I shall check the link and have a knowledge on it.

Actually, i just came up with an idea of merging the C header files in Perl.
And searched in net, since i could not get a proper solution, i mailed to
the list. It was just my idea and not for implementation. Wanted to learn
more on that.

Anyways, thanks once again.


Regards,
Dharshana


Pattern matching

2007-02-20 Thread Dharshana Eswaran

Hello All,

I have quite a number of strings which has some typical matches between
them. I am unable to come up with a generalised pattern for them.

Few among those strings are like this:

TAPI_VOICE_NOTIFY_OTHERAPP_JOINING_MSGID
TAPI_TTY_NOTIFY_TTY_TONE_MSGID
TAPI_NOTIFY_CALL_LINE_INFO_MSGID
TAPI_SMS_NOTIFY_RECV_ORANGE_MOSES_SM_MSGID
TAPI_SIM_NOTIFY_FIXDIALING_STATUS_REFRESHED_MSGID
TAPI_APP_ASYNC_SIM_MSG_GRPID_END
TAPI_POWER_NOTIFY_OFF_MSGID

The similarities among them are

1. All alphabets are in caps
2. It has one underscore between a grp of alphabets...
3. All the strings start from TAPI



Can anyone help me in getting a generalised pattern from these?


Thanks and Regards,
Dharshana


Is there any way to use C header files in perl program?

2007-02-19 Thread Dharshana Eswaran

Hello All,

I need to use a C header file in Perl program in Unix.

Is it possible to use the header files from perl in any way? I do not want
to use any modules for the same.

I do not want to enable the perl program to call a routine in C library
through XS. I just want to use the values rather than any code.


For example, Consider headerfile.h:

Within that header file, i define a structure like this:

struct sample {
   int x;
};

Then in my C program I might do the following:

#include stdio.
#include headerfile.h

int
main(void)
{
   printf(The size of a headerfile is %d\n,sizeof(headerfile));
   return 0;
}

Can i do the same in Perl?

I kindly request to guide me in the same.

Thanks and Regards,
Dharshana


Re: Pattern Matching

2007-01-21 Thread Dharshana Eswaran

On 1/19/07, Igor Sutton [EMAIL PROTECTED] wrote:


I have an update:

 my @data = $string =~ m/0x(\d{2})/g;

my @data = $string =~ m/0x(\S{2}),?/g;

Now I think it is right :)

--
Igor Sutton Lopes [EMAIL PROTECTED]



I used the above expression and it worked for me. Thanks you so much.

Thanks and Regards,
Dharshana


Re: Pattern Matching

2007-01-21 Thread Dharshana Eswaran

On 1/19/07, Rob Dixon [EMAIL PROTECTED] wrote:


Igor Sutton wrote:
 I have an update:

 my @data = $string =~ m/0x(\d{2})/g;

 my @data = $string =~ m/0x(\S{2}),?/g;

 Now I think it is right :)

my @data = $string =~ m/=0x(..)/g;

:)

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





Thanks for the alternative option.

Thanks and Regards,
Dharshana


Re: Pattern Matching

2007-01-21 Thread Dharshana Eswaran

On 1/19/07, John W. Krahn [EMAIL PROTECTED] wrote:


Dharshana Eswaran wrote:
 Hi All,

Hello,

 I have a string as shown below:

 $string =

{[0]=0x53,[1]=0x65,[2]=0x63,[3]=0x75,[4]=0x72,[5]=0x69,[6]=0x74,[7]=0x79,[8]=0x43,[9]=0x6F,[10]=0x64,[11]=0x65,[12]=0x00}


 This is stored as a string in a variable. I need to pull out only the
 numbers and store them in a array. Like:

 @array = (53, 65, 63, 75, 72, 69, 74, 79, 43, 6F, 64, 65, 00);

 I am unable to get a pattern to try pattern matching and spliting
it.

 How do i do this?

$ perl -le'
my $string =

{[0]=0x53,[1]=0x65,[2]=0x63,[3]=0x75,[4]=0x72,[5]=0x69,[6]=0x74,[7]=0x79,[8]=0x43,[9]=0x6F,[10]=0x64,[11]=0x65,[12]=0x00};

my @array = $string =~ /[[:xdigit:]]{2}/g;

print @array;
'
53 65 63 75 72 69 74 79 43 6F 10 64 11 65 12 00




John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





Thank you John.

Thanks and Regards,
Dharshana


Pattern Matching

2007-01-19 Thread Dharshana Eswaran

Hi All,

I have a string as shown below:

$string =
{[0]=0x53,[1]=0x65,[2]=0x63,[3]=0x75,[4]=0x72,[5]=0x69,[6]=0x74,[7]=0x79,[8]=0x43,[9]=0x6F,[10]=0x64,[11]=0x65,[12]=0x00}

This is stored as a string in a variable. I need to pull out only the
numbers and store them in a array. Like:

@array = (53, 65, 63, 75, 72, 69, 74, 79, 43, 6F, 64, 65, 00);

I am unable to get a pattern to try pattern matching and spliting it.

How do i do this?

Thanks and Regards,
Dharshana


Calling a perl program from a perl script

2007-01-10 Thread Dharshana Eswaran

Hi All,

I Have a perl program which runs successfully and gets the required output.

I need to call that program from a perl script. I tried this using eval
function. But it failed.

Can i know how to do this?

Can anyone guide me in this?

Thanks and Regards,
Dharshana


Re: Calling a perl program from a perl script

2007-01-10 Thread Dharshana Eswaran

On 1/11/07, Jeff Pang [EMAIL PROTECTED] wrote:



I Have a perl program which runs successfully and gets the required
output.

I need to call that program from a perl script. I tried this using eval
function. But it failed.

 Can i know how to do this?

Can anyone guide me in this?


It's maybe good to define the called program to be a perl module/lib,then
access the subroutines in the module by OO way.

--
Books below translated by me to Chinese.
Practical mod_perl: http://home.earthlink.net/~pangj/mod_perl/
Squid the Definitive Guide: http://home.earthlink.net/~pangj/squid/




Hi all,

I need to call the perl program and i have to pass arguments too along with
the calling. And the called perl program has to return values too.

Can i do this without converting the called program into module?

Thanks and Regards,
Dharshana


Reversing Digits

2007-01-08 Thread Dharshana Eswaran

Hi all,

I was trying to reverse the digits.

For eg: if i have 50, i wanted to print 05

Can anyone tell me a simple way?

Thanks and Regards,
Dharshana


Ragarding regular expression

2007-01-04 Thread Dharshana Eswaran

Hi,

I have an array which reads as follows:

@array = (01, 45,  02, 57,  03);

When i try to print this array, it prints the single digit value as

1, 45, 2, 57, 3

But i want it to print like

01, 45, 02, 57, 03

I can use if condition and then try printing the value as double digit, but
i was thinking of a better way. Can anyone suggest me a more efficient way?

Thanks and Regards,
Dharshana


Re: Syswrite Function in Perl

2007-01-02 Thread Dharshana Eswaran

On 1/3/07, John W. Krahn [EMAIL PROTECTED] wrote:


Dharshana Eswaran wrote:
 Hi All,

Hello,

 I have a piece of code which reads as shown below:

 unless (open(IN, in.txt)) {
die(Cannot open input file \n);

You should include the $! variable in the error message so you know *why*
it
failed.

}
 binmode(IN);

You appear to be reading from a text file so why binmode?

 unless (open(OUT, +output.txt)) {
die(Cannot open input file input.txt\n);

You should include the $! variable in the error message so you know *why*
it
failed.

}

 %structure = (1 = A, 2 = B, 3 = C,
);
 @keys = keys %structure;
 %table = (A = 4, B = 8, C = 32,
);
 $j=0;

 print(ENTER THE SEQUENCE between[1-3]:\n);
 $seq = STDIN;
 chop($seq);

You should use chomp() instead of chop().

 @seq = split(/ +/, $seq);
 $seq_len = @seq;

 $input = IN;
 @input = split(/ +/, $input);
 $new = join (, @input);

Why not just modify the string instead of splitting and joining:

( my $new = IN ) =~ s/ +//g;

 for($i=0; $i$seq_len; $i++) {
$read1[$i] = $table{$structure{$seq[$j]}};
syswrite (OUT, $new, $read1[$i]);
print OUT (\n);

perldoc -f syswrite
syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
syswrite FILEHANDLE,SCALAR,LENGTH
syswrite FILEHANDLE,SCALAR
Attempts to write LENGTH bytes of data from variable SCALAR to
the
specified FILEHANDLE, using the system call write(2).  If
LENGTH
is not specified, writes whole SCALAR.  It bypasses buffered
IO,


so mixing this with reads (other than sysread()), print,
^^
write, seek, tell, or eof may cause confusion because
the

^
perlio and stdio layers usually buffers data.  Returns the
number
^
of bytes actually written, or undef if there was an error
(in
this case the errno variable $! is also set).  If the LENGTH
is
greater than the available data in the SCALAR after the
OFFSET,
only as much data as is available will be written.


You are using syswrite() *and* print() on the same filehandle which you
shouldn't do.

$j++;
 }

 In the above code, i m trying to read the input in bytes

It *looks* like you are reading lines of text?

 and display
 them in another output file. The reading is done in different sizes
 (4 or 8 or 32bytes), as per the sequence specifed by the User. The
 input file with filehandle IN contains data as shown below:

 F1 2F 8A 02 05 09 00 00 00 04 2B 48 00 00 00 68


 When i use syswrite function, i face the following problem

 syswrite (OUT, $new, 4); = Writes 4 bytes properly
 syswrite (OUT, $new, $val); (where $val =4;) = Writes 4 bytes properly
 syswrite (OUT, $new, $read1[$i]); = This does not work. It displays all
 the
 bytes together, without seperators(new line). I dont know the reason.

 Can anyone please guide me in this?

When I run your code it seems to work for me, so what exactly is not
working?



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Hi John,

Thanks for the suggestions regarding the code. I still need to learn to
optimize the code.

When I run your code it seems to work for me, so what exactly is not
working?

The output what i m getting is

The input file contains message as follows:

D0 1A 81 03 01 21 80 82 02 81 02 8D 0F 04 54 6F 6F 6C 6B 69 74 20 54 65 73

Sample output:

ENTER THE SEQUENCE between[1-3]:
2 1 1 3

The output file contains:

D01A8103012180820281028D0F04546F

I am unable to give spaces between each entry in the output.I need the
output in steps...

Something like:
D01A8103
0121
8082
0281028D0F04546F

I tried printing a new line after the syswrite instruction, but i am unable
to achieve that :-(

Thanks and Regards,
Dharshana


Syswrite Function in Perl

2007-01-01 Thread Dharshana Eswaran

Hi All,

I have a piece of code which reads as shown below:

unless (open(IN, in.txt)) {
   die(Cannot open input file \n);
   }
binmode(IN);

unless (open(OUT, +output.txt)) {
   die(Cannot open input file input.txt\n);
   }

%structure = (1 = A, 2 = B, 3 = C,
   );
@keys = keys %structure;
%table = (A = 4, B = 8, C = 32,
   );
$j=0;

print(ENTER THE SEQUENCE between[1-3]:\n);
$seq = STDIN;
chop($seq);
@seq = split(/ +/, $seq);
$seq_len = @seq;

$input = IN;
@input = split(/ +/, $input);
$new = join (, @input);

for($i=0; $i$seq_len; $i++) {
   $read1[$i] = $table{$structure{$seq[$j]}};
   syswrite (OUT, $new, $read1[$i]);
   print OUT (\n);
   $j++;
}

In the above code, i m trying to read the input in bytes and display them in
another output file. The reading is done in different sizes (4 or 8 or
32bytes), as per the sequence specifed by the User. The input file with
filehandle IN contains data as shown below:

F1 2F 8A 02 05 09 00 00 00 04 2B 48 00 00 00 68


When i use syswrite function, i face the following problem

syswrite (OUT, $new, 4); = Writes 4 bytes properly
syswrite (OUT, $new, $val); (where $val =4;) = Writes 4 bytes properly
syswrite (OUT, $new, $read1[$i]); = This does not work. It displays all the
bytes together, without seperators(new line). I dont know the reason.

Can anyone please guide me in this?

Thanks and Regards,
Dharshana


Re: Perl Query - Conversion of EXE file

2006-12-06 Thread Dharshana Eswaran

On 12/5/06, Jenda Krynicky [EMAIL PROTECTED] wrote:


From: kilaru rajeev [EMAIL PROTECTED]
 Jenda,

 I got a doubt here. Suppose the file does not contain any thing perl
 code. If it contains only some data for configuration, is it possible
 to include by using 'require' ?

 Rajeev

Depends on the format. But if it's not Perl why does it have a .pl
extension? And if it's configuration why do you want to pack it into
the EXEcutable?

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Now suppose, a EXE for the Perl Program is created in Windows.


The input for the EXE has to be taken from the file provided by the
user.AndThe EXE shud get invoked by just dragging and dropping the
input file on the
EXE.

Assume, the input file is some text file containing some raw data.

How should this be done?


- Dharshana


Re: Perl Query - Conversion of EXE file

2006-12-06 Thread Dharshana Eswaran

On 12/7/06, Jenda Krynicky [EMAIL PROTECTED] wrote:


From: Dharshana Eswaran [EMAIL PROTECTED]
 Now suppose, a EXE for the Perl Program is created in Windows.


 The input for the EXE has to be taken from the file provided by the
 user.AndThe EXE shud get invoked by just dragging and dropping the
 input file on the EXE.

 Assume, the input file is some text file containing some raw data.

 How should this be done?

You'll get the path to the dropped file in @ARGV.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response





Hi,

I also wanted to tell the same. For drag and drop, the filename is read from
$ARGV[0].

Now, my tool's EXE is working.


Thanks a lot for your constant support.

Thanks and Regards,
Dharshana


Re: Perl Query - Conversion of EXE file

2006-12-04 Thread Dharshana Eswaran

On 12/4/06, Jenda Krynicky [EMAIL PROTECTED] wrote:


From: Dharshana Eswaran [EMAIL PROTECTED]
 Hi Randal,

 I am trying to generate an exe file from few perl programs.

 I have 4 files which are main.pl, subroutine1.pl, subroutine2.pl and
 subroutine3.pl.

 main.pl file is the main program and it depends on the other
 subroutine files for data.

 So i tried zipping it using winzip and ran
  pp -o foldername.exe foldername.zip

 the exe file gets created as foldername.exe but when i tried runing it
 , it flags an error saying Usage: D:\Perl\foldername.exe
 script_file_name.

 Can i know how to create the EXE file with all the files together?

 Thanks and Regards,
 Dharshana

You are making it harder for yourself than you have to. Don't ZIP
anything ...

pp -o main.exe main.pl

should be enough. And if the pp doesn't notice your main.pl uses
subroutineX.pl then try

pp -o main.exe main.pl subroutine*.pl

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Hi Jenda,

I learnt that zipping wont help me and i tried the way you specified, like:

pp -o main.exe main.pl subroutine*.pl

But even that did not help me. It creates a EXE file, but when i try using
it all alone without the other supported files, it says that can't open
subroutine.pl

This is the problem i encounter.

Thanks and Regards,
Dharshana


Re: Perl Query - Conversion of EXE file

2006-12-04 Thread Dharshana Eswaran

On 12/4/06, Jenda Krynicky [EMAIL PROTECTED] wrote:


  You are making it harder for yourself than you have to. Don't ZIP
  anything ...
 
  pp -o main.exe main.pl
 
  should be enough. And if the pp doesn't notice your main.pl uses
  subroutineX.pl then try
 
  pp -o main.exe main.pl subroutine*.pl
 
  Jenda

 Hi Jenda,

 I learnt that zipping wont help me and i tried the way you specified,
 like:

 pp -o main.exe main.pl subroutine*.pl

 But even that did not help me. It creates a EXE file, but when i try
 using it all alone without the other supported files, it says that
 can't open subroutine.pl

 This is the problem i encounter.

 Thanks and Regards,
 Dharshana

subroutine.pl?

Anyway .. if you run the main.pl it works, right?



Yeah, mail.pl works

If you run the created EXE in the same folder what does it do?


The created EXE in the same folder works

If you run it from a different folder?



From a different folder it flags a msg Cannot open subroutine.pl which i

have written in my main.pl like
unless (open(LINE, subroutine.pl)) {
   die(Cannot open input file subroutine.pl\n);

So, the die statement is executed.


If you run it on a different machine?


The same action as described above happens  when run on a different machine

What happens if you add


BEGIN { print Starting the execution of main.pl\n }



If the above statement is added, it prints the above statement and then
prints the message as shown above, like:
Starting the execution of main.pl

Cannot open input file subroutine.pl


on the very top of main.pl? Do you get first this message and then

the one about subroutine.pl? And if that subroutine.pl even in the
same folder as the main.pl? Maybe you need to give pp the whole path
to this subroutine.pl




But the requirement is that the resulting EXE should not have any depending
files. So keeping subroutine.pl in the same folder does not satisfy the
requirement.

As, the resulkting file has to be distributed among ppl who does not have
any knowledge on Perl. So, they can only run the exe file.

And also, i wanted to know, if the EXE can be created in UNIX

Jenda

= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Please guide me in the same.

Thanks and Regards,
Dharshana


Usage of PAR (Perl ARchive Toolkit)

2006-11-30 Thread Dharshana Eswaran

Hi all,

I am trying to generate an exe file from few perl programs.

I have 4 files which are main.pl, subroutine1.pl, subroutine2.pl and
subroutine3.pl.

main.pl file is the main program and it depends on the other subroutine
files for data.

So i tried zipping it using winzip and ran

pp -o foldername.exe foldername.zip


the exe file gets created as foldername.exe but when i tried runing it , it
flags an error saying
Usage: D:\Perl\foldername.exe script_file_name.

Can i know how to create the EXE file with all the files together?

Thanks and Regards,
Dharshana


Re: Perl Query - Conversion of EXE file

2006-11-30 Thread Dharshana Eswaran

Hi Randal,

I am trying to generate an exe file from few perl programs.

I have 4 files which are main.pl, subroutine1.pl, subroutine2.pl and
subroutine3.pl.

main.pl file is the main program and it depends on the other subroutine
files for data.

So i tried zipping it using winzip and ran

pp -o foldername.exe foldername.zip


the exe file gets created as foldername.exe but when i tried runing it , it
flags an error saying
Usage: D:\Perl\foldername.exe script_file_name.

Can i know how to create the EXE file with all the files together?

Thanks and Regards,
Dharshana

On 28 Nov 2006 16:10:08 -0800, Randal L. Schwartz merlyn@stonehenge.com
wrote:


 Dharshana == Dharshana Eswaran [EMAIL PROTECTED] writes:

Dharshana I am in search of a way to convert Perl Program to EXE file.
So that it can
Dharshana be run anywhere even without installing Perl.

See PAR in the CPAN.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response





Perl Query - Conversion of EXE file

2006-11-27 Thread Dharshana Eswaran

Hi All,

I just have a query in Perl.

I am in search of a way to convert Perl Program to EXE file. So that it can
be run anywhere even without installing Perl.

I searched the net and had mailed the beginners mailing list which suggested
me a  few tools like Perl2exe or Perl_Dev_Kit to do the same. But i wanted
to know if there is any other way to do the same.

Can we make this program as a Perl module, use it in a C code and then
create the EXE of the C code? Will this work? I am not sure, so thought will
ask you for suggestions.

Can anyone please guide me in the same?

Thanks and Regards,
Dharshana


I







Re: How to make a perl program to an exe file

2006-11-21 Thread Dharshana Eswaran

Hi Rajeev,

I tried using Perlcc, but the following error occurs.

bash$ perlcc zzz.pl
Can't exec gcc: No such file or directory at /XXX/xxx/perl/bin/perlcc line
347.
bash$

What does this mean? or Where it has gone wrong?

Thanks and Regards,
Dharshana




On 11/22/06, kilaru rajeev [EMAIL PROTECTED] wrote:


Hi Dharsana,

Please check this link.
http://perldoc.perl.org/perlcc.html

I hope this will clarify your questions.

Regards,
Rajeev Kilaru


On 11/21/06, kilaru rajeev [EMAIL PROTECTED] wrote:

 There are some programs call perlcc like that. You can change Perl
 files as the executable.

 rgds,
 Rajeev


  On 11/21/06, Dharshana Eswaran [EMAIL PROTECTED]  wrote:
 
  Hi all,
 
  I have a perl program in a folder along with 2 more files associated
  to the
  main program.
 
  I need to know how to create a exe file out of this?
 
  I kindly request you to guide me in this.
 
  Thanks and Regards,
  Dharshana
 
 




Re: How to make a perl program to an exe file

2006-11-21 Thread Dharshana Eswaran

Hi All,

I tried getting the executable from Perl2exe, but when i run the program i
get the following error:

D:\in2309c\Perlexe\p2x-8.80-Win32perl2exe example.pl
Perl2Exe V8.80 Copyright (c) 1997-2006 IndigoSTAR Software

This is an evaluation version of Perl2Exe, which may be used for 30 days.
For more information see the attached pxman.htm file,
or visit http://www.indigostar.com

Converting 'example.pl' to example.exe
ERROR: Can't open D:\in2309c\Perlexe\p2x-8.80-Win32\p2x583exe.lib
ERROR: Can't open D:\in2309c\Perlexe\p2x-8.80-Win32\p2x583.dll

After this a exe gets created but it cannot be opened at all...

Can anyone guide me in this?

Thanks and Regards,
Dharshana

On 11/22/06, Krishnakumar K P [EMAIL PROTECTED] wrote:


Try Perl2Exe   http://www.indigostar.com/.

the only drawback i found is that the size of exe is huge.

Krishnakumar K.P


-Original Message-
From: kilaru rajeev [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 22, 2006 11:08 AM
To: Dharshana Eswaran
Cc: beginners@perl.org
Subject: Re: How to make a perl program to an exe file


Hi Dharsana,

Please check this link.
http://perldoc.perl.org/perlcc.html

I hope this will clarify your questions.

Regards,
Rajeev Kilaru


On 11/21/06, kilaru rajeev [EMAIL PROTECTED] wrote:

 There are some programs call perlcc like that. You can change Perl
files
 as the executable.

 rgds,
 Rajeev


  On 11/21/06, Dharshana Eswaran [EMAIL PROTECTED] wrote:
 
  Hi all,
 
  I have a perl program in a folder along with 2 more files associated
to
  the
  main program.
 
  I need to know how to create a exe file out of this?
 
  I kindly request you to guide me in this.
 
  Thanks and Regards,
  Dharshana
 
 



Legal Disclaimer: This electronic message and all contents contain
information from Cybage Software Private Limited which may be privileged,
confidential, or otherwise protected from disclosure. The information is
intended to be for the addressee(s) only. If you are not an addressee, any
disclosure, copy, distribution, or use of the contents of this message is
strictly prohibited. If you have received this electronic message in error
please notify the sender by reply e-mail to and destroy the original message
and all copies. Cybage has taken every reasonable precaution to minimize the
risk of malicious content in the mail, but is not liable for any damage you
may sustain as a result of any malicious content in this e-mail. You should
carry out your own malicious content checks before opening the e-mail or
attachment.
www.cybage.com





Perl - Joining of Binary values

2006-11-16 Thread Dharshana Eswaran

Hi all,

I am working on the code below:

use strict;
use warnings;

my %TypeofNumber = (
 '00' = Integer,
 '01' = Floating,
 '10' = Char,
 '11' = Double );


my @hex = (14, 2a, 11, 83);
$hex_length = @hex;

for($i=0; $i$hex_length; $i++) {

my $binary = unpack 'B*', pack 'H*', $hex[$i];

print $binary\n\n;

my @fields = unpack 'A2A2A4', $binary;

my $i;
printf %-4s = %s\n\n, $fields[0], 'Ext';

print TypeofNumber\n;
printf %-4s = %s\n\n, $fields[1], $TypeofNumber{$fields[1]};

printf %-4s = %s\n\n, $fields[2], 'NumberingPlan';

}

Now i need to split the binary value of the first element into two halves
(A7A1), seecond element into A6A2, third element into A5A3 and so on...

Then i need to display the 7bits of the first element, then join 1bit of the
first element to the 6bits of the second element(that is join A1 of first
element and A6of the second element) and then display it, then join A2 of
the second element and A5 of the third element and then display it and so
on.

How to go bout this?

Thanks and Regards,
Dharshana


Re: Perl - Joining of Binary values

2006-11-16 Thread Dharshana Eswaran

Rob,

my @fields = unpack '(A7)*', $binary;

When i tried compiling, it says that

Invalid type in unpack: '(' at line 10.

It does not accept this, i tried other combinations too. But it does not
compile the program.

What should i do?

Thanks and Regards,
Dharshana


On 11/16/06, Rob Dixon [EMAIL PROTECTED] wrote:


Dharshana Eswaran wrote:
 Hi all,

 I am working on the code below:

 use strict;
 use warnings;

 my %TypeofNumber = (
  '00' = Integer,
  '01' = Floating,
  '10' = Char,
  '11' = Double );


 my @hex = (14, 2a, 11, 83);
 $hex_length = @hex;

 for($i=0; $i$hex_length; $i++) {

 my $binary = unpack 'B*', pack 'H*', $hex[$i];

 print $binary\n\n;

 my @fields = unpack 'A2A2A4', $binary;

 my $i;
 printf %-4s = %s\n\n, $fields[0], 'Ext';

 print TypeofNumber\n;
 printf %-4s = %s\n\n, $fields[1], $TypeofNumber{$fields[1]};

 printf %-4s = %s\n\n, $fields[2], 'NumberingPlan';

 }

 Now i need to split the binary value of the first element into two
halves
 (A7A1), seecond element into A6A2, third element into A5A3 and so on...

 Then i need to display the 7bits of the first element, then join 1bit of
 the
 first element to the 6bits of the second element(that is join A1 of
first
 element and A6of the second element) and then display it, then join A2
of
 the second element and A5 of the third element and then display it and
so
 on.

 How to go bout this?

Does this help?

Rob


use strict;
use warnings;

my @hex = (14, 2a, 11, 83);
my $hex = join '', @hex;
my $binary = unpack 'B*', pack 'H*', $hex;

my @fields = unpack '(A7)*', $binary;
print $_, \n foreach @fields;

**OUTPUT

0001010
0001010
110
0011000
0011



Re: Perl - Joining of Binary values

2006-11-16 Thread Dharshana Eswaran

On 11/16/06, Rob Dixon [EMAIL PROTECTED] wrote:


Dharshana Eswaran wrote:

 On 11/16/06, Rob Dixon [EMAIL PROTECTED] wrote:

 Dharshana Eswaran wrote:

 I am working on the code below:

[snip irrelevancies]

 my @hex = (14, 2a, 11, 83);
 $hex_length = @hex;

 for($i=0; $i$hex_length; $i++) {

 my $binary = unpack 'B*', pack 'H*', $hex[$i];

 print $binary\n\n;

 my @fields = unpack 'A2A2A4', $binary;

[snip irrelevancies]

 Now i need to split the binary value of the first element into two
halves
 (A7A1), seecond element into A6A2, third element into A5A3 and so
on...

 Then i need to display the 7bits of the first element, then join 1bit
of the
 first element to the 6bits of the second element(that is join A1 of
first
 element and A6of the second element) and then display it, then join A2
of
 the second element and A5 of the third element and then display it and
so
 on.

 How to go bout this?

 Does this help?

 Rob


 use strict;
 use warnings;

 my @hex = (14, 2a, 11, 83);
 my $hex = join '', @hex;
 my $binary = unpack 'B*', pack 'H*', $hex;

 my @fields = unpack '(A7)*', $binary;
 print $_, \n foreach @fields;

 **OUTPUT

 0001010
 0001010
 110
 0011000
 0011

 my @fields = unpack '(A7)*', $binary;

 When i tried compiling, it says that

 Invalid type in unpack: '(' at line 10.

 It does not accept this, i tried other combinations too. But it does not
 compile the program.

 What should i do?

(Please bottom-post your replies, as it makes long threads like this much
easier
to understand. Thanks.)

Oh dear. It looks like you have an ealier version of Perl where unpack has
no
sub-templates, altthough I thought it had always been like that. Find out
what
version you are running (with perl -v) and consider upgrading. I am using
v5.8.8
and bmost people use v5.8 or above.

In the meantime, replace

my @fields = unpack '(A7)*', $binary;

with

my @fields = $binary =~ /.{1,7}/g;



Rob




Thanks Rob. I sincerely want to appreciate your immediate response. It has
been a great help for me.

Thanks and Regards,
Dharshana


Re: Perl - Joining of Binary values

2006-11-16 Thread Dharshana Eswaran

Thanks Jay. I will keep Perl on my system, up to date.

Thanks and Regards,
Dharshana


On 11/16/06, Jay Savage [EMAIL PROTECTED] wrote:


On 11/16/06, Rob Dixon [EMAIL PROTECTED] wrote:
 Dharshana Eswaran wrote:
[snip]
  my @fields = unpack '(A7)*', $binary;
 
  When i tried compiling, it says that
 
  Invalid type in unpack: '(' at line 10.
 
  It does not accept this, i tried other combinations too. But it does
not
  compile the program.
 
  What should i do?

 (Please bottom-post your replies, as it makes long threads like this
much easier
 to understand. Thanks.)

 Oh dear. It looks like you have an ealier version of Perl where unpack
has no
 sub-templates, altthough I thought it had always been like that. Find
out what
 version you are running (with perl -v) and consider upgrading. I am
using v5.8.8
 and bmost people use v5.8 or above.

 In the meantime, replace

 my @fields = unpack '(A7)*', $binary;

 with

 my @fields = $binary =~ /.{1,7}/g;


Groups (or sub-templates, if you prefer) were introduced in 5.8. If
you don't have them, it's time to upgrade your Perl. In general, you
should keep reasonably up-to-date. Not only are there bug and security
fixes between releases, but if you don't keep up with the the major
versions, you'll find the advice you get on this list and elsewhere
increasingly unhelpful as your Perl slips more and more out-of-date.
It also means fewer and fewer modules will compile correctly as
authors start to rely on newer behaviors.

If you don't have pack groups, that means your system hasn't been
updated in at least 4 years (5.8.0 was released in 2002). You wouldn't
let your OS go for that long without security fixes. 5.6 to 5.8 was a
pretty big jump, too!

In the meantime, see the perldoc for perlpacktut for some pointers on
using the x-multiplication to do some ad-hoc templating.

HTH,

-- jay
--
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!



Perl - Joining of Binary values

2006-11-16 Thread Dharshana Eswaran

On 11/16/06, Rob Dixon [EMAIL PROTECTED] wrote:


Dharshana Eswaran wrote:

 On 11/16/06, Rob Dixon [EMAIL PROTECTED]  wrote:

 Dharshana Eswaran wrote:

 I am working on the code below:

[snip irrelevancies]

 my @hex = (14, 2a, 11, 83);
 $hex_length = @hex;

 for($i=0; $i$hex_length; $i++) {

 my $binary = unpack 'B*', pack 'H*', $hex[$i];

 print $binary\n\n;

 my @fields = unpack 'A2A2A4', $binary;

[snip irrelevancies]

 Now i need to split the binary value of the first element into two
halves
 (A7A1), seecond element into A6A2, third element into A5A3 and so
on...

 Then i need to display the 7bits of the first element, then join 1bit
of the
 first element to the 6bits of the second element(that is join A1 of
first
 element and A6of the second element) and then display it, then join A2
of
 the second element and A5 of the third element and then display it and
so
 on.

 How to go bout this?

 Does this help?

 Rob


 use strict;
 use warnings;

 my @hex = (14, 2a, 11, 83);
 my $hex = join '', @hex;
 my $binary = unpack 'B*', pack 'H*', $hex;

 my @fields = unpack '(A7)*', $binary;
 print $_, \n foreach @fields;

 **OUTPUT

 0001010
 0001010
 110
 0011000
 0011

 my @fields = unpack '(A7)*', $binary;

 When i tried compiling, it says that

 Invalid type in unpack: '(' at line 10.

 It does not accept this, i tried other combinations too. But it does not
 compile the program.

 What should i do?

(Please bottom-post your replies, as it makes long threads like this much
easier
to understand. Thanks.)

Oh dear. It looks like you have an ealier version of Perl where unpack has
no
sub-templates, altthough I thought it had always been like that. Find out
what
version you are running (with perl -v) and consider upgrading. I am using
v5.8.8
and bmost people use v5.8 or above.

In the meantime, replace

my @fields = unpack '(A7)*', $binary;

with

my @fields = $binary =~ /.{1,7}/g;



Rob






Rob,

my @fields = $binary =~ /.{7,1}/g; This works fine

my @fields = $binary =~ /.{7,1}/g; Why does'nt this work?

Coz i wanted the procedure to be reversed, that is if the input is
31,59, 4C,15,53

I wanted the output to be

0110001
0110010
0110001
0101010
1110001
01010


Thanks and Regards,
Dharshana


Re: Perl - Joining of Binary values

2006-11-16 Thread Dharshana Eswaran

On 11/17/06, Rob Dixon [EMAIL PROTECTED] wrote:


Dharshana Eswaran wrote:

 On 11/16/06, Rob Dixon [EMAIL PROTECTED] wrote:

 Dharshana Eswaran wrote:

 I am working on the code below:

 my @hex = (14, 2a, 11, 83);
 $hex_length = @hex;

 for($i=0; $i$hex_length; $i++) {

 my $binary = unpack 'B*', pack 'H*', $hex[$i];

 print $binary\n\n;

 Oh dear. It looks like you have an ealier version of Perl where unpack
has no
 sub-templates, altthough I thought it had always been like that. Find
out
 what version you are running (with perl -v) and consider upgrading. I
am
 using v5.8.8 and bmost people use v5.8 or above.

 In the meantime, replace

 my @fields = unpack '(A7)*', $binary;

 with

 my @fields = $binary =~ /.{1,7}/g;


 my @fields = $binary =~ /.{7,1}/g; This works fine

 my @fields = $binary =~ /.{7,1}/g; Why does'nt this work?

 Coz i wanted the procedure to be reversed, that is if the input is
 31,59, 4C,15,53




 I wanted the output to be

 0110001
 0110010
 0110001
 0101010
 1110001
 01010



The input is 31,59, 4C,15,53,DD,54,31

The above input is represented as shown below:
00110001 01011001 01001100 00010101 01010011 11011101 01010100 00110001

The correction in the desired output is

0110001
0110010
0110001
0101010
0110001
0101010
0110111

The output should have 7bits for each representation. That is 8th bit of the
1st byte is taken as the 0th bit of the next byte and 7th and 8th of the
second bytes becomes the 0th and 1st of the third byte, next 6th, 7th,8th of
the third becomes 0th,1st,2nd of the fourthAnd so on



The 1 and the 7 in the regex can't be exchanged as they are a minimum and

maximum number of characters to match. The pattern matches between one and
seven
of any character, and so splits the 40-character string into five blocks
of
seven characters and one of five.

I don't understand what you mean about reversing the procedure I'm afraid.

31,59,4C,15,53

is

00110001 01011001 01001100 00010101 01010011

in binary, and I can't see how to get to the bit patterns you give from
that,
although it starts off close enough. Your fourth pattern of seven bits,
for
instance, has three consecutive 1s in it, and that doesn't appear anywhere
in
the number sequence you gave.

Are you sure the data you've posted is right?

Rob



I hope the corrections would help you better.

Thanks and Regards,
Dharshana

--

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response





Re: Perl - Joining of Binary values

2006-11-16 Thread Dharshana Eswaran

On 11/17/06, Dharshana Eswaran [EMAIL PROTECTED] wrote:




 On 11/17/06, Rob Dixon [EMAIL PROTECTED] wrote:

 Dharshana Eswaran wrote:
 
  On 11/16/06, Rob Dixon [EMAIL PROTECTED]  wrote:
 
  Dharshana Eswaran wrote:
 
  I am working on the code below:
 
  my @hex = (14, 2a, 11, 83);
  $hex_length = @hex;
 
  for($i=0; $i$hex_length; $i++) {
 
  my $binary = unpack 'B*', pack 'H*', $hex[$i];
 
  print $binary\n\n;
 
  Oh dear. It looks like you have an ealier version of Perl where
 unpack has no
  sub-templates, altthough I thought it had always been like that. Find
 out
  what version you are running (with perl -v) and consider upgrading. I
 am
  using v5.8.8 and bmost people use v5.8 or above.
 
  In the meantime, replace
 
  my @fields = unpack '(A7)*', $binary;
 
  with
 
  my @fields = $binary =~ /.{1,7}/g;
 
 
  my @fields = $binary =~ /.{7,1}/g; This works fine
 
  my @fields = $binary =~ /.{7,1}/g; Why does'nt this work?
 
  Coz i wanted the procedure to be reversed, that is if the input is
  31,59, 4C,15,53


  I wanted the output to be
 
  0110001
  0110010
  0110001
  0101010
  1110001
  01010


The input is 31,59, 4C,15,53,DD,54,31

 The above input is represented as shown below:
00110001 01011001 01001100 00010101 01010011 11011101 01010100 00110001

The correction in the desired output is

0110001
0110010
0110001
0101010
0110001
0101010
0110111



0110001
0110010
0110001
0101010
0110001
0101010
0110111
0101010
0110001
0
This is the complete pattern output for the input array





The output should have 7bits for each representation. That is 8th bit of
the 1st byte is taken as the 0th bit of the next byte and 7th and 8th of the
second bytes becomes the 0th and 1st of the third byte, next 6th, 7th,8th of
the third becomes 0th,1st,2nd of the fourthAnd so on



The 1 and the 7 in the regex can't be exchanged as they are a minimum and
 maximum number of characters to match. The pattern matches between one
 and seven
 of any character, and so splits the 40-character string into five blocks
 of
 seven characters and one of five.

 I don't understand what you mean about reversing the procedure I'm
 afraid.

 31,59,4C,15,53

 is

 00110001 01011001 01001100 00010101 01010011

 in binary, and I can't see how to get to the bit patterns you give from
 that,
 although it starts off close enough. Your fourth pattern of seven bits,
 for
 instance, has three consecutive 1s in it, and that doesn't appear
 anywhere in
 the number sequence you gave.

 Are you sure the data you've posted is right?

 Rob


I hope the corrections would help you better.

Thanks and Regards,
Dharshana

--
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/  http://learn.perl.org/first-response






Re: Perl - Joining of Binary values

2006-11-16 Thread Dharshana Eswaran

On 11/17/06, Dr.Ruud [EMAIL PROTECTED] wrote:


Dr.Ruud schreef:

   my $data = join(\n, map {sprintf %08b, $_}
 map hex, DATA =~ /[[:xdigit:]]+/g) . \n ;

   1 while $data =~ s/(.+?)(.{7}\n.*)/$2$1/ ;

Better:

  my $data = join \n, map {sprintf %08b, $_}
map hex, DATA =~ /[[:xdigit:]]+/g ;

  $data =~ s/(?=.)\z/\n/
while $data =~ s/(.+?)(.{7}\n.*)/$2$1/ ;


Alternative for that last (folded) line:

  for ($data) {s/(?=.)\z/\n/ while s/(.+?)(.{7}\n.*)/$2$1/}

--
Affijn, Ruud

Gewoon is een tijger.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response

Thanks Dr.Ruud. Since i am unable to understand the working of the code
which you have written, I request you to explain the working for me.




Thanks and Regards,
Dharshana


How to define modules?

2006-11-14 Thread Dharshana Eswaran

Hi all,

I have perl programs with me and i wish to convert it into perl modules.

Can i know how to do the same?

Or can i know any links or documents which describes the same?


Thanks and Regards,
Dharshana


Re: Perl - Bit Manipulation

2006-11-13 Thread Dharshana Eswaran

Hi all,

In the below program, i give in the hash as

%TypeofNumber  = ( 0b00 = Integer, 0b01 = Floating, 0b10 = Char, 0b11 =
Double );

Using this hash i need to priont the appropriate combination

How to do that?

Thanks and Regards,
Dharshana

On 11/13/06, Dharshana Eswaran [EMAIL PROTECTED] wrote:


Hi all,

I am working on the code below

use strict;
use warnings;

my $hex = 43;

my $binary = unpack 'B*', pack 'H*', $hex;

print $binary\n\n;

my @fields = unpack 'A2A2A4', $binary;

my $i;
printf %-4s = %s\n, $fields[$i++], $_ foreach qw/Ext TypeofNumber
NumberingPlan/;

**OUTPUT**

0111

01 = Ext
00 = TypeofNumber
0011 = NumberingPlan

But, now i have a hash(associative array),

%TypeofNumber  = ( 00 = Integer, 01 = Floating, 10 = Char, 11 = Double
);

Using this hash, the type of number has to be specified in the output.

As shown here:
01 = Ext

TypeofNumber
00 = Integer

0011 = NumberingPlan


I am unable to get the desired output?


Thanks and regards,
Dharshana





Perl - Bit Manipulation

2006-11-12 Thread Dharshana Eswaran

Hi all,

I am working on the code below

use strict;
use warnings;

my $hex = 43;

my $binary = unpack 'B*', pack 'H*', $hex;

print $binary\n\n;

my @fields = unpack 'A2A2A4', $binary;

my $i;
printf %-4s = %s\n, $fields[$i++], $_ foreach qw/Ext TypeofNumber
NumberingPlan/;

**OUTPUT**

0111

01 = Ext
00 = TypeofNumber
0011 = NumberingPlan

But, now i have a hash(associative array),

%TypeofNumber  = ( 00 = Integer, 01 = Floating, 10 = Char, 11 = Double
);

Using this hash, the type of number has to be specified in the output.

As shown here:
01 = Ext

TypeofNumber
00 = Integer

0011 = NumberingPlan


I am unable to get the desired output?


Thanks and regards,
Dharshana


Conversion of Hex bytes to binary and vice versa

2006-11-09 Thread Dharshana Eswaran

Hi all,

I have to convert a hex byte [eg: 0x2A] into its binary form [eg:00101010].
The input is always only one byte that is 8 bits.

I tried using pack() and unpack(). But i am unable to get desired results.

The desired output should look like the following:

0x0a = 1010
0x23 = 00100011

Can anyone suggest me for the same?


parsing of 8bit binary data bitwise

2006-11-09 Thread Dharshana Eswaran

Hi all,

I wanted to know how to parse a 8bit binary data bitwise?

I have my input in hex and i convert it into binary form using the following
logic:

%h2b = (0 = , 1 = 0001, 2 = 0010, 3 = 0011,
4 = 0100, 5 = 0101, 6 = 0110, 7 = 0111,
8 = 1000, 9 = 1001, a = 1010, b = 1011,
c = 1100, d = 1101, e = 1110, f = ,
);

$hex = 43;
($binary = $hex) =~ s/(.)/$h2b{lc $1}/g;
print $binary, \n;

Now the output for the above prg is

0111

Now i have to display this binary data as shown below:

0= abc
100= def
0011= lmn

How to go about this?


Re: parsing of 8bit binary data bitwise

2006-11-09 Thread Dharshana Eswaran

Rajeev,

Actually, i get data in hex bytes from a log file. I have to parse them or
analyze them according to some predefined rules or values.

For eg: a hex byte of 0xa4 is converted to binary as 10100100

Now, i have a file in which the values are predefined. It looks like

0xa4 = 10100100

in that MSB 1 stands for some abc
then the following bits 01 stands for cdf
then the remaining bits 00100 stands for xyz

(0/1)  | 2 bits   |5 bits
abc   |System name|Other details

System name Other Details
00  ujj 0
01  cdf1 etc
10  bbg
11  gtt


In the above example, the text is just an eg and not the actual text.

I get those 8 bits as a whole as hex byte which i need to parse and diplay
them bitwise.


Hope this explains better.



Dharshana







On 11/9/06, kilaru rajeev [EMAIL PROTECTED] wrote:


Dharshana,

The program you wrote here to convert the number to binary is good. In the
second one, I am not getting what is your intention correctly. You said you
what to convert 0= abc,. Can I know a little bit more.

Rajeev


On 11/9/06, Dharshana Eswaran [EMAIL PROTECTED] wrote:

 Hi all,

 I wanted to know how to parse a 8bit binary data bitwise?

 I have my input in hex and i convert it into binary form using the
 following
 logic:

 %h2b = (0 = , 1 = 0001, 2 = 0010, 3 = 0011,
 4 = 0100, 5 = 0101, 6 = 0110, 7 = 0111,
 8 = 1000, 9 = 1001, a = 1010, b = 1011,
 c = 1100, d = 1101, e = 1110, f = ,
 );

 $hex = 43;
 ($binary = $hex) =~ s/(.)/$h2b{lc $1}/g;
 print $binary, \n;

 Now the output for the above prg is

 0111

 Now i have to display this binary data as shown below:

 0= abc
 100= def
 0011= lmn

 How to go about this?





Re: parsing of 8bit binary data bitwise

2006-11-09 Thread Dharshana Eswaran

Rob,

my $i;
printf %-4s = %s\n, $fields[$i++], $_ foreach qw/abc def lmn/;

These are arbitrary values.

Thanks for the kind and immediate response. I sincerely appreciate it.

Thanks and Regards,
Dharshana


On 11/9/06, Rob Dixon [EMAIL PROTECTED] wrote:


Dharshana Eswaran wrote:
 Hi all,

 I wanted to know how to parse a 8bit binary data bitwise?

 I have my input in hex and i convert it into binary form using the
 following
 logic:

 %h2b = (0 = , 1 = 0001, 2 = 0010, 3 = 0011,
 4 = 0100, 5 = 0101, 6 = 0110, 7 = 0111,
 8 = 1000, 9 = 1001, a = 1010, b = 1011,
 c = 1100, d = 1101, e = 1110, f = ,
 );

 $hex = 43;
 ($binary = $hex) =~ s/(.)/$h2b{lc $1}/g;
 print $binary, \n;

 Now the output for the above prg is

 0111

 Now i have to display this binary data as shown below:

 0= abc
 100= def
 0011= lmn

 How to go about this?


I assume your 'abc', 'def' etc. are arbitrary data? The program below may
help
you. Do come back here idf you have any questions.

Rob


use strict;
use warnings;

my $hex = 43;

my $binary = unpack 'B*', pack 'H*', $hex;

print $binary\n\n;

my @fields = unpack 'A1A3A4', $binary;

my $i;
printf %-4s = %s\n, $fields[$i++], $_ foreach qw/abc def lmn/;

**OUTPUT**

0111

0= abc
100  = def
0011 = lmn



Parsing of HEX bytes using PErl

2006-10-25 Thread Dharshana Eswaran

Hi all,

I am a student working on a project using Perl.

My work is...

I have few hex bytes as inputs for my program. Its a series of hex bytes.
for eg: 01 0a ab 2a 1c etc...

Here each byte stands for some representation. I also have a data file in
which all the representations are stored. For eg:
01 = abcd
02 = ertg
1c = srfrf
etc...

I have to parse the input hex bytes using this data file and the output
should show the parsed input series.

The problem i face in linear search id, there are few hex bytes in which the
digits are same but the representations are different. For eg: 01 stands for
abcd and also in some other place it stands for cdfv also.

My program follows ASN.1 format. I mean The bytes come in a fashion like
TYPE and then LENGTH and then VALUE..

So i have to parse in teh above mentioned manner.

I am unable to come up with an algorithm for the same as i am very new to
Perl programming.

Also, the data files are very huge and input also is very huge file in which
there are several hex bytes.

So plz can anyone help me in this?


Plz HELP

2006-10-17 Thread Dharshana Eswaran

Hi All,

I am a student who is working on Perl on my project.

I am a beginner in Perl.

I know how to read the data from files into a variable or array. I mean, i
know to read the data line by line into a varaiable or teh full file
contents into an array.

But, i have stored few hex bytes in the file and i need to read a pair of
character one by one which is seperated using spaces.
For eg:
The file contents are stored in the following fashion,
00 01 a0 ab 55 76 ff cb etc

How should i read number by number?

Thanks and Regards,
Dharshana