[29940] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1183 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 9 18:09:40 2008

Date: Wed, 9 Jan 2008 15:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 9 Jan 2008     Volume: 11 Number: 1183

Today's topics:
    Re: Force return of the diamond operator from network s <uri@stemsystems.com>
    Re: Force return of the diamond operator from network s <n0nb.DO.NOT.SPAM@ME.n0nb.us>
    Re: Force return of the diamond operator from network s <tzz@lifelogs.com>
    Re: Force return of the diamond operator from network s <uri@stemsystems.com>
    Re: Force return of the diamond operator from network s <n0nb.DO.NOT.SPAM@ME.n0nb.us>
    Re: Force return of the diamond operator from network s xhoster@gmail.com
    Re: Force return of the diamond operator from network s <steve.roscio@hp.com>
    Re: Help with a Reg Ex <someone@example.com>
    Re: Help with a Reg Ex <someone@example.com>
    Re: Help with a Reg Ex <m@rtij.nl.invlalid>
    Re: Help with a Reg Ex <m@rtij.nl.invlalid>
    Re: Help with a Reg Ex <jurgenex@hotmail.com>
    Re: Help with a Reg Ex <someone@example.com>
    Re: Help with a Reg Ex <someone@example.com>
    Re: how to do bit complement in perl <jimsgibson@gmail.com>
    Re: Search/Replace text in XML file <jimsgibson@gmail.com>
    Re: Search/Replace text in XML file <someone@example.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 09 Jan 2008 21:11:09 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Force return of the diamond operator from network socket
Message-Id: <x7fxx6902b.fsf@mail.sysarch.com>

>>>>> "NB" == Nate Bargmann <n0nb.DO.NOT.SPAM@ME.n0nb.us> writes:

  NB> while (<$socket>) {
  NB>     chomp;
  NB>     print "$_\n";
  NB> }

  NB> however, the diamond operator doesn't return despite trying to
  NB> send a NULL string from the C program through the socket.  Here is
  NB> a snippet of my C program:

  NB>         fprintf(fout, "");
  NB>         fflush(fout);

first, use write() so you don't need the fflush call. that means you
need to do an open() and not an fopen. it will run faster as well as you
avoid the stdio overhead.

a c null string is a single byte of 0. the <> operator expects to read a
line of text which a 0 byte is not. that is why you hang. you should
either send complete lines that end in \n (or cleaner for the net
\015\012) or you need to stop using <> to read from the socket. you
can't easily mix/match line oriented protocols with binary ones (and
your 0 byte forces you into a binary protocol.

  NB> Perhaps there is a better method of signalling the end of the C
  NB> program's output to the Perl program.  At the moment I'm a bit
  NB> stumped.

if this is a one and done request (like web) just close the socket and
the <> will return with an undef (eof detected). otherwise use a proper
line with some token like END or whatever you want that works within
your protocol. and yes, you have a protocol and you need to make sure it
can handle inline commands like that if you want line oriented I/O.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Architecture, Development, Training, Support, Code Review  ------
-----------  Search or Offer Perl Jobs  ----- http://jobs.perl.org  ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Wed, 09 Jan 2008 15:25:14 -0600
From: Nate Bargmann <n0nb.DO.NOT.SPAM@ME.n0nb.us>
Subject: Re: Force return of the diamond operator from network socket
Message-Id: <D8ednXD7GfMnphjanZ2dnUVZ_hudnZ2d@kans.com>

On Wed, 09 Jan 2008 21:11:09 +0000, Uri Guttman wrote:

>>>>>> "NB" == Nate Bargmann <n0nb.DO.NOT.SPAM@ME.n0nb.us> writes:
> 
>   NB> while (<$socket>) {
>   NB>     chomp;
>   NB>     print "$_\n";
>   NB> }
> 
>   NB> however, the diamond operator doesn't return despite trying to
>   NB> send a NULL string from the C program through the socket.  Here is
>   NB> a snippet of my C program:
> 
>   NB>         fprintf(fout, "");
>   NB>         fflush(fout);
> 
> first, use write() so you don't need the fflush call. that means you
> need to do an open() and not an fopen. it will run faster as well as you
> avoid the stdio overhead.

I think the reason the stdio functions are used is due to portability to
win32 although Linux is the primary platform. The fflush() was my addition
to try and force the NULL string through after the fprintf().

