[31552] in Perl-Users-Digest
Perl-Users Digest, Issue: 2811 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 9 16:09:24 2010
Date: Tue, 9 Feb 2010 13: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 Tue, 9 Feb 2010 Volume: 11 Number: 2811
Today's topics:
Re: can I get a new httpd.conf file <john@castleamber.com>
Re: can I get a new httpd.conf file <cartercc@gmail.com>
Re: can I get a new httpd.conf file <john@castleamber.com>
Re: can I get a new httpd.conf file <delcofiftyfive@gmail.com>
Re: can I get a new httpd.conf file <cartercc@gmail.com>
help with big numbers and DBI (hymie!)
Re: help with big numbers and DBI <smallpond@juno.com>
Re: help with big numbers and DBI <cartercc@gmail.com>
Re: help with big numbers and DBI <RedGrittyBrick@spamweary.invalid>
Re: help with big numbers and DBI <ben@morrow.me.uk>
Re: Math not working <ben@morrow.me.uk>
perl read bin file <m@m.ccc>
Re: perl read bin file <jurgenex@hotmail.com>
Re: perl read bin file <m@m.ccc>
Re: perl read bin file <m@m.ccc>
Re: perl read bin file <jurgenex@hotmail.com>
Reading binary file created a C++ program inside a Perl <freesoft12@gmail.com>
Re: Reading binary file created a C++ program inside a <hjp-usenet2@hjp.at>
Re: Reading binary file created a C++ program inside a <hjp-usenet2@hjp.at>
Re: Reading binary file created a C++ program inside a <peter@makholm.net>
Re: shebang and ubuntu <pawnMU@NGprawn.mine.nu>
Re: shebang and ubuntu <Huge@nowhere.much.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 09 Feb 2010 10:41:18 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: can I get a new httpd.conf file
Message-Id: <874olqcqfl.fsf@castleamber.com>
Tad McClellan <tadmc@seesig.invalid> writes:
> John Bokma <john@castleamber.com> wrote:
>> Myron <delcofiftyfive@gmail.com> writes:
>>
>>> I have changed mine so many times that I no longer know what I
>>> changed.
>>> How do I get a new, clean one for OpenBSD 4.6 apache.?
>>
>> Kind request to the regulars here: If you see a question that has
>> nothing to do with Perl, or in any other way breaks the posting
>> guidelines:
>>
>> Take a deep breath, and move on to the next message.
>
>
> I will not be honoring your request.
Heh, of course not, because you fit the shoe perfectly. And fear not, I
wasn't expecting anyone to honor my request; but I was somehow hoping.
But there is probably a reason people like you /have to jump/ on every
newbie posting wrong with a "holier than thou" attitude.
I do understand the need for correction, been there and stuff. But there
is no need to do it in asshole mode collectively.
>> Somehow those posts attract 5+ regulars all stating nearly the same
>> message, and causing IMO noise that could've been prevented.
>
> You have a strange notion of cause and effect...
Rest assured, I consider the original post also noise, and I do
understand that noise is unwelcome.
*But* 5+ regulars posting all the same knee jerking message is also
annoying. Maybe I experience this because a) I have taken a break from
Usenet for about a year (got tired of exactly this and related
attitude), and b) I rarely see this behavior in comp.lang.python and
some other groups I follow.
You can now reply that I then should go there and leave you all to
it. Well, rest assured (and save time so you can tear another asshole in
some newbie), I am already considering to leave comp.lang.perl.misc
behind. Won't be the first time, but will be the last. And based on the
daily traffic that I see, you and your trigger happy buddies will soon
be alone.
Perl is to me a great language, it's only sad that its community, at
least the part that's visible on Usenet has so many rotten apples. And
yes, I might have been one of them, /but/ are not blind.
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
------------------------------
Date: Tue, 9 Feb 2010 09:01:17 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: can I get a new httpd.conf file
Message-Id: <36ac81c0-e68c-493a-869d-9673e687f9cd@y33g2000yqb.googlegroups.com>
On Feb 8, 7:16=A0pm, John Bokma <j...@castleamber.com> wrote:
> Kind request to the regulars here: If you see a question that has
> nothing to do with Perl, or in any other way breaks the posting
> guidelines:
Either provide the answer if such can be done expeditiously, or point
the poster to the correct resource. DO NOT (!!!) insult, flame, or
criticize the poster as he may not know better (except for those
posters who abuse the privilege of posting here.)
> Somehow those posts attract 5+ regulars all stating nearly the same
> message, and causing IMO noise that could've been prevented.
First, if you consider this noise, you obviously don't read many
groups. c.l.p.m. is remarkable for its quietness and lack of noise.
Second, we all learn something sometimes from reading the replies to
such posts. If you consider that you have nothing left to learn, you
are truly ignorant.
I'm not being personally critical of you, or trying to insult you in
any way, just making a (very short) case for patience, forbearance,
tolerance, humility, and helpfulness.
CC
------------------------------
Date: Tue, 09 Feb 2010 11:45:53 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: can I get a new httpd.conf file
Message-Id: <87wrymb8vi.fsf@castleamber.com>
ccc31807 <cartercc@gmail.com> writes:
> On Feb 8, 7:16Â pm, John Bokma <j...@castleamber.com> wrote:
>> Kind request to the regulars here: If you see a question that has
>> nothing to do with Perl, or in any other way breaks the posting
>> guidelines:
>
> Either provide the answer if such can be done expeditiously, or point
> the poster to the correct resource. DO NOT (!!!) insult, flame, or
> criticize the poster as he may not know better (except for those
> posters who abuse the privilege of posting here.)
My point exactly.
>> Somehow those posts attract 5+ regulars all stating nearly the same
>> message, and causing IMO noise that could've been prevented.
>
> First, if you consider this noise, you obviously don't read many
> groups.
I do. Moreover, I've been on Usenet for 16+ years.
> c.l.p.m. is remarkable for its quietness and lack of noise.
Quietness, yes. Lack of noise, certainly not.
> Second, we all learn something sometimes from reading the replies to
> such posts.
See above, I am talking about posts that are considered off-topic or in
any other way a "violation" of the posting guide lines. Such posts are
often met with a knee jerk reply by 5+ regulars; i.e. they insult, flame,
or critisize a poster who may not know better.
> If you consider that you have nothing left to learn, you
> are truly ignorant.
If that was the case I wouldn't be around here, nor would I've written
my request.
> I'm not being personally critical of you, or trying to insult you in
> any way, just making a (very short) case for patience, forbearance,
> tolerance, humility, and helpfulness.
That's exactly what I tried to do here as well:
If ask for patience & forbearance; if you (in general) see a posting
that's clearly off-topic or violates the posting guidelines: take a deep
breath, and move on to the next post. Because there is always someone
who can't resist, and will point out what an idiot (since that's in my
opinion most of the time the nuance of the reply) the OP is.
But yeah, like I wrote earlier, just after I had posted it I already had
the feeling that my post was futile. Time will tell, and I hope my
feeling is wrong.
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
------------------------------
Date: Tue, 9 Feb 2010 12:33:52 -0800 (PST)
From: Myron <delcofiftyfive@gmail.com>
Subject: Re: can I get a new httpd.conf file
Message-Id: <a944857f-3328-4770-8318-a2e64badf8b3@q16g2000yqq.googlegroups.com>
> >> Somehow those posts attract 5+ regulars all stating nearly the same
> >> message, and causing IMO noise that could've been prevented.
this reminds me of a story:
There was this guy that went into a grocery store and he askes for a
mixer. The guy there says "That building acrost the street has them,
you can look there." So the guy walks out of the store. But before he
gets to the door, two guys, with oversize pants hanging off their butt
and ball caps on backwards, walk up on each side of him and ask "What
are you doing here? Don't you know this is a grocery store? You know
that this is a grocery store, why are you bothering us about a pan?
Pans aren't groceries. DUH."
I am sure you wouldn't do this in a grocery store, you shouldn't do it
here either.
I would like to thank RedGrittyBrick again for directing me to the
correct forum. Also I would like an appoligy from Tad McClellan for
asserting that I was rude by asking a question in ignorance, and
replying to his question.
I am writing this in an effort to keep this group healthy so it don't
go down in flames like many others. I haven't participated in
newsgroups for about 10 years. I am using a Perl scrpt and will edit
it in the future, and it would be nice to have someplace I could go
for help.
------------------------------
Date: Tue, 9 Feb 2010 12:55:04 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: can I get a new httpd.conf file
Message-Id: <82d010d4-7d96-4dd8-8685-79c6e7ccad09@g27g2000yqh.googlegroups.com>
On Feb 9, 3:33=A0pm, Myron <delcofiftyf...@gmail.com> wrote:
> I am writing this in an effort to keep this group healthy so it don't
> go down in flames like many others. =A0I haven't participated in
> newsgroups for about 10 years. =A0I am using a Perl scrpt and will edit
> it in the future, and it would be nice to have someplace I could go
> for help.
Develop a thick skin and pay no attention to the insulting jerks (of
which I have been one and probably will be one again.)
Sometimes, the insults have a point, and wittingly or not you deserve
to be the target of the insults. I have been such a target and
probably will be again.
Remember the old saw that ninety percent of all communication is non-
verbal, and that all we get here is the ten percent that is verbal, so
make allowance for the ninety percent that can't be conveyed with mere
words.
CC.
------------------------------
Date: Tue, 09 Feb 2010 13:47:19 GMT
From: hymie@lactose.homelinux.net (hymie!)
Subject: help with big numbers and DBI
Message-Id: <HHdcn.47922$zN4.14362@newsfe05.iad>
Greetings. I'm not sure exactly where my problem is, and I'm looking
for a little help. I hope my need to anonymize the info will not
impact your ability to guide me.
I have an MSSQL database. I connect to it with SQL Server, run a
query "select content_id from log" with a "where" clause I'm not
allowed to broadcast, and I get these results:
1037479785592177191
1037222160396202204
1036993281177442875
1037489555080390716
1037253823299245752
I probably need to note that "content_id" is defined in the database
as a "bigint not null".
I run a perl script with the same query:
my $query = "select content_id from log ";
my $st = $ardbh->prepare($query);
$st->execute(@ARGV);
while (my @row = $st->fetchrow_array)
{
print "$row[0]\n";
}
I get this result:
1.03747978559218e+18
1.0372221603962e+18
1.03699328117744e+18
1.03748955508039e+18
1.03725382329925e+18
So I made a slight change to my script:
while (my @row = $st->fetchrow_array)
{
$row[0] = sprintf "%ld",$row[0];
print "$row[0]\n";
}
and I get this result:
1037479785592177152
1037222160396202240
1036993281177442816
1037489555080390656
1037253823299245696
Note that the last two or three digits do not match.
Then I found the "bignum" module and altered my script thusly:
use DBI;
use bignum;
my $query = "select content_id from log ";
my $st = $ardbh->prepare($query);
$st->execute(@ARGV);
while (my @row = $st->fetchrow_array)
{
$row[0] = $row[0] + 0;
print "$row[0]\n";
}
and got these results:
1037479785592180000
1037222160396200000
1036993281177440000
1037489555080390000
1037253823299250000
So perhaps I need a module other than "bignum"? Or is there something else
I need to do so that I end up with the correct numbers printed out?
Or am I just doomed by the lack of precision in my machines?
Thanks.
--hymie! http://lactose.homelinux.net/~hymie hymie@lactose.homelinux.net
-------------------------------------------------------------------------------
------------------------------
Date: Tue, 09 Feb 2010 09:26:52 -0500
From: Steve C <smallpond@juno.com>
Subject: Re: help with big numbers and DBI
Message-Id: <hkrrbl$1a0$1@news.eternal-september.org>
hymie! wrote:
> Greetings. I'm not sure exactly where my problem is, and I'm looking
> for a little help. I hope my need to anonymize the info will not
> impact your ability to guide me.
>
> I have an MSSQL database. I connect to it with SQL Server, run a
> query "select content_id from log" with a "where" clause I'm not
> allowed to broadcast, and I get these results:
>
> 1037479785592177191
> 1037222160396202204
> 1036993281177442875
> 1037489555080390716
> 1037253823299245752
>
> I probably need to note that "content_id" is defined in the database
> as a "bigint not null".
>
> I run a perl script with the same query:
>
> my $query = "select content_id from log ";
> my $st = $ardbh->prepare($query);
> $st->execute(@ARGV);
> while (my @row = $st->fetchrow_array)
> {
> print "$row[0]\n";
> }
>
> I get this result:
> 1.03747978559218e+18
> 1.0372221603962e+18
> 1.03699328117744e+18
> 1.03748955508039e+18
> 1.03725382329925e+18
>
> So I made a slight change to my script:
>
> while (my @row = $st->fetchrow_array)
> {
> $row[0] = sprintf "%ld",$row[0];
> print "$row[0]\n";
> }
>
> and I get this result:
> 1037479785592177152
> 1037222160396202240
> 1036993281177442816
> 1037489555080390656
> 1037253823299245696
>
> Note that the last two or three digits do not match.
>
> Then I found the "bignum" module and altered my script thusly:
>
> use DBI;
> use bignum;
> my $query = "select content_id from log ";
> my $st = $ardbh->prepare($query);
> $st->execute(@ARGV);
> while (my @row = $st->fetchrow_array)
> {
> $row[0] = $row[0] + 0;
> print "$row[0]\n";
> }
>
> and got these results:
> 1037479785592180000
> 1037222160396200000
> 1036993281177440000
> 1037489555080390000
> 1037253823299250000
>
> So perhaps I need a module other than "bignum"? Or is there something else
> I need to do so that I end up with the correct numbers printed out?
> Or am I just doomed by the lack of precision in my machines?
>
> Thanks.
>
This is perl on my 32-bit desktop system:
perl -V |grep use64bitint
use64bitint=undef use64bitall=undef uselongdouble=undef
This is from an Opteron server running CentOS 64-bit:
perl -V |grep use64bitint
use64bitint=define use64bitall=define uselongdouble=undef
So your results may change depending on what perl build you are using.
------------------------------
Date: Tue, 9 Feb 2010 06:58:02 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: help with big numbers and DBI
Message-Id: <b9c4ad30-68ac-413c-8169-f7faabed6ad3@f8g2000yqn.googlegroups.com>
On Feb 9, 8:47=A0am, hy...@lactose.homelinux.net (hymie!) wrote:
> I have an MSSQL database. =A0I connect to it with SQL Server, run a
> query "select content_id from log" with a "where" clause I'm not
> allowed to broadcast, and I get these results:
>
> 1037479785592177191
> 1037222160396202204
> 1036993281177442875
> 1037489555080390716
> 1037253823299245752
If these are keys, then you probably want to manipulate them as
strings rather than integers. Perl is perfectly happy to accept a
string of any size, as long as the hardware doesn't complain, and you
probably won't be performing arithmetic on your keys anyway.
> my $query =3D "select content_id from log ";
> my $st =3D $ardbh->prepare($query);
> $st->execute(@ARGV);
> while (my @row =3D $st->fetchrow_array)
> {
> =A0 print "$row[0]\n";
>
> }
My general approach is to save the results of the fetch operation in a
hash reference ($row =3D $sth->fetchrow_hashref();) and then iterate
through the hash. If you are doing anything even remotely
sophisticated with the data, it's a lot easier to use the hash syntax
rather than the array syntax.
CC
------------------------------
Date: Tue, 09 Feb 2010 15:25:05 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: help with big numbers and DBI
Message-Id: <4b717e50$0$2477$db0fefd9@news.zen.co.uk>
On 09/02/2010 13:47, hymie! wrote:
> Greetings. I'm not sure exactly where my problem is, and I'm looking
> for a little help. I hope my need to anonymize the info will not
> impact your ability to guide me.
>
> I have an MSSQL database. I connect to it with SQL Server, run a
> query "select content_id from log" with a "where" clause I'm not
> allowed to broadcast, and I get these results:
>
> 1037479785592177191
> 1037222160396202204
> 1036993281177442875
> 1037489555080390716
> 1037253823299245752
>
> I probably need to note that "content_id" is defined in the database
> as a "bigint not null".
>
> I run a perl script with the same query:
>
> my $query = "select content_id from log ";
> my $st = $ardbh->prepare($query);
> $st->execute(@ARGV);
> while (my @row = $st->fetchrow_array)
> {
> print "$row[0]\n";
> }
>
> I get this result:
> 1.03747978559218e+18
> 1.0372221603962e+18
> 1.03699328117744e+18
> 1.03748955508039e+18
> 1.03725382329925e+18
>
> So I made a slight change to my script:
>
> while (my @row = $st->fetchrow_array)
> {
> $row[0] = sprintf "%ld",$row[0];
> print "$row[0]\n";
> }
>
> and I get this result:
> 1037479785592177152
> 1037222160396202240
> 1036993281177442816
> 1037489555080390656
> 1037253823299245696
>
> Note that the last two or three digits do not match.
>
> Then I found the "bignum" module and altered my script thusly:
>
> use DBI;
> use bignum;
> my $query = "select content_id from log ";
> my $st = $ardbh->prepare($query);
> $st->execute(@ARGV);
> while (my @row = $st->fetchrow_array)
> {
> $row[0] = $row[0] + 0;
> print "$row[0]\n";
> }
>
> and got these results:
> 1037479785592180000
> 1037222160396200000
> 1036993281177440000
> 1037489555080390000
> 1037253823299250000
>
> So perhaps I need a module other than "bignum"? Or is there something else
> I need to do so that I end up with the correct numbers printed out?
> Or am I just doomed by the lack of precision in my machines?
Transforming your Perl quesion into an MS-SQL question, can you do
something like
select cast(content_id as varchar(19)) as content_id from ...
------------------------------
Date: Tue, 9 Feb 2010 15:26:37 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: help with big numbers and DBI
Message-Id: <deb847-6bo1.ln1@osiris.mauzo.dyndns.org>
Quoth hymie@lactose.homelinux.net (hymie!):
> Greetings. I'm not sure exactly where my problem is, and I'm looking
> for a little help. I hope my need to anonymize the info will not
> impact your ability to guide me.
>
> I have an MSSQL database. I connect to it with SQL Server, run a
> query "select content_id from log" with a "where" clause I'm not
> allowed to broadcast, and I get these results:
>
> 1037479785592177191
> 1037222160396202204
> 1036993281177442875
> 1037489555080390716
> 1037253823299245752
>
> I probably need to note that "content_id" is defined in the database
> as a "bigint not null".
>
> I run a perl script with the same query:
>
> my $query = "select content_id from log ";
> my $st = $ardbh->prepare($query);
> $st->execute(@ARGV);
> while (my @row = $st->fetchrow_array)
> {
> print "$row[0]\n";
> }
>
> I get this result:
> 1.03747978559218e+18
You need to read the DBI docs (and possibly the docs of whichever DBD
you are using: Sybase?) to find out how to get DBI to return the data in
a different format. As cartercc said, you probably want to retrieve the
data as strings rather than numbers.
Ben
------------------------------
Date: Tue, 9 Feb 2010 13:26:11 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Math not working
Message-Id: <jc4847-qin1.ln1@osiris.mauzo.dyndns.org>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2010-02-08, Ben Morrow <ben@morrow.me.uk> wrote:
>
> >> In my first experiments, I saw that the behaviour with {fallback =>
> >> 1} was too error-prone - it was very hard for the developer to see
> >> whether the codepath was through convert-to-Perlish-data methods, or
> >> through the "specialized operations" methods.
> >>
> >> So I made the default 0.
>
> > I can see that might be a problem, though I think it's one the developer
> > has to deal with anyway.
>
> With default being 1, it would be much harder for them to see the
> problem. The current way, it is much more probable that *they* would
> see the problem first, so the users would have less problems...
Yes, I suppose that's true. Certainly, there are no easy answers here.
> > Would you agree with me that new overload types
> > *must* default to falling back
>
> How would "new" types be different from the "old" ones? The problem
> existed back then; what changed?
What changed is that there are now published classes that use some
overloading, don't specify fallback, and don't overload the new type.
Take for example the new "qr" overload. Under 5.10 and earlier, treating
an object as a regex would invoke the stringify overload, so 5.12 must
continue to do so for objects that don't have a qr overload *even* if
fallback was not requested.
Ben
------------------------------
Date: Tue, 9 Feb 2010 12:18:13 +0100
From: "hehehe" <m@m.ccc>
Subject: perl read bin file
Message-Id: <hkrg9l$1sj4$1@news2.ipartners.pl>
Hello!
I have binfile and i need to find regular expression "1234test1234" in
1000 bin files... so ineed to use perl for this but std. function
open(FILE,"< bin.bin");
while (<FILE>) {
print $_;
}
not working... sow how to solve my problem?
regards - MJ
------------------------------
Date: Tue, 09 Feb 2010 03:25:54 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: perl read bin file
Message-Id: <96h2n5l759htve40df1ihmlu6jr8qkjg6k@4ax.com>
"hehehe" <m@m.ccc> wrote:
> I have binfile and i need to find regular expression "1234test1234" in
>1000 bin files... so ineed to use perl for this but std. function
>
>open(FILE,"< bin.bin");
>
>while (<FILE>) {
>print $_;
>}
>
>not working... sow how to solve my problem?
Had you asked perl to help then chances are you would know the answer
already:
>open(FILE,"< bin.bin");
open(FILE,'<', 'bin.bin') or die "Cannot open bin.bin because $!\n";
jue
------------------------------
Date: Tue, 9 Feb 2010 12:30:31 +0100
From: "hehehe" <m@m.ccc>
Subject: Re: perl read bin file
Message-Id: <hkrh0o$1t56$1@news2.ipartners.pl>
Uzytkownik "Jürgen Exner" <jurgenex@hotmail.com> napisal w wiadomosci
news:96h2n5l759htve40df1ihmlu6jr8qkjg6k@4ax.com...
> "hehehe" <m@m.ccc> wrote:
>> I have binfile and i need to find regular expression "1234test1234" in
>>1000 bin files... so ineed to use perl for this but std. function
>>
>>open(FILE,"< bin.bin");
>>
>>while (<FILE>) {
>>print $_;
>>}
>>
>>not working... sow how to solve my problem?
>
> Had you asked perl to help then chances are you would know the answer
> already:
>
>>open(FILE,"< bin.bin");
>
> open(FILE,'<', 'bin.bin') or die "Cannot open bin.bin because $!\n";
>
> jue
not working error :
readline() on closed filehandle FILE at print_bin.pl line 4.
------------------------------
Date: Tue, 9 Feb 2010 12:45:51 +0100
From: "hehehe" <m@m.ccc>
Subject: Re: perl read bin file
Message-Id: <hkrhtg$1th1$1@news2.ipartners.pl>
Uzytkownik "Jürgen Exner" <jurgenex@hotmail.com> napisal w wiadomosci
news:96h2n5l759htve40df1ihmlu6jr8qkjg6k@4ax.com...
> "hehehe" <m@m.ccc> wrote:
>> I have binfile and i need to find regular expression "1234test1234" in
>>1000 bin files... so ineed to use perl for this but std. function
>>
>>open(FILE,"< bin.bin");
>>
>>while (<FILE>) {
>>print $_;
>>}
>>
>>not working... sow how to solve my problem?
>
> Had you asked perl to help then chances are you would know the answer
> already:
>
>>open(FILE,"< bin.bin");
>
> open(FILE,'<', 'bin.bin') or die "Cannot open bin.bin because $!\n";
>
> jue
my mistake bad path.... :-]
------------------------------
Date: Tue, 09 Feb 2010 04:00:31 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: perl read bin file
Message-Id: <bdj2n5d49sgvr82jtisft8h7r2nrfor84l@4ax.com>
"hehehe" <m@m.ccc> wrote:
>Uzytkownik "Jürgen Exner" <jurgenex@hotmail.com> napisal w wiadomosci
>news:96h2n5l759htve40df1ihmlu6jr8qkjg6k@4ax.com...
>> "hehehe" <m@m.ccc> wrote:
>>> I have binfile and i need to find regular expression "1234test1234" in
>>>1000 bin files... so ineed to use perl for this but std. function
>>>
>>>open(FILE,"< bin.bin");
>>>
>>>while (<FILE>) {
>>>print $_;
>>>}
>>>
>>>not working... sow how to solve my problem?
>>
>> open(FILE,'<', 'bin.bin') or die "Cannot open bin.bin because $!\n";
>>
>not working error :
>readline() on closed filehandle FILE at print_bin.pl line 4.
I find this highly suspicious. The open() was successful (i.e. you
didn't get an error message there) but the readline failed with "closed
filehandle"? I have a hard time believing that. Is there something you
are not telling us?
jue
------------------------------
Date: Tue, 9 Feb 2010 11:16:30 -0800 (PST)
From: "freesoft12@gmail.com" <freesoft12@gmail.com>
Subject: Reading binary file created a C++ program inside a Perl prog
Message-Id: <957dc71c-e579-4bc4-ac97-aea16c3fa93a@b35g2000vbc.googlegroups.com>
Hi,
I have a written a C++ program that writes a set of paths into a
binary file. In the program, the 'write_binary()', writes to the
binary file and the 'read_binary()' opens the binary file, reads the
data and prints it out.
Here is the C++ program:
-----------------------------
#include <vector>
#include <string>
#include <stdio.h>
using namespace std;
void
write_binary()
{
vector<string> v;
v.push_back("/a/b/c/d");
v.push_back("/e/f");
v.push_back("../h");
FILE *fp = fopen("rw_binary.dat","w");
if (!fp)
{
printf("Error: Unable to open ./rw_binary.dat\n");
exit(1);
}
for (vector<string>::const_iterator
it(v.begin()),itEnd(v.end());it!=itEnd;++it)
{
unsigned size = it->size()+1;
fwrite(&size,sizeof(unsigned),1,fp);
fwrite(it->c_str(),sizeof(char),size,fp);
}
fclose(fp);
}
void
read_binary()
{
FILE *fp = fopen("rw_binary.dat","r");
while (!feof(fp))
{
unsigned size(0);
fread(&size,sizeof(unsigned),1,fp);
char *buf = (char*)malloc(size*sizeof(char));
fread(buf,sizeof(char),size,fp);
printf("%s\n",buf);
free(buf);
}
fclose(fp);
}
int main()
{
write_binary();
read_binary();
return 0;
}
----------------------
I wanted to create a Perl program that mimics the 'read_binary()'. But
I am getting a perl warning ( I have the 'use strict & diagnostics').
Here it is:
-----------------------
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' && eval 'exec
perl -w -S $0 $argv:q' if 0;
#
use strict;
use diagnostics;
open(IN,"/home/rradhakr/progs/rw_binary.dat") or die "Cannot open
rw_binary.dat\n";
binmode(IN);
while (<IN>) {
my $buf = 0;
read(IN,$buf,6);
my $string = undef;
read(IN,$string,$size);
print "$size\n";
}
close(IN);
-------------------------
Here is the error I get Perl:
Argument "" isn't numeric in read at read_binary_file.pl line 13, <IN>
line 1 (#1)
(W numeric) The indicated string was fed as an argument to an
operator that expected a numeric value instead. If you're fortunate
the message will identify which operator was so unfortunate.
Any suggestions?
Regards
John
------------------------------
Date: Tue, 9 Feb 2010 20:37:47 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Reading binary file created a C++ program inside a Perl prog
Message-Id: <slrnhn3ecd.kvd.hjp-usenet2@hrunkner.hjp.at>
On 2010-02-09 19:16, freesoft12@gmail.com <freesoft12@gmail.com> wrote:
> unsigned size = it->size()+1;
> fwrite(&size,sizeof(unsigned),1,fp);
So this writes sizeof(unsigned) bytes containing the (implementation
defined) binary representation of an unsigned int. You will need to
check your compiler documentation for the details and be aware that they
can change when you use a different compiler (or the same compiler using
different flags).
> fwrite(it->c_str(),sizeof(char),size,fp);
This writes the string including the terminating "\0".
> while (<IN>) {
Here you read one line (i.e. everything up to including the first "\n"
byte). Why?
> my $buf = 0;
> read(IN,$buf,6);
^
Where does the number 6 come from?
You are obviously trying to read the unsigned int written by the C++
compiler. While it is theoretically possible that your unsigned ints are
6 bytes long, that would be extremely unusual. Most likely they are 4
bytes long (but 2 or 8 are also possible).
> my $string = undef;
> read(IN,$string,$size);
Where does $size come from? You read the size into $buf, not into $size.
Plus, the $buf will contain the size in the format specific to your C++
compiler, so you need to unpack() (see perldoc -f unpack) it before you
can use it.
> print "$size\n";
Why do you print $size instead of the $string?
> }
> close(IN);
hp
------------------------------
Date: Tue, 9 Feb 2010 20:42:43 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Reading binary file created a C++ program inside a Perl prog
Message-Id: <slrnhn3elk.kvd.hjp-usenet2@hrunkner.hjp.at>
On 2010-02-09 19:16, freesoft12@gmail.com <freesoft12@gmail.com> wrote:
> I wanted to create a Perl program that mimics the 'read_binary()'. But
> I am getting a perl warning ( I have the 'use strict & diagnostics').
>
> Here it is:
>
> -----------------------
> eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' && eval 'exec
> perl -w -S $0 $argv:q' if 0;
> #
>
> use strict;
> use diagnostics;
>
> open(IN,"/home/rradhakr/progs/rw_binary.dat") or die "Cannot open
> rw_binary.dat\n";
> binmode(IN);
> while (<IN>) {
> my $buf = 0;
> read(IN,$buf,6);
> my $string = undef;
> read(IN,$string,$size);
> print "$size\n";
> }
> close(IN);
> -------------------------
>
> Here is the error I get Perl:
>
> Argument "" isn't numeric in read at read_binary_file.pl line 13, <IN>
> line 1 (#1)
Just noticed this now. This is impossible. Your program cannot even
start since you forgot to declare $size.
You were obviously running a different program than the one you posted.
Please don't do that.
hp
------------------------------
Date: Tue, 09 Feb 2010 20:46:13 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: Reading binary file created a C++ program inside a Perl prog
Message-Id: <87mxzichve.fsf@vps1.hacking.dk>
"freesoft12@gmail.com" <freesoft12@gmail.com> writes:
> I wanted to create a Perl program that mimics the 'read_binary()'. But
> I am getting a perl warning ( I have the 'use strict & diagnostics').
Are you sure that you pasted the right code? Neither $string nor $size
is declared and I'm sure that 'use strict' would complain about this
before the erroryou have pasted?
> -----------------------
> eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' && eval 'exec
> perl -w -S $0 $argv:q' if 0;
> #
>
> use strict;
> use diagnostics;
>
> open(IN,"/home/rradhakr/progs/rw_binary.dat") or die "Cannot open
> rw_binary.dat\n";
A matter of style, but use a lexical filehandle and the three-argument
form of open. Incluing $! in the error message will also be usefull
some time in the future:
open my $fh, '<', '/home/rradhakr/progs/rw_binary.dat'
or die "Couldn't open rw_binary.dat: $!";
As a consequence all occurences of IN should be replaced by $fh.
> binmode(IN);
> while (<IN>) {
Here you read one line from the file including the line separator ("\n").
> my $buf = 0;
Why? $buf is unconditionally overwritten by the next statement
> read(IN,$buf,6);
Here you read the following 6 bytes into $buf.
> my $string = undef;
This "initialization" is even worse. You never have to do an explicite
initialization to undef. And then again, $string will be
unconditionally overwritten by the following read.
> read(IN,$string,$size);
Here you read the following $size bytes into $string. BUT you havn't
showed us where $size is declared, much less where it gets it's value
from. If you code uses 'use strict' you clearly havn't pasted you
complete code.
But my guess is that this is line 13 and you somehow never initializes
$size with an correct value.
> print "$size\n";
> }
> close(IN);
Mixing reading files with the <> operator and with read() is confusing
at best (and at least calls for a comment in you code) and plain wrong
most of time. My guess is that your case is the latter
//Makholm
------------------------------
Date: Tue, 9 Feb 2010 11:51:44 +0000
From: prawn <pawnMU@NGprawn.mine.nu>
Subject: Re: shebang and ubuntu
Message-Id: <gru747-uv9.ln1@prawn.mine.nu>
On Mon, 08 Feb 2010 17:24:14 -0700, Phred Phungus wrote:
> Since this is x-posted to alt.os.linux.ubuntu, I would be curious where
> others like to put their perl scripts.
/usr/local/bin for anything I write.
--
Leviticus 11:10
------------------------------
Date: 9 Feb 2010 13:52:50 GMT
From: Huge <Huge@nowhere.much.invalid>
Subject: Re: shebang and ubuntu
Message-Id: <7td7liFfh6U1@mid.individual.net>
On 2010-02-09, prawn <pawnMU@NGprawn.mine.nu> wrote:
> On Mon, 08 Feb 2010 17:24:14 -0700, Phred Phungus wrote:
>
>> Since this is x-posted to alt.os.linux.ubuntu, I would be curious where
>> others like to put their perl scripts.
>
> /usr/local/bin for anything I write.
It may also be worth noting that for anything more than a few lines of
shell script or perl, use a version control system, else you'll rapidly
forget what's what.
I seem to have Subversion installed on my Ubuntu box, although I suspect
that came with the NetBeans IDE.
[I'm learning Java. :o( ]
--
219361311
email me, if you must, at huge {at} huge (dot) org <dot> uk]
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2811
***************************************