[18983] in Perl-Users-Digest
Perl-Users Digest, Issue: 1178 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 22 18:17:33 2001
Date: Fri, 22 Jun 2001 15:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993247509-v10-i1178@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 22 Jun 2001 Volume: 10 Number: 1178
Today's topics:
Can't install CPAN module <ktappe@assocgraphics.com>
Re: Converting COBOL numbers <EUSWMCL@am1.ericsson.se>
Re: Converting COBOL numbers jim@buttafuoco.org
Re: libwww in Standard Distro? (was: Re: Grabbing a web <bart.lateur@skynet.be>
Re: newbie: sendmail based on array of addresses <ryan@don't.think.about.it.com>
Re: newbie: sendmail based on array of addresses <krahnj@acm.org>
Re: one liner ... simple question (Craig Berry)
Re: parsing perl to create list of undefined subroutine (Anno Siegel)
Re: parsing perl to create list of undefined subroutine (Sweth Chandramouli)
Perl *is* strongly typed (was Re: Perl description) (Randal L. Schwartz)
Re: Perl *is* strongly typed (was Re: Perl description) (Sweth Chandramouli)
Re: Perl *is* strongly typed (was Re: Perl description) (Mark Jason Dominus)
Perl Programmer needed (missrockieh)
Problem reading large files (dumb question?) <cjmackie@princeton.edu>
Re: Problem reading large files (dumb question?) <goldbb2@earthlink.net>
Re: regular expression problem (Xtreme)
what's the Perl Code for removing 1st two characters of <czajko@ocas.on.ca>
Re: what's the Perl Code for removing 1st two character <krahnj@acm.org>
Re: what's the Perl Code for removing 1st two character <kevinp@emerge-us.com>
Re: what's the Perl Code for removing 1st two character <lamp77@anti.spam.disinfo.net>
Re: what's the Perl Code for removing 1st two character <joe+usenet@sunstarsys.com>
Re: Why is perl faster then Tcl (Cameron Laird)
Re: Why is perl faster then Tcl lvirden@yahoo.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Jun 2001 21:49:06 GMT
From: Kurt Tappe <ktappe@assocgraphics.com>
Subject: Can't install CPAN module
Message-Id: <9h0egi$3r9$0@216.155.1.6>
Keywords: perl,cpan,make
Newbie question:
I'm trying to install the CPAN module Net::FTP for use with my Perl
scripting projects. But I've hit an odd problem.
After downloading and unarchiving the stuff, I'm able to create the
makefile and perform the make. However, making the test fails:
ai:/tmp/Net-FTP-Common-1.9$ make test
PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib
-I/opt/gnu//lib/perl5/5.0
0503/sun4-solaris -I/opt/gnu//lib/perl5/5.00503 test.pl
1..1
Can't locate Net/FTP.pm in @INC
BEGIN failed--compilation aborted at blib/lib/Net/FTP/Common.pm line
9.
BEGIN failed--compilation aborted at test.pl line 11.
not ok 1
make: *** [test_dynamic] Error 2
I assume this is because I was logged in as me, not as root. BUT, when
do the same steps as root, I hit a roadblock earlier in the process:
# perl Makefile.PL
Writing Makefile for Net::FTP::Common
# make
bash: make: command not found
# ./make
bash: ./make: No such file or directory
How is it I can't find make when I'm root? This is driving me more
than a bit nuts.
Thanks for any tips,
-Kurt
--
Kurt Tappe
Manager, Information Technology
Associates Graphic Services
Wilmington, DE
------------------------------
Date: Fri, 22 Jun 2001 14:40:15 -0400
From: William Cardwell <EUSWMCL@am1.ericsson.se>
Subject: Re: Converting COBOL numbers
Message-Id: <3B33910F.2A3A1192@am1.ericsson.se>
William Cardwell wrote:
>
> Hello,
>
> I have 10 character strings like the list below representing dollar
> amounts. I think they are some COBOL form such as "high punch" values,
> but maybe not.
>
> I tried all the unpack templates, and I would like not to have to load
> special packages because so far I use binary perl on Win32 and VMS.
>
> Any ideas as to what could be intended here and how to convert?
>
> Thanks.
>
> Will Cardwell
>
> 000014364{
> 000001026A
> 000002760A
> 000001620A
> 000011160A
> 000001026A
> 000000744A
> 000003810A
> 000000732A
> 000015052A
> 000010560A
> 000006435A
> 000000360A
> 000013759E
> 000011160A
> 000001980A
> 000002472F
> 000001819A
> 000007440A
> 000014560A
> 000000700A
> 000000640A
> 000002910A
> 000000340A
Replying to myself after researching on the web:
convertovrpnch {
# Will code in perl using the following info: wrc 06/22/01
# Specs described below found on following site:
# http://discinterchange.com/reading_COBOL_layouts_.html
# Value Character EBCDIC Hex code ASCII Hex code
#
# +0 { C0 7B
# +1 A C1 41
# +2 B C2 42
# +3 C C3 43
# +4 D C4 44
# +5 E C5 45
# +6 F C6 46
# +7 G C7 47
# +8 H C8 48
# +9 I C9 49
#
# -0 } D0 7D
# -1 J D1 4A
# -2 K D2 4B
# -3 L D3 4C
# -4 M D4 4D
# -5 N D5 4E
# -6 O D6 4F
# -7 P D7 50
# -8 Q D8 51
# -9 R D9 52
#
# To convert the zoned ASCII field which results from an EBCDIC to
ASCII
# character translation, to a leading sign numeric field, inspect the
last
# digit in the field. If it's a "{" replace the last digit with a 0
and
# make the number positive. If it's an "A" replace the last digit with
a 1
# and make the number positive, etc., etc. If the last digit is a "}"
# replace the last digit with a 0 and make the number negative. If
it's a
# "J" replace the last digit with a 1 and make the number negative,
etc.
# Follow these rules for all possible values.
#
# The overpunch for an EBCDIC "unsigned" value is an F0 hex, which,
when
# OR'd with the binary values 0-9, results in F0-F9, which are simply
the
# EBCDIC characters 0-9. When converted to ASCII these will become the
# ASCII characters 0-9. In this case, and this case only, the field
can be
# treated as if it were an EBCDIC numeric value (all characters), and
no
# further conversion is needed after translation to ASCII.
}
Thanks,
Will
------------------------------
Date: 22 Jun 2001 20:14:10 GMT
From: jim@buttafuoco.org
Subject: Re: Converting COBOL numbers
Message-Id: <9h08ui$n1c$1@pyrite.mv.net>
Will,
I use the following to convert
$string =~ tr/{ABCDEFGHI/0123456789/;
and
$string =~ tr/JKLMNOPQR}/1234567890/; (if this converts anything then $string*=-1
Jim
:
William Cardwell <EUSWMCL@am1.ericsson.se> wrote:
: Hello,
: I have 10 character strings like the list below representing dollar
: amounts. I think they are some COBOL form such as "high punch" values,
: but maybe not.
: I tried all the unpack templates, and I would like not to have to load
: special packages because so far I use binary perl on Win32 and VMS.
: Any ideas as to what could be intended here and how to convert?
: Thanks.
: Will Cardwell
: 000014364{
: 000001026A
: 000002760A
: 000001620A
: 000011160A
: 000001026A
: 000000744A
: 000003810A
: 000000732A
: 000015052A
: 000010560A
: 000006435A
: 000000360A
: 000013759E
: 000011160A
: 000001980A
: 000002472F
: 000001819A
: 000007440A
: 000014560A
: 000000700A
: 000000640A
: 000002910A
: 000000340A
--
****************************************************************************
Jim Buttafuoco Unix/Linux/Perl Consultant
Perl Hacker email: jim@buttafuoco.net
Linux Fan web: http://www.buttafuoco.net
****************************************************************************
------------------------------
Date: Fri, 22 Jun 2001 21:01:28 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: libwww in Standard Distro? (was: Re: Grabbing a web page?)
Message-Id: <mhc7jts6tesdd7t9n9684mopa6t12hvg34@4ax.com>
Jason Clifford wrote:
>> Which begs the question, "Why isn't libwww included as part of the standard
>> Perl distribution?" It seems like a tremendously useful and heavily used set
>> of utilities.
>
>Because while perl is a very good language for writing CGI in that is not
>it's only or even primary raison d'etre.
Oh, so let's dump CGI.pm from the distro, shall we. It's over a 100k, so
it's quite some saving.
You can use libwww in a non-CGI environmetn, you know. CGI is on the
server side, libwww on the client side.
--
Bart.
------------------------------
Date: Fri, 22 Jun 2001 14:07:17 -0400
From: "Ryan Covert" <ryan@don't.think.about.it.com>
Subject: Re: newbie: sendmail based on array of addresses
Message-Id: <pNLY6.3125$n%3.31034515@radon.golden.net>
Hi Jason,
Could you elaborate on various "preferred methods"? I'm looking to use
sendmail just like that and I'm hoping you can show me how to make Perl send
a quick'n'dirty e-mail using this same method.
Thanks,
Ryan
--
Ryan Covert
Punch Integrated Communications
Ph: (519) 826-9700 x235
Fx: (519) 826-9614
"Jason Clifford" <jason@uklinux.net> wrote in message
news:Pine.LNX.4.30.0106221731510.4515-100000@s1.uklinux.net...
> On Fri, 22 Jun 2001, Marshall Hunt wrote:
>
> > I've been handed some perl code, and I have an urgent need. I am
receiving
> > variables from an HTML form and based on what I receive in one of those
form
> > variables, I need to sendmail to a particular email address. Can anyone
> > show me basically how I would do this in Perl? Below is pseudocode for
what
> > I need:
> >
> > array email [ ][ ] =
> > {selection1, email1@it.com,
> > selection2, email2@it.com,
> > selection3, email3@it.com,
> > selection4, email4@it.com};
>
> Have you ever heard of a hash?
>
> my %selection;
>
> $selection{1}=email1@it.com;
> $selection{2}=email2@it.com;
>
> my $item = param('item');
> # You really should check that the value in item is valid data using a
> # regex at this point.
>
> if ( ! defined($selection{$item}) )
> {
> $emailaddress = "default\@it.com";
> }
> else
> {
> if (! validate($selection{$item}) # you need to write a sub to
> # validate the value in $selection{$item}
> {
> # not valid data
> $emailaddress = "default\@it.com";
> }
> $emailaddress = $selection{$item};
> }
>
> # and then on you go to use your prefered method to send the email on.
>
> Jason
>
------------------------------
Date: Fri, 22 Jun 2001 20:30:14 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: newbie: sendmail based on array of addresses
Message-Id: <3B33AAD0.13EAF00A@acm.org>
Marshall Hunt wrote:
>
> I've been handed some perl code, and I have an urgent need. I am receiving
> variables from an HTML form and based on what I receive in one of those form
> variables, I need to sendmail to a particular email address. Can anyone
> show me basically how I would do this in Perl? Below is pseudocode for what
> I need:
>
> array email [ ][ ] =
> {selection1, email1@it.com,
> selection2, email2@it.com,
> selection3, email3@it.com,
> selection4, email4@it.com};
>
> if (item == selection1)
> sendmail to email1@it.com;
> else if (item == selection2)
> sendmail to email2@it.com;
> else if (item == selection3);
> sendmail to email3@it.com
> else if (item == selection4);
> sendmail to email4@it.com
> else
> sendmail to default@it.com
my %email = ( 'selection1' => 'email1@it.com',
'selection2' => 'email2@it.com',
'selection3' => 'email3@it.com',
'selection4' => 'email4@it.com',
);
send_to_via_sendmail( $email{ $item } );
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 22 Jun 2001 20:22:11 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: one liner ... simple question
Message-Id: <tj7a7jffmtogfa@corp.supernews.com>
Walter Hafner (hafner-usenet@ze.tu-muenchen.de) wrote:
: I want to convert a list to a hash, so that all the list values become
: keys in the hash.
: Currently I use:
:
: map {$a{$_} = 1} @b;
:
: with @b being the list and %a the generated hash.
For reasons discussed in the faq and elsewhere, using map in void context
(that is, throwing away its returned list) is frowned upon. Using foreach
you can express the same technique like this:
$a{$_} = 1 foreach @b;
: Any other way of doing this? (Of course there ist - we're talking about
: Perl here :-)
My prefered idiom is
@a{@b} = (1) x @b;
The left-hand-side of this assignment is called a 'hash slice'. The
right-hand-side uses the x operator in its list-building mode.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Magick is the art and science of causing change in conformity
| with Will." - Aleister Crowley
------------------------------
Date: 22 Jun 2001 18:55:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: parsing perl to create list of undefined subroutines
Message-Id: <9h04ai$rgg$1@mamenchi.zrz.TU-Berlin.DE>
According to Sweth Chandramouli <sweth+perl@gwu.edu>:
> In article <dfKY6.379$Ga.97900@news1.rdc1.md.home.com>,
> Sweth Chandramouli <sweth+perl@gwu.edu> wrote:
> > . I can go to the end of my app in vi, do a
> >"!get_new_subs %", and have the skeletons for all of the placeholder subs
> >that I've used but not yet defined appended to the file. It isn't perfect,
> >obviously--there are lots of potential false positives (any text string
> >containing an & followed by text, for example) and false negatives
> >(dynamically generated subroutines don't get caught correctly)
>
> And, of course, it assumes that I use the &sub notation for all
> calls. Ever since I've started using this script, though, I've been doing
> that, so that isn't an issue.
You are aware of the implications of using & on sub calls, I assume?
(Bypassing of prototypes, @_ isn't built unless there are parentheses)
It is not exactly the done thing.
Personally, I have never missed a tool like the one you're writing.
Forgetting to write a subroutine that is called somewhere happens to
everyone, but it's no big deal. Perl tells you so. It *is* a
bit of an art to keep the number of "dangling" subroutines small,
but that's only part of the art of keeping a program runnable (and
testable) most of the time.
Anno
------------------------------
Date: Fri, 22 Jun 2001 19:41:37 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: parsing perl to create list of undefined subroutines
Message-Id: <RbNY6.1305$Ga.142992@news1.rdc1.md.home.com>
In article <9h04ai$rgg$1@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>You are aware of the implications of using & on sub calls, I assume?
>(Bypassing of prototypes, @_ isn't built unless there are parentheses)
>It is not exactly the done thing.
Why not? (I don't use function prototypes anyway, since
they aren't exactly reliable (at least in 5.005; I have no idea if they've
been improved in 5.6), and I always use parens on my sub calls when not
playing golf.)
>Personally, I have never missed a tool like the one you're writing.
>Forgetting to write a subroutine that is called somewhere happens to
>everyone, but it's no big deal. Perl tells you so. It *is* a
>bit of an art to keep the number of "dangling" subroutines small,
>but that's only part of the art of keeping a program runnable (and
>testable) most of the time.
It's not a question of eliminating dangling subroutines so
much as automating the task of putting in placeholders for those subs so that
I have a starting point from which to work when fleshing out the code. I
like to do my initial drafts of large programs in pseudocode, and I got in
the habit a while ago of making that pseudocode actual perl that just uses a
lot of placeholders; that means, though, that I can sometimes sit down and
hash out the general logic of a program and in the process use a few hundred
placeholder subs that I then need to define; it's simply a tedious process
to go through the entire file finding every one of those subs manually, so
I automated it. There's still usually the need to fire up the program and
wait for the interpreter to spit out an undefined subroutine error to find
the ones I've missed, but it's nice to have a good start.
-- Sweth.
--
Sweth Chandramouli ; <sweth+perl@gwu.edu>
------------------------------
Date: 22 Jun 2001 11:21:25 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <m1y9qk9xzu.fsf_-_@halfdome.holdit.com>
>>>>> "Cristian" == Cristian Cespedes V <ccespede@anakena.dcc.uchile.cl> writes:
Cristian> yes, i undestand the questions. I can suposse that Perl is
Cristian> weak typing (not strong typing)
No, Perl has strong compile-time typing for primitive data types
(scalars, arrays, hashes, filehandles), and strong run-time typing for
user-defined data types (but weak compile-time typing).
The compiler will abort if you try to put an array into a hash
variable: in fact, it can't even be specified because of the prefix
characters and the context they provide.
The runtime system will abort if you use a method on an object of the
wrong type. There's some work being done to detect this at
compile-time in Perl 6, but don't hold your breath for Perl 5 to get
it right.
I don't know where everyone gets this notion that Perl has "weak
typing". It's just not true, as long as you define the context
properly.
C++, by contrast, has strong compile-time typing, but weak run-time
typing, because you can cast a pointer to another type and call a
totally broken method on it. Crash!
--
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!
------------------------------
Date: Fri, 22 Jun 2001 19:23:47 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <7XMY6.1184$Ga.138139@news1.rdc1.md.home.com>
In article <m1y9qk9xzu.fsf_-_@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>I don't know where everyone gets this notion that Perl has "weak
>typing". It's just not true, as long as you define the context
>properly.
Yes, but Perl makes it easy to not define that context
properly--things like autovivification can let you think you are defining
one type of primitive when you are actually defining another if you aren't
paying close attention. Add to that the fact that use of warnings is
optional, and I can definitely see how people decide that Perl is weakly
typed--I know that I did when I first started using it.
-- Sweth.
--
Sweth Chandramouli ; <sweth+perl@gwu.edu>
------------------------------
Date: Fri, 22 Jun 2001 21:14:31 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <3b33b536.37c$36b@news.op.net>
In article <m1y9qk9xzu.fsf_-_@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>No, Perl has strong compile-time typing for primitive data types
>(scalars, arrays, hashes, filehandles),
I cannot imagine what you might mean by this, since each of these is
converted to the others automatically upon request, and hardly any
checking is done. If this qualifies as 'strong typing' then I must
conclude that 'strong typing' no longer has any meaning at all.
>The compiler will abort if you try to put an array into a hash
>variable: in fact, it can't even be specified because of the prefix
>characters and the context they provide.
Again, I think this makes a mockery of the concept of strong typing.
It seems to me that the only way to accept this and still have a
logical, consistent meaning for 'strongly typed' is to accept a
trivial definition, so that *every* language is strongly typed. If
you do this, the concept of 'strongly typed' uses any usefulness it
might have had.
In Perl,
@a = %h
and
%h = @a
are perfectly legal, and the compiler will not raise an error or even
a warning for them; it will instead apply an automatic conversion.
This behavior would appear to be the exact opposite of 'strongly
typed'.
awk is normally considered to be a not-strongly-typed language and is
frequently cited as a counterexample. But awk shows better diagnosis
of type errors than Perl in examples similar to the one you cited:
awk 'BEGIN { x["y"] = 1;
z = x }'
awk: cmd. line:2: fatal: attempt to use array `x' in a scalar context
I conclude from this that you would also consider awk to be a strongly
typed language, perhaps more strongly typed than Perl. If so, then
what you mean by 'strongly typed' above has nothing to do with the
what the mainstream of computer science means by it.
If this isn't what you meant, I would like to see what you would
consider to be an example of a non-strongly-typed language of any
sort, and an example of an assignment or binding allowed by this
language that is disallowed in Perl.
>C++, by contrast, has strong compile-time typing, but weak run-time
>typing, because you can cast a pointer to another type and call a
>totally broken method on it. Crash!
I suppose this is your example, but I don't find it very illuminating,
because you can do an analogous thing in Perl:
my $randal = PerlExpert->new(NAME => "Randal Schwartz");
$randal->{number_of_wheels} = 18;
$randal->{temperature_of_fusion} = "1600 Kelvins";
bless $randal => 'Adorable_Doggie';
$randal->wag_tail(); # Totally broken method! Crash!
I don't see how you conclude from this anything about the relative
run-time typing strength of C++ and Perl.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 22 Jun 2001 11:55:03 -0700
From: raquel@mamashealth.com (missrockieh)
Subject: Perl Programmer needed
Message-Id: <4cd600b4.0106221055.2114ba44@posting.google.com>
I'm looking for a PERL programmer to make a search engine to be used
in UNIX. The search engine will search through a specific
directory...I want to be able to add and delete pages from the
directory and have the the new pages added to the search and the
deleted pages deleted from the search...Will pay $$.
------------------------------
Date: Fri, 22 Jun 2001 16:38:22 -0400
From: "Christopher J. Mackie" <cjmackie@princeton.edu>
Subject: Problem reading large files (dumb question?)
Message-Id: <9h0abu$55t$1@cnn.Princeton.EDU>
Apologies if this is a CompSci 101 question--I'm self-taught.
I *really* need to read data out of a 14Gb binary file, convert it from
double to float, and write it into another file. The perl script I wrote
works great on smaller files, but every time I try to read() or sysread()
the big file, I get a core dump (segmentation fault). I'm not keeping the
data in memory--I write it out in 400Mb chunks. I know there are limits on
how much memory a 32-bit computer can address, but I'm reading these files
on the same machine that wrote them (an SGI Origin 2000), so it's got to be
possible to read/write them somehow. Is this there something different
about files over 2Gb, or am I just doing something stupid?
The code works fine on files up to 1.5 Gb. Since I don't control the size
of these input files, I can't specify exactly where the problems
start--somewhere between 1.5 and 14Gb is all I know.
The data are a huge matrix, with known row and column sizes, and while it
would be easier to do what I need to do in one pass, I'll happily settle for
instructions on how to break it into manageable chunks, if it's not possible
to read something this big directly in perl.
here's the code -- any ideas? And *thanks* in advance, --Chris
==========================
open(INFILE, "<$binfile") or die "oops!: $!";
binmode(INFILE): # I've tried it with and without this, since TFM says it's
not necessary on UNIX
while (sysread(INFILE, $val, 8, 0)==8)
{ # tried 'for' too--didn't work
$val= pack("f", unpack("d", $val));
push(@buffer, $val);
...
#Code to write out and empty buffer each 400Mb--buffer is not the
overflow problem.
# The script bombs before *any* data are written out, so somewhere in
the first loop.
...
} # end WHILE sysread
------------------------------
Date: Fri, 22 Jun 2001 18:06:34 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Problem reading large files (dumb question?)
Message-Id: <3B33C16A.19CF7D32@earthlink.net>
Christopher J. Mackie wrote:
>
> Apologies if this is a CompSci 101 question--I'm self-taught.
>
> I *really* need to read data out of a 14Gb binary file, convert it
> from double to float, and write it into another file. The perl script
> I wrote works great on smaller files, but every time I try to read()
> or sysread() the big file, I get a core dump (segmentation fault).
> I'm not keeping the data in memory--I write it out in 400Mb chunks. I
> know there are limits on how much memory a 32-bit computer can
> address, but I'm reading these files on the same machine that wrote
> them (an SGI Origin 2000), so it's got to be possible to read/write
> them somehow. Is this there something different about files over 2Gb,
> or am I just doing something stupid?
For any program to files over the 2Gb limit, it has to have been
specially compiled to do so. You need to recompile your perl binary
with the appropriate option(s) set. I think what you need is to have
the symbol _LARGE_FILES defined.
> The code works fine on files up to 1.5 Gb. Since I don't control the
> size of these input files, I can't specify exactly where the problems
> start--somewhere between 1.5 and 14Gb is all I know.
>
> The data are a huge matrix, with known row and column sizes, and while
> it would be easier to do what I need to do in one pass, I'll happily
> settle for instructions on how to break it into manageable chunks, if
> it's not possible to read something this big directly in perl.
If you can't recompile perl, you may have to split your files. I
suppose it all depends on how responsive your system administrator is to
your needs. Most sysadmins respond more quickly if you can do the
research and find out what needs to be changed yourself, before going to
them with your complaint. This way, you can say "The perl binary has
problem X. According to what I read, it can be fixed by doing Y," so
they don't have to go and look up Y themselves.
One possible solution is to use STDIN and STDOUT as your filehandles,
and hope that the shell you use has _LARGE_FILES defined.
If that doesn't work, you can write a C program for conversion or
splitting, compiled with the _LARGE_FILES defined, and open with open64
or fopen64 (instead of open or fopen).
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: 22 Jun 2001 11:22:30 -0700
From: lxl22@visto.com (Xtreme)
Subject: Re: regular expression problem
Message-Id: <91ff860e.0106221022.505ce10d@posting.google.com>
jacklam@math.uio.no (Peter J. Acklam) wrote in message news:<cxclmmk388v.fsf@masterblaster.uio.no>...
> lxl22@visto.com (Xtreme) wrote:
>
> > Assuming I have a string of the form "a_b_b_c" in which I don't
> > know how many "b_" substrings it has, how can I, in one single
> > s/// line replace every b_ for a "x_"? My main problem is that
> > I don't know how to tell the re engine how to replace it the
> > same number of times as it occurred.
>
> s/b_/x_/g;
>
> Peter
Thanks, Peter. I had forgotten to mention that a,b and c can each be
distinct or the same -- I don't know ahead of time, and that I don't
want to replace a or c (i.e. not the first or last in the string). I
figured it out in the mean time by going through (of all things) the
faq:
s/\G_b_/_x_/g;
I still don't really grasp the \G, but it works!
------------------------------
Date: Fri, 22 Jun 2001 20:07:21 GMT
From: "Daniel Czajko" <czajko@ocas.on.ca>
Subject: what's the Perl Code for removing 1st two characters of a string?
Message-Id: <GFCLE6.Hx0@alfalfa.utcs.utoronto.ca>
Actually, I need the code for removing:
-- 1st two characters
-- 1st three character
-- last two characters
from a string
Any help is much appreciated
Daniel Czajko
------------------------------
Date: Fri, 22 Jun 2001 20:46:14 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: what's the Perl Code for removing 1st two characters of a string?
Message-Id: <3B33AE94.FB5EC07E@acm.org>
Daniel Czajko wrote:
>
> Actually, I need the code for removing:
>
> -- 1st two characters
$string =~ s/^..//s;
$string = substr $string, 2;
$string = unpack 'x2 a*', $string;
> -- 1st three character
$string =~ s/^...//;
$string = substr $string, 3;
$string = unpack 'x3 a*', $string;
> -- last two characters
$string =~ s/..$//s;
$string = substr $string, 0, length( $string ) - 2;
> from a string
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 22 Jun 2001 16:55:36 -0500
From: "Kevin L. Papendick" <kevinp@emerge-us.com>
Subject: Re: what's the Perl Code for removing 1st two characters of a string?
Message-Id: <3B33BED8.D17D8FC0@emerge-us.com>
If that is exactly what you want to do, here's one way:
#!/usr/local/bin/perl -w
use strict;
my $orig = "The line to left chop";
my $chop_one = substr($orig, 1);
my $chop_two = substr($orig, 2);
my $chop_nine = substr($orig, 9);
print "$chop_one\n";
print "$chop_two\n";
print "$chop_nine\n";
Daniel Czajko wrote:
>
> Actually, I need the code for removing:
>
> -- 1st two characters
> -- 1st three character
> -- last two characters
>
> from a string
>
> Any help is much appreciated
>
> Daniel Czajko
--
Kevin L. Papendick
Sr. Programmer Analyst
E-Merge Strategies, Inc.
617 Main Street, Suite M104
Buffalo, NY 14203
PH: 716-847-8170
FAX: 716-847-8625
kevinp@emerge-us.com
www.emerge-us.com
------------------------------
Date: Fri, 22 Jun 2001 20:59:20 GMT
From: Bill Keenan <lamp77@anti.spam.disinfo.net>
Subject: Re: what's the Perl Code for removing 1st two characters of a string?
Message-Id: <Xns90C8AC12445F5lamp77antispamdisinf@142.77.1.194>
"Daniel Czajko" <czajko@ocas.on.ca> wrote in
news:GFCLE6.Hx0@alfalfa.utcs.utoronto.ca:
> Actually, I need the code for removing:
>
> -- 1st two characters
$tmp =~ s/^..(.*$)/$1/;
> -- 1st three character
$tmp =~ s/^...(.*$)/$1/;
> -- last two characters
$tmp =~ s/^.*(..$)/$1/;
>
> from a string
>
> Any help is much appreciated
>
> Daniel Czajko
>
>
>
>
>
------------------------------
Date: 22 Jun 2001 17:14:34 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: what's the Perl Code for removing 1st two characters of a string?
Message-Id: <m3g0cs2p51.fsf@mumonkan.sunstarsys.com>
Bill Keenan <lamp77@anti.spam.disinfo.net> writes:
> "Daniel Czajko" <czajko@ocas.on.ca> wrote in
> news:GFCLE6.Hx0@alfalfa.utcs.utoronto.ca:
>
> > Actually, I need the code for removing:
> >
> > -- 1st two characters
>
> $tmp =~ s/^..(.*$)/$1/;
>
> > -- 1st three character
> $tmp =~ s/^...(.*$)/$1/;
>
> > -- last two characters
> $tmp =~ s/^.*(..$)/$1/;
This one keeps only the last two chars, and the rest need
an s-modifier if $tmp has an "\n" somewhere (other than the end).
Using the lvalue property of substr is IMO cleaner:
1st two: substr($tmp, 0, 2) = "";
1st three: substr($tmp, 0, 3) = "";
last two: substr($tmp,-2, 2) = "";
--
Joe Schaefer "We are all naive; only about different things."
--Mark Twain
------------------------------
Date: 22 Jun 2001 13:24:05 -0500
From: claird@starbase.neosoft.com (Cameron Laird)
Subject: Re: Why is perl faster then Tcl
Message-Id: <D0FBCE8E3D749D0C.A4CCAFF987F28B9D.FFFFDAEF77942687@lp.airnews.net>
In article <m3u218v7jv.fsf@ns.bagley.org>,
Doug Bagley <usenet.2001-06-22@bagley.org> wrote:
>claird@starbase.neosoft.com (Cameron Laird) writes:
>> In article <3B2D938B.CB2D4C02@localhost.blorg>, <karl@localhost.blorg> wrote:
>> >Q: Why is perl faster than tcl?
>> .
>> .
>> .
>> >> I'm doing a paper on Tcl and perl and I have an import
>> >> quesition.
>> >>
>> >> Do you know why perl is so much faster then Tcl? I've
>> .
>> .
>> .
>> <URL: http://mini.net/tcl/1799.html > is slowly
>> accreting material that bears on this question.
>
>On that page, the following URL is referenced:
>
> http://www.equi4.com/md5/
>
>I have recently submitted a significantly faster version of the pure
>Perl MD5 code. It doesn't look like it has been posted yet, but it
Great!
>should put Perl ahead of the current Lua entry. The current code
That's a significant achievement.
.
.
.
>I would advise everyone not to trust benchmarks, nor to be quick to
>draw conclusions from them :-)
Me, too.
.
.
.
--
Cameron Laird <claird@NeoSoft.com>
Business: http://www.Phaseit.net
Personal: http://starbase.neosoft.com/~claird/home.html
------------------------------
Date: 22 Jun 2001 18:25:30 GMT
From: lvirden@yahoo.com
Subject: Re: Why is perl faster then Tcl
Message-Id: <9h02iq$hge$1@srv38.cas.org>
:> >> I'm doing a paper on Tcl and perl and I have an import
:> >> quesition.
:> >>
:> >> Do you know why perl is so much faster then Tcl? I've
:I would advise everyone not to trust benchmarks, nor to be quick to
:draw conclusions from them :-)
I would similarly advise people not to trust "common" knowledge, such as
the original question that was asked. Obviously, anyone can tilt the
game in any way they please.
--
--
"See, he's not just anyone ... he's my son." Mark Schultz
<URL: mailto:lvirden@cas.org> <URL: http://www.purl.org/NET/lvirden/>
Even if explicitly stated to the contrary, nothing in this posting
------------------------------
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.
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 V10 Issue 1178
***************************************