> if this is a one and done request (like web) just close the socket and
> the <> will return with an undef (eof detected). otherwise use a proper
> line with some token like END or whatever you want that works within
> your protocol. and yes, you have a protocol and you need to make sure it
> can handle inline commands like that if you want line oriented I/O.

Unlike a web browser, my intent is a persistent socket.  It's possible
that the client may query the server quite frequently, every few seconds
or perhaps even more frequently.  It seems to me that opening and closing
the socket that frequently would itself create a lot of overhead.

The END idea is a good one as, at this point, it doesn't conflict with the
text returned by the server.  So, would the recv() function be a better
choice to read the socket?  Especially since two to five lines (now
including the END token) could be available and the data length is
variable.

Thanks, Uri,

- Nate >>

-- 

"The optimist proclaims that we live in the best of all
possible worlds.  The pessimist fears this is true."


------------------------------

Date: Wed, 09 Jan 2008 16:06:26 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Force return of the diamond operator from network socket
Message-Id: <867iiihcwt.fsf@lifelogs.com>

On Wed, 09 Jan 2008 15:25:14 -0600 Nate Bargmann <n0nb.DO.NOT.SPAM@ME.n0nb.us> wrote: 

NB> Unlike a web browser, my intent is a persistent socket.  It's possible
NB> that the client may query the server quite frequently, every few seconds
NB> or perhaps even more frequently.  It seems to me that opening and closing
NB> the socket that frequently would itself create a lot of overhead.

HTTP and web browsers works just fine with a persistent connection;
see http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html for example.
HTTP 1.1 makes it the default, in fact.

Unless you're doing something unusual, you may find that HTTP is a good
solution for you.  Not only are there a million implementations of it
out there on both the client and the server side, but it's also easy to
script and test HTTP interactions.  HTTP also allows a lot of
flexibility with the URI, so your client/server interactions can be as
rich as a URI will express (which is plenty).  Binary data is well
supported in several encoding schemes, including raw or compressed raw
data if you need it.  Finally, HTTP error codes allow you out-of-band
signaling back to the client about the server's state.

HTTP is not perfect, but I would at least consider it for generic
network communications nowadays.

Ted


------------------------------

Date: Wed, 09 Jan 2008 22:17:05 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Force return of the diamond operator from network socket
Message-Id: <x7myre7ify.fsf@mail.sysarch.com>

>>>>> "NB" == Nate Bargmann <n0nb.DO.NOT.SPAM@ME.n0nb.us> writes:

  NB> On Wed, 09 Jan 2008 21:11:09 +0000, Uri Guttman wrote:
  >>>>>>> "NB" == Nate Bargmann <n0nb.DO.NOT.SPAM@ME.n0nb.us> writes:
  >> 
  NB> while (<$socket>) {
  NB> chomp;
  NB> print "$_\n";
  NB> }
  >> 
  NB> however, the diamond operator doesn't return despite trying to
  NB> send a NULL string from the C program through the socket.  Here is
  NB> a snippet of my C program:
  >> 
  NB> fprintf(fout, "");
  NB> fflush(fout);
  >> 
  >> first, use write() so you don't need the fflush call. that means you
  >> need to do an open() and not an fopen. it will run faster as well as you
  >> avoid the stdio overhead.

  NB> I think the reason the stdio functions are used is due to portability to
  NB> win32 although Linux is the primary platform. The fflush() was my addition
  NB> to try and force the NULL string through after the fprintf().

that has nothing to do with anything. writing to a socket is not
something that ever needs to use stdio. that just slows you down and
requires extra fflush calls. but this is something that is not perl
related and off topic.

  >> if this is a one and done request (like web) just close the socket and
  >> the <> will return with an undef (eof detected). otherwise use a proper
  >> line with some token like END or whatever you want that works within
  >> your protocol. and yes, you have a protocol and you need to make sure it
  >> can handle inline commands like that if you want line oriented I/O.

  NB> Unlike a web browser, my intent is a persistent socket.  It's possible
  NB> that the client may query the server quite frequently, every few seconds
  NB> or perhaps even more frequently.  It seems to me that opening and closing
  NB> the socket that frequently would itself create a lot of overhead.

  NB> The END idea is a good one as, at this point, it doesn't conflict with the
  NB> text returned by the server.  So, would the recv() function be a better
  NB> choice to read the socket?  Especially since two to five lines (now
  NB> including the END token) could be available and the data length is
  NB> variable.

if you are sticking with a line oriented protocol then <> is fine. it
still limits the client to being blocked on the protocol but that is ok
too if you understand that. just keep reading with <> in the loop until you see
END (or whatever token you choose) and collect the lines. then process
them and reenter the loop at the top. something like this (untested
code):

sub get_results {

	my ($sock) = @_ ;

	my @lines ;

	while( my $line = <$sock> ) {

		return @lines if $line =~ /^END$/ ;
		push @lines, $line ;
	}
}

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Architecture, Development, Training, Support, Code Review  ------
-----------  Search or Offer Perl Jobs  ----- http://jobs.perl.org  ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Wed, 09 Jan 2008 16:52:53 -0600
From: Nate Bargmann <n0nb.DO.NOT.SPAM@ME.n0nb.us>
Subject: Re: Force return of the diamond operator from network socket
Message-Id: <4vidnVNJ1NvYzRjanZ2dnUVZ_h7inZ2d@bluevalley.net>

On Wed, 09 Jan 2008 22:17:05 +0000, Uri Guttman wrote:

> if you are sticking with a line oriented protocol then <> is fine. it
> still limits the client to being blocked on the protocol but that is ok
> too if you understand that. just keep reading with <> in the loop until you see
> END (or whatever token you choose) and collect the lines. then process
> them and reenter the loop at the top. something like this (untested
> code):
> 
> sub get_results {
> 
> 	my ($sock) = @_ ;
> 
> 	my @lines ;
> 
> 	while( my $line = <$sock> ) {
> 
> 		return @lines if $line =~ /^END$/ ;
> 		push @lines, $line ;
> 	}
> }

Thanks so much, Uir!  That's exactly the kind of jump-start I needed.  It
works perfectly.  Now I need to brush up on my poor Perl skills.  :-)

- Nate >>

-- 

"The optimist proclaims that we live in the best of all
possible worlds.  The pessimist fears this is true."


------------------------------

Date: 09 Jan 2008 22:58:30 GMT
From: xhoster@gmail.com
Subject: Re: Force return of the diamond operator from network socket
Message-Id: <20080109175833.097$FO@newsreader.com>

Nate Bargmann <n0nb.DO.NOT.SPAM@ME.n0nb.us> wrote:
> I am involved with a project that will use a server process written in C
> and a client written in Perl.  The processes will communicate over a
> network socket that is opened when the Perl process starts and and
> remains open throughout the life of the Perl program.
>
> The server is queried by the Perl program and responds with short text
> strings that are newline terminated.  The server can return from one to
> three lines depending on the query.  This part is working well.
>
> Here is where I am running into trouble.  I am using the diamond
> operator to read from the socket as in:
>
> while (<$socket>) {
>     chomp;
>     print "$_\n";
> }
>
> however, the diamond operator doesn't return despite trying to send a
> NULL string from the C program through the socket.  Here is a snippet of
> my C program:
>
>         fprintf(fout, "");
>         fflush(fout);

How about sending an empty line:

fprintf(fout, "\n");
fflush(fout);

>
> however, I'm not certain that the NULL string is even making it through
> the socket to the Perl program.

How could it?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


------------------------------

Date: Wed, 09 Jan 2008 16:06:00 -0700
From: Steve Roscio <steve.roscio@hp.com>
Subject: Re: Force return of the diamond operator from network socket
Message-Id: <fm3k0p$efc$1@usenet01.boi.hp.com>

Nate Bargmann wrote:
> I am involved with a project that will use a server process written in C
> and a client written in Perl.  The processes will communicate over a
> network socket that is opened when the Perl process starts and and remains
> open throughout the life of the Perl program.
> 
> The server is queried by the Perl program and responds with short text
> strings that are newline terminated.  The server can return from one to
> three lines depending on the query.  This part is working well.
> 
> Here is where I am running into trouble.  I am using the diamond
> operator to read from the socket as in:
> 
> while (<$socket>) {
>     chomp;
>     print "$_\n";
> }
> 
> however, the diamond operator doesn't return despite trying to send a NULL
> string from the C program through the socket.  Here is a snippet of my C
> program:
> 
>         fprintf(fout, "");
>         fflush(fout);
> 
> however, I'm not certain that the NULL string is even making it through
> the socket to the Perl program.
> 
> Perhaps there is a better method of signalling the end of the C program's
> output to the Perl program.  At the moment I'm a bit stumped.
> 
> - Nate >>
> 

By the way, you can change what <> considers its line terminator by 
setting $/ ($INPUT_RECORD_SEPARATOR).  Look in perlvar for the details 
on this.

But that said, Ted's recommendation to use HTTP for your net
protocol is a very good recommendation.  If you need some more
structure to your data, you can add YAML inside the
HTTP.  A gazillion folks are doing this already with great success!


------------------------------

Date: Wed, 09 Jan 2008 21:14:02 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help with a Reg Ex
Message-Id: <uOahj.9144$fj2.2227@edtnps82>

J=FCrgen Exner wrote:
> J=FCrgen Exner <jurgenex@hotmail.com> wrote:
>> "amerar@iwc.net" <amerar@iwc.net> wrote:
>>> I have the following expression in my Perl script:
>>>
>>> if (/^"([^\,].+)"\,"$/)
>>>
>>> Although I know that it is checking to see if the string starts with
>>> some characters, it is not working for my input file.
>>>
>>> Can someone explain to me in english what it is doing???
>> Match a string that
>> ^ 	starts with=20
>> " 	a double quote
>> ( 	and then a group that consists of=20
>> [^\,] 		one of the three characters caret, backslash, comma
>=20
> Ooops, correction. Make that
> [^\,] 		any single character, that is not backslash or comma

You were right the first time.  A backslash before a normal character in =

a double quoted string is superfluous.

$ perl -le'print qr/[^\,]/'
(?-xism:[^,])



John
--=20
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


------------------------------

Date: Wed, 09 Jan 2008 21:17:09 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help with a Reg Ex
Message-Id: <pRahj.9146$fj2.7207@edtnps82>

J=FCrgen Exner wrote:
> J=FCrgen Exner <jurgenex@hotmail.com> wrote:
>> "amerar@iwc.net" <amerar@iwc.net> wrote:
>>> I have the following expression in my Perl script:
>>>
>>> if (/^"([^\,].+)"\,"$/)
>>>
>>> Although I know that it is checking to see if the string starts with
>>> some characters, it is not working for my input file.
>>>
>>> Can someone explain to me in english what it is doing???
>> Match a string that
>> ^ 	starts with=20
>> " 	a double quote
>> ( 	and then a group that consists of=20
>> [^\,] 		one of the three characters caret, backslash, comma
>=20
> Ooops, correction. Make that
> [^\,] 		any single character, that is not backslash or comma

A backslash before a normal character in a double quoted string is=20
superfluous.

$ perl -le'print qr/[^\,]/'
(?-xism:[^,])



John
--=20
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


------------------------------

Date: Wed, 9 Jan 2008 22:24:14 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Help with a Reg Ex
Message-Id: <pan.2008.01.09.21.24.14@rtij.nl.invlalid>

On Wed, 09 Jan 2008 20:40:49 +0000, Jürgen Exner wrote:

> Jürgen Exner <jurgenex@hotmail.com> wrote:
>>"amerar@iwc.net" <amerar@iwc.net> wrote:
>>>
>>>I have the following expression in my Perl script:
>>>
>>>if (/^"([^\,].+)"\,"$/)
>>>
>>>Although I know that it is checking to see if the string starts with
>>>some characters, it is not working for my input file.
>>>
>>>Can someone explain to me in english what it is doing???
>>
>>Match a string that
>>^ 	starts with
>>" 	a double quote
>>( 	and then a group that consists of
>>[^\,] 		one of the three characters caret, backslash, 
comma
> 
> Ooops, correction. Make that
> [^\,] 		any single character, that is not backslash or 
comma

No, is not comma:

[martijn@dexter ~]$  perl -e 'print "yes\n" if "," =~ /[^\,]/'
[martijn@dexter ~]$  perl -e 'print "yes\n" if "\\" =~ /[^\,]/'
yes
[martijn@dexter ~]$ 

HTH,
M4


------------------------------

Date: Wed, 9 Jan 2008 22:29:47 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Help with a Reg Ex
Message-Id: <pan.2008.01.09.21.29.47@rtij.nl.invlalid>

On Wed, 09 Jan 2008 12:06:35 -0800, amerar@iwc.net wrote:

> On Jan 9, 2:39 pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>> On Wed, 09 Jan 2008 11:00:18 -0800, ame...@iwc.net wrote:
>> > I have the following expression in my Perl script:
>>
>> > if (/^"([^\,].+)"\,"$/)

(snip)

> I might add, the input file looks like this:
> 
> "#ABC","
> [
> ","ABC Dispensing designs, manufactures and services dispensing systems
(snip)

Yes, that regex will match the first line.

$  perl -e 'print "yes\n" if "\"#ABC\",\"" =~ /^"([^\,].+)"\,"$/'
yes

(Note extra backslashes in the input line because this is executed from 
the commandline)

BTW, the backslashes before the commas are completely unneeded.

$  perl -e 'print "yes\n" if "\"#ABC\",\"" =~ /^"([^,].+)","$/'
yes

HTH,
M4


------------------------------

Date: Wed, 09 Jan 2008 21:42:22 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Help with a Reg Ex
Message-Id: <epfao3d0h63h05cdpvn5aghi2joe3fookd@4ax.com>

"John W. Krahn" <someone@example.com> wrote:
>Jürgen Exner wrote:
>> Jürgen Exner <jurgenex@hotmail.com> wrote:

>>> [^\,] 		one of the three characters caret, backslash, comma
>> 
>> Ooops, correction. Make that
>> [^\,] 		any single character, that is not backslash or comma
>
>You were right the first time.  A backslash before a normal character in 
>a double quoted string is superfluous.

Yes, but:
- this is not a double quoted string but a RE character class. So the
backslash would be taken literally ARAIR.
- My mistake was to not consider that ^ at the beginning of a character
class indicates the negation of that class.

jue


------------------------------

Date: Wed, 09 Jan 2008 21:45:18 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help with a Reg Ex
Message-Id: <Ofbhj.9148$fj2.9063@edtnps82>

Martijn Lievaart wrote:
> On Wed, 09 Jan 2008 12:06:35 -0800, amerar@iwc.net wrote:
> 
>> On Jan 9, 2:39 pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>>> On Wed, 09 Jan 2008 11:00:18 -0800, ame...@iwc.net wrote:
>>>> I have the following expression in my Perl script:
>>>> if (/^"([^\,].+)"\,"$/)
> 
> (snip)
> 
>> I might add, the input file looks like this:
>>
>> "#ABC","
>> [
>> ","ABC Dispensing designs, manufactures and services dispensing systems
> (snip)
> 
> Yes, that regex will match the first line.
> 
> $  perl -e 'print "yes\n" if "\"#ABC\",\"" =~ /^"([^\,].+)"\,"$/'
> yes
> 
> (Note extra backslashes in the input line because this is executed from 
> the commandline)
> 
> BTW, the backslashes before the commas are completely unneeded.
> 
> $  perl -e 'print "yes\n" if "\"#ABC\",\"" =~ /^"([^,].+)","$/'
> yes

Actually, none of the backslashes are really needed:

perl -e 'print qq/yes\n/ if q/"#ABC","/ =~ /^"([^,].+)","$/'



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


------------------------------

Date: Wed, 09 Jan 2008 22:00:28 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help with a Reg Ex
Message-Id: <0ubhj.9152$fj2.1928@edtnps82>

J=FCrgen Exner wrote:
> "John W. Krahn" <someone@example.com> wrote:
>> J=FCrgen Exner wrote:
>>> J=FCrgen Exner <jurgenex@hotmail.com> wrote:
>=20
>>>> [^\,] 		one of the three characters caret, backslash, comma
>>> Ooops, correction. Make that
>>> [^\,] 		any single character, that is not backslash or comma
>> You were right the first time.  A backslash before a normal character =
in=20
>> a double quoted string is superfluous.
>=20
> Yes, but:
> - this is not a double quoted string but a RE character class. So the
> backslash would be taken literally ARAIR.

Unless the regular expression uses single quote delimiters the pattern=20
is first interpolated as if it were a double quoted string.

perldoc perlop

Read through the sections "Quote and Quote-like Operators", "Regexp=20
Quote-Like Operators" and "Gory details of parsing quoted constructs".



John
--=20
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


------------------------------

Date: Wed, 09 Jan 2008 13:12:08 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: how to do bit complement in perl
Message-Id: <090120081312089690%jimsgibson@gmail.com>

In article
<8b9c4337-421b-4da3-919d-a05e78702786@f47g2000hsd.googlegroups.com>,
IJALAB <balaji.draj@gmail.com> wrote:

> hi all,
> 
> i have a file in which there are 8 byte hex values one followed by
> another. For example:
> 2A414364
> 00001DA9
> 01A3F9DD
> 3FFFF661
> 00EE6670
> 000011CF
> 2BC43FD0
> 3FEB0003
> 3F7FFF40
> 
> I need to check for the last bit in every data and if it being set,
> then the next data's 24 bits have to be inverted(assuming last bit is
> d31, starting from d26 to d7 needs to be inverted). For example:
> 1st data 0x2A414364 has last bit as '0' so the next word can be
> retained as same.But, 00001DA9(2nd data), the last bit is '1' so the
> next data  01A3F9DD will have to be printed as 3e5c061d. so, for the
> upper set of data, the below data needs to be printed. how do i do bit
> complement in hex using perl.
> 
> 2a414364
> 00001da9
> 3e5c061d
> 000009a1
> 3f1199b0
> 000011cf
> 143bc010
> 3feb0003
> 00800080

You can complement bits by exclusive or'ing with a suitable bit mask.
Perl treats scalars as binary numbers in bitwise operations: &, |, ^.

I don't quite follow your bit numbering, but the following seems to do
what you want:

#!/usr/local/bin/perl
use strict;
use warnings;

my $invert;
my $data = 0x3fffffc0;
my $mask = $data ^ 0x7fffffff;

while(<DATA>) {
  chomp;
  my $n = hex($_);
  if( $invert ) {
    $n = ($n & $mask) | ( ($n & $data) ^ $data);
  }
  printf "%08x\n", $n;
  $invert = $n & 1; # won't work if data includes last bit!
}
__DATA__
2A414364
00001DA9
01A3F9DD
3FFFF661
00EE6670
000011CF
2BC43FD0
3FEB0003
3F7FFF40

 ... producing ...

2a414364
00001da9
3e5c061d
000009a1
3f1199b0
000011cf
143bc010
3feb0003
00800080

Note the warning on saving the last bit of each number. If your data
field includes bit 0 (leftmost), then you will have to save the bit in
an other variable.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Wed, 09 Jan 2008 13:20:11 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Search/Replace text in XML file
Message-Id: <090120081320118663%jimsgibson@gmail.com>

In article
<5d60d81b-4be0-48b6-8e57-f8c840597e78@p69g2000hsa.googlegroups.com>,
Lax <lax_reddy@hotmail.com> wrote:

> Hello all,
> I'm trying to search and replace  the value of a tag in an xml file.
> I'm not in a position to use the usual XML parsers as the version of
> Perl I'm required to use
> doesnt contain any of the XML libraries. I can use Text::Balanced, but
> I want to deal with the xml file on a
> line-by-line basis, as the value of my tag could strecth over multiple-
> lines.

[data, program snipped]

> ------------------------------------------
> 
> The above script works, and a "diff bak <xml-file>" gives me the
> expected result when the stand-alone <version> is all on one line, I
> cant get this working when its extended over multiple-lines.
> 
> Could anyone give me some pointers, please?

Read the entire file into a single scalar:

  my $contents = do { local $/; <IN> };

Then add the /s modifier to your regular expression so that the '.'
special character will match the newlines embedded in your string.

See 'perldoc 'q entire' and 'perldoc perlre'.

Also read the documentation on the File::Slurp module, although that is
not a core module and may not be loaded with your Perl.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Wed, 09 Jan 2008 21:23:58 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Search/Replace text in XML file
Message-Id: <OXahj.9147$fj2.8062@edtnps82>

Jim Gibson wrote:
> In article
> <5d60d81b-4be0-48b6-8e57-f8c840597e78@p69g2000hsa.googlegroups.com>,
> Lax <lax_reddy@hotmail.com> wrote:
> 
>> Hello all,
>> I'm trying to search and replace  the value of a tag in an xml file.
>> I'm not in a position to use the usual XML parsers as the version of
>> Perl I'm required to use
>> doesnt contain any of the XML libraries. I can use Text::Balanced, but
>> I want to deal with the xml file on a
>> line-by-line basis, as the value of my tag could strecth over multiple-
>> lines.
> 
> [data, program snipped]
> 
>> ------------------------------------------
>>
>> The above script works, and a "diff bak <xml-file>" gives me the
>> expected result when the stand-alone <version> is all on one line, I
>> cant get this working when its extended over multiple-lines.
>>
>> Could anyone give me some pointers, please?
> 
> Read the entire file into a single scalar:
> 
>   my $contents = do { local $/; <IN> };
> 
> Then add the /s modifier to your regular expression so that the '.'
> special character will match the newlines embedded in your string.
> 
> See 'perldoc 'q entire' and 'perldoc perlre'.
ITYM:  perldoc -q entire



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


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1183
***************************************


home help back first fref pref prev next nref lref last post