[12874] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 283 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 28 13:17:34 1999

Date: Wed, 28 Jul 1999 10:05:14 -0700 (PDT)
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, 28 Jul 1999     Volume: 9 Number: 283

Today's topics:
    Re: _Don't_ loose the connection <gt7202e@prism.gatech.edu>
    Re: a little motivation, anyone? <gt7202e@prism.gatech.edu>
    Re: Beginner needs help with a function <mike@crusaders.no>
    Re: Beginner needs help with a function (I R A Darth Aggie)
    Re: Beginner needs help with a function <tg@channel-one.de>
    Re: Beginner needs help with a function <marshalc@americasm01.nt.com>
    Re: Beginner needs help with a function (Larry Rosler)
    Re: Beginner needs help with a function (Larry Rosler)
    Re: Beginner needs help with a function (Larry Rosler)
    Re: Beginner needs help with a function (Larry Rosler)
    Re: Beginner needs help with a function <uri@sysarch.com>
    Re: Beginner-friendly group as cultural adaptation? (Tad McClellan)
    Re: Beginner-friendly group as cultural adaptation? <mike@crusaders.no>
    Re: Beginner-friendly group as cultural adaptation? (I R A Darth Aggie)
    Re: beginner-redirect and download <gt7202e@prism.gatech.edu>
    Re: Can perl declare constant? <c8133594@comp.polyu.edu.hk>
        cutom search engine? <pmt@top.mitre.org>
    Re: Date? <mhc@Eng.Sun.COM>
    Re: Directory Listing with Size <Adrian.Duncan@trinite.co.uk>
    Re: ebcdic packed numbers <uri@sysarch.com>
    Re: ebcdic packed numbers <uri@sysarch.com>
    Re: ebcdic packed numbers (Anno Siegel)
        eval renorum@my-deja.com
    Re: Help removing special characters from a string ryan7879@my-deja.com
        HELP! tied DB_RECNO ->put() fails with R_IAFTER (Sara London)
        help: push array refs into hash, sort by refs in hash (Rory C-L)
    Re: how to print an hexadecimal with more than 32 bits <sb@sdm.de>
    Re: how to print an hexadecimal with more than 32 bits (Anno Siegel)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Wed, 28 Jul 1999 11:31:21 -0400
From: andy barfoot <gt7202e@prism.gatech.edu>
Subject: Re: _Don't_ loose the connection
Message-Id: <379F2249.9224CD83@prism.gatech.edu>

Kaare Rasmussen wrote:
> 
> The problem: I'm planning a program that is supposed to use a browser as 
> the client. This means it will run through a web server of course. It
> a) uses a database. I don't want to open and close the database all the
> time
> b) builds a lot of objects. I don't want to rebuild them all the time

Take a look at www.fastcgi.com.  You can use the same process to handle
multiple requests.  Works with Apache.  May be want you want.



HTH,
-- 
 andy barfoot


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

Date: Wed, 28 Jul 1999 11:53:15 -0400
From: andy barfoot <gt7202e@prism.gatech.edu>
Subject: Re: a little motivation, anyone?
Message-Id: <379F276B.1AAE0F34@prism.gatech.edu>

Medley8086 wrote:
> 
> Ok, I'm running a win98 partition and a linux partition.  I have all sorts of
> programming tools, and have studied how to program in assembly and c++.  In
> addition, I plan to know c (should I bother after c++?  give me your opinion),
> pascal, euphoria, and some scripting languages by the end of the summer.
> Through all this planning, however, I keep running into the same problem with
> learning how to program.  I'm teaching myself, so the motivation isn't there.


You need
Bentley's "Programming Pearls", 	[Yes "pearls" not "perl" :) ]
Kernighan & Ritchie's "The C Programming Language",
Schwartz, Christensen, & Wall's "Learning Perl",
Satir & Brown's "C++: The Core Language".

This is about $100 worth of books, but if you absorb them you could
easily get a job starting at $20/hour. (With a degree/certification or
previous experience you can do better.)

Get a big city's newspaper and look at the want ads.  C,C++,Perl coding,
unix sysadmin stuff.. you're headed in the right direction.



-- 
 andy barfoot


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

Date: Wed, 28 Jul 1999 17:36:06 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: Beginner needs help with a function
Message-Id: <TrFn3.280$ZU.2504@news1.online.no>


Alec Kelingos <akelingos@petrosys-usa.com> wrote in message
news:01bed909$73961020$7637ebcf@psusa6.petrosys-usa.com...
> I need a function to trim the first/last characters off a string if and
> only if these characters are a user defined character.
> I'm reading records from the following file:
> |MICHIGAN|
> Other files have other first/last characters
> "MICHIGAN"
> But other files may just be
> MICHIGAN
> it alone?  Perhaps some niffty regular expression.

$line =~ s/
 ^([|\"]?) # grab the first character of the line if it's
           # either " or | and place it in $1
 (.*?)     # put the rest of the line in $2
 \1$       #except the last character if it's the same as $1
/
 $2        # and replace the entire line with $2
/x;

should do the trick.

--
Trond Michelsen





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

Date: 28 Jul 1999 15:33:05 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: Beginner needs help with a function
Message-Id: <slrn7pu8pm.gn3.fl_aggie@thepentagon.com>

On Wed, 28 Jul 1999 14:56:04 GMT, Alec Kelingos
<akelingos@petrosys-usa.com>, in
<01bed909$73961020$7637ebcf@psusa6.petrosys-usa.com> wrote:

+ I need a function to trim the first/last characters off a string if and
+ only if these characters are a user defined character.

perlfaq4: How do I strip blank space from the beginning/end of a string?

I presume you can change "blank space" into "any arbritary character"?

James


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

Date: 28 Jul 1999 15:52:31 GMT
From: Tobias Galitzien <tg@channel-one.de>
Subject: Re: Beginner needs help with a function
Message-Id: <7nn8vv$gnf$1@news.is-europe.net>

I R A Darth Aggie <fl_aggie@thepentagon.com> wrote:

> + I need a function to trim the first/last characters off a string if and
> + only if these characters are a user defined character.

I assume "c" is your character you want to strip.

So do a 
$string =~ s/^c+//g;
to strip the c's at the beginning, and a
$string =~ s/c+$//g;
to strip them at the end.

Maybe there is a way to do this with only one command, I would be glad to
hear about it.

-- 
Tobias Galitzien	mailto:tg@channel-one.de
Channel.One GmbH 	http://www.channel-one.de


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

Date: Wed, 28 Jul 1999 10:47:00 -0500
From: Marshall Culpepper <marshalc@americasm01.nt.com>
Subject: Re: Beginner needs help with a function
Message-Id: <379F25F4.95A8A5DC@americasm01.nt.com>

Alec Kelingos wrote:

> I need a function to trim the first/last characters off a string if and
> only if these characters are a user defined character.
>
> e.g.
>
> I'm reading records from the following file:
>
> |MICHIGAN|
> |TEXAS|
>
> Other files have other first/last characters
>
> "MICHIGAN"
> "TEXAS"
>
> But other files may just be
>
> MICHIGAN
> TEXAS
>
> Any way to write some function that takes the string and a character to
> trim.  Something like
>
> $newString = trimChr($string,"|")
>

you could just do a switch statement...
$string =~ s/\|//g;

~Marshall



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

Date: Wed, 28 Jul 1999 08:58:15 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Beginner needs help with a function
Message-Id: <MPG.1208c86f8b557b8b989d60@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <01bed909$73961020$7637ebcf@psusa6.petrosys-usa.com> on Wed, 
28 Jul 1999 14:56:04 GMT, Alec Kelingos <akelingos@petrosys-usa.com> 
says...

[with a doubly-bad Subject]

> I need a function to trim the first/last characters off a string if and
> only if these characters are a user defined character.

<SNIP of examples>
 
> Any way to write some function that takes the string and a character to
> trim.  Something like
> 
> $newString = trimChr($string,"|")
> 
> and trim the string if inclosed by the specified character, otherwise leave
> it alone?  Perhaps some niffty regular expression.

#!/usr/local/bin/perl -w
use strict;

print trim_char("|foo\nbar|", '|'), "\n";

sub trim_char {
    my ($string, $char) = (shift, quotemeta shift);
    $string =~ s/^$char(.*)$char\z/$1/s;
    $string
}
__END__

Just as a regex, that might be something like this:

    s/^(\Q$char\E)(.*)\1\z/$2/s;

Nifty enough, I guess.  <small yawn>

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 28 Jul 1999 09:17:14 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Beginner needs help with a function
Message-Id: <MPG.1208ccdfa5924278989d61@nntp.hpl.hp.com>

In article <7nn8vv$gnf$1@news.is-europe.net> on 28 Jul 1999 15:52:31 
GMT, Tobias Galitzien <tg@channel-one.de> says...
> I R A Darth Aggie <fl_aggie@thepentagon.com> wrote:
> 
> > + I need a function to trim the first/last characters off a string if and
> > + only if these characters are a user defined character.
> 
> I assume "c" is your character you want to strip.
> 
> So do a 
> $string =~ s/^c+//g;
> to strip the c's at the beginning, and a

Why the '/g'?  How many 'beginning's are there?

> $string =~ s/c+$//g;
> to strip them at the end.

Ditto for 'end's.

I think each of you misread the problem (see the quote above).  The 
strip should occur if and only if the specified character appears at 
both ends of the string.
 
> Maybe there is a way to do this with only one command, I would be glad to
> hear about it.

I posted it.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 28 Jul 1999 09:24:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Beginner needs help with a function
Message-Id: <MPG.1208ce8da88dd3ac989d62@nntp.hpl.hp.com>

In article <TrFn3.280$ZU.2504@news1.online.no> on Wed, 28 Jul 1999 
17:36:06 +0200, Trond Michelsen <mike@crusaders.no> says...
> Alec Kelingos <akelingos@petrosys-usa.com> wrote in message
> news:01bed909$73961020$7637ebcf@psusa6.petrosys-usa.com...
> > I need a function to trim the first/last characters off a string if and
> > only if these characters are a user defined character.
> > I'm reading records from the following file:
> > |MICHIGAN|
> > Other files have other first/last characters
> > "MICHIGAN"
> > But other files may just be
> > MICHIGAN
> > it alone?  Perhaps some niffty regular expression.
> 
> $line =~ s/
>  ^([|\"]?) # grab the first character of the line if it's
>            # either " or | and place it in $1

If it isn't, because of the '?', the regex matches but makes no change 
in the string.  This is needless work.  So is the backslash before the 
double-quote.  Also, the spec said *one* character, not one of a set of 
characters.

>  (.*?)     # put the rest of the line in $2

Because of the anchors, the '?' is unnecessary.

>  \1$       #except the last character if it's the same as $1

But what if the last character is actually "\n", not the same as the 
first character?  The '$' should be '\z'.

> /
>  $2        # and replace the entire line with $2
> /x;

And what if the string contains a "\n"?  This needs the '/s' modifier.

> should do the trick.

Nearly.  See my other response.

Well presented and commented, though!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 28 Jul 1999 09:32:13 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Beginner needs help with a function
Message-Id: <MPG.1208d05fb495af1c989d63@nntp.hpl.hp.com>

In article <379F25F4.95A8A5DC@americasm01.nt.com> on Wed, 28 Jul 1999 
10:47:00 -0500, Marshall Culpepper <marshalc@americasm01.nt.com> says...
> Alec Kelingos wrote:
> > I need a function to trim the first/last characters off a string if and
> > only if these characters are a user defined character.
 ...
> you could just do a switch statement...

Do you mean 'substitute'?  See perlfaq7: "How do I create a switch or 
case statement?"  Perl doesn't have any.  :-)

> $string =~ s/\|//g;

'a|rrrg|h'

If you're going to give an answer unrelated to the question, at least 
give an efficient unrelated answer.  :-)

  $string =~ tr/|//d;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 28 Jul 1999 12:53:58 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Beginner needs help with a function
Message-Id: <x7g128sok9.fsf@home.sysarch.com>

>>>>> "MC" == Marshall Culpepper <marshalc@americasm01.nt.com> writes:

  MC> you could just do a switch statement...

perl has no switch statement. perhaps you meant substitute operation?

  MC> $string =~ s/\|//g;

and that would remove any embedded | as well. he wants them to be remove
if they surround the string.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Wed, 28 Jul 1999 06:07:28 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Beginner-friendly group as cultural adaptation?
Message-Id: <0pkmn7.5dn.ln@magna.metronet.com>

Tim Morley (flyfishin@iname.com) wrote:

: I posted
: a reply last fall to a beginner question and was auto emailed
: information about the newsgroup and where to find documentation about
: Perl.  That should give any newbie a good start and a hint about what
: not to post.


   But as many newbies munge their email addresses, they do
   not get the benefit of those pointers on finding out answers
   for themselves.

   (If I don't think the answer is of general interest to the
    newsgroup, I would want to email it.

    If the address is munged, I give up and let them sleep
    in the bed they have made.

    So they might miss actual answers to their questions as well.
   )


   They want to limit their communication.

   That isn't going to be "free".

   It will cost them something.

   Like whirling around for hours trying to solve some Perl problem
   that could have been solved in 10 minutes of trying the things
   outlined in the auto-FAQ.


   They weigh the merits of munging vs. filtering and most often
   (it seems) choose munging.
   
   They have chosen (and therefore deserve) to not get clued.

   Let 'em waste their time.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 28 Jul 1999 17:24:47 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: Beginner-friendly group as cultural adaptation?
Message-Id: <ahFn3.270$ZU.2531@news1.online.no>


Martien Verbruggen <mgjv@comdyn.com.au> wrote in message
news:Kx9n3.401$1m.40786@nsw.nnrp.telstra.net...
> In article <379cae41$0$214@nntp1.ba.best.com>,
> John Callender <jbc@shell2.la.best.com> writes:
> > There has been some very interesting (to me at least) discussion here
> Maybe the auto-pollution that TC has set up here will prevent, or is
> already preventing, some of the noise. I personally think it's a good
> idea. It's easily filtered out, and makes it clear to a new person
> that there is actually documentation out there.

I think the "problem" with the FAQ and documentation is that it is so huge.
It's so comprehensive that a newbie just skips it because it's far more than
he can just skim through in a few minutes.
It also occures to me that the FAQ that is posted here regularly is a Perl
FAQ, not a c.l.p.m FAQ. It could probably be a good idea to create a small
(not more than two page-views) c.l.p.m FAQ that in addition to explaing how
to post basically explains how to use the docs, the FAQ and Dejanews. This
FAQ should of course also explain the difference between a perl question, a
CGI-question and a web-server question.

--
Trond Michelsen




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

Date: 28 Jul 1999 15:26:20 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: Beginner-friendly group as cultural adaptation?
Message-Id: <slrn7pu8d1.gn3.fl_aggie@thepentagon.com>

On 28 Jul 1999 14:02:53 -0000, Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de>, in

+ The typical newbie wants to run away with the answer to a single
+ question.  A mailing list is about as unsuitable as it gets.

Not only that, but how many would forget how to unsubscribe?

James


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

Date: Wed, 28 Jul 1999 11:06:30 -0400
From: andy barfoot <gt7202e@prism.gatech.edu>
Subject: Re: beginner-redirect and download
Message-Id: <379F1C76.48BBB344@prism.gatech.edu>

James Williamson wrote:
> .. It's intellectual elitism to think that
> everyone has your knowledge. The whole ethos of newsgroups (although feel
> free to put me right) is to share information to help those less enabled.

That sounds like, "You're an arrogant bastard if you argue with me".


> [M.V. wrote:]
> >Not at all. Although Abigail's answers are quite rough most of the
> >time, they are always on topic, and almost always correct. And she's
> 
> Come on, Abigail's answers are always rough all the time, is there really a
> need to flame everyone who makes a Usenet faux pas unintentionally?

Answer newbie posts daily as Abigail does, and the character of the
group will change.  Lurk, and it will stay the same.  It's impractical
to try to change people's personalities by insulting them.


> [M.V. wrote:]
> >not rough at all when the questions are actually decent. You do know
> >that penguins and cucumbers are considered on-topic here, right?
> 
> Yeah, to those of you in your cosy clique.



-- 
 andy barfoot


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

Date: Thu, 29 Jul 1999 00:19:02 +0800
From: Carfield Yim <c8133594@comp.polyu.edu.hk>
Subject: Re: Can perl declare constant?
Message-Id: <379F2D76.25EE2D52@comp.polyu.edu.hk>

Thank for reply

Eric Winter wrote:

> Sure.
>
> use constant CONSTANT_NAME => CONSTANT_VALUE;
>
> The Constant module is a standard module.
>
> Carfield Yim <c8133594@comp.polyu.edu.hk> wrote in message
> news:7nmdv4$gtm$1@nnrp1.deja.com...
> > Can perl declare unchangable varible like constant in C?? How??
> >
> >
> > Sent via Deja.com http://www.deja.com/
> > Share what you know. Learn what you don't.



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

Date: Wed, 28 Jul 1999 12:25:22 -0400
From: Patrick Tully <pmt@top.mitre.org>
Subject: cutom search engine?
Message-Id: <379F2EF1.DA4B3C24@top.mitre.org>

Anyone know of a free script that will parse the output of a search
engine to a user defined template.  I would like to be able to search
something like altavista or something, but have the results shown the
way I want them.  Something like
http://www.aesir.com/aesir/staff/JimSearch.html
would be quite nice.  Any info would help,
Thanks,

-Pat-
tcblue82@yahoo.com



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

Date: 28 Jul 1999 08:24:13 -0700
From: Mike Coffin <mhc@Eng.Sun.COM>
Subject: Re: Date?
Message-Id: <8p64sioyezm.fsf@Eng.Sun.COM>

"Tom Beauchamp" <acafounder@crosswinds.net> writes:

> How can I get the current date into my perl script in numbers.  Like $day,
> $month, and $year?  

The built-in function 'localtime' does exactly that.

> Is there any library that I could use that would let me
> to date addition as well?

Look in the CPAN modules under "Time".

-mike


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

Date: Wed, 28 Jul 1999 16:32:04 +0100
From: Adrian Duncan <Adrian.Duncan@trinite.co.uk>
Subject: Re: Directory Listing with Size
Message-Id: <379F2274.F239A71@trinite.co.uk>

Jason,
cheers for the reply.

I had thought of using dir /s, but this is quite slow.
I would have to parse each line looking for a line
that says Total Files and then take the size from the
next line.

Do you know of a more expedient method?
Full specs below
Cheers
Adrian.

Full Spec:
I have 3 or more web servers.
Each has a directory called webpages.
I need to get a list of each directory under
this directory and how much space it takes up,
including any sub directories.  We need to do this
to bill people for the amount of space that their
web domain takes up.



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

Date: 28 Jul 1999 12:36:40 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: ebcdic packed numbers
Message-Id: <x7so68spd3.fsf@home.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  AS> Uri Guttman  <uri@sysarch.com> wrote in comp.lang.perl.misc:
  >> on it. i did a pl/i any 2 any converter many years ago and know this
  >> stuff too well.

  AS> Oh yes... pl/i (or pl/1, nobody ever knew) inherited bcd from cobol.

officially, IBM uses PL/I. our compiler on unix was the pl1 command. i
heard they copyrighted all the values to PL/100!

  AS> ObOffTopic:  I am currently reading _The Mythical Man Month_ for the
  AS> first time (Yes... I know).  Brooks' ideas about the management of
  AS> large industrial software projects seem as sound as ever.  Well, it's
  AS> not my field at all, but it all looks very plausible.  But when he gets
  AS> down to detail, it's Computer Language Cemetery.  "Sketch your ideas in
  AS> ada, then implement them in pl/i."  Do you hear the bones rattle?  Lady
  AS> ada's ghost also rears her lovely but somewhat maggoty head.  Spooky.

i read brooks for the philosophy, not the technology. very insightful
and a must read for all software engineer wannabes. but skip his
selection of tools and languages, he is definitely stuck in the 60's.

on a similar note, check out mjd's page on the perl of the 60's:

http://www.plover.com/~mjd/perl/perl.html#perl67

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: 28 Jul 1999 12:44:20 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: ebcdic packed numbers
Message-Id: <x7pv1csp0b.fsf@home.sysarch.com>

>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:

  BL> Uri Guttman wrote:
  BL> Anyway, in order to decode BCD data, you could first convert this data
  BL> to a hex string, e.g. using sprintf(), and treat the result as a decimal
  BL> number. Basically, that should cut it.
  >> 
  >> this fails as they are decimal numbers, not hex. you have to grab each
  >> nibble (maybe with some unpack template) and do a *= 10, += digit loop
  >> on it. i did a pl/i any 2 any converter many years ago and know this
  >> stuff too well.

  BL> Are you sure it will fail? Suppose, as a simple example, that the upper
  BL> nibble is 1, the lower nibble is 2 (byte = 18). If you print it out as a
  BL> hexadecimal number, you get "12". What's would you want as the value for
  BL> the byte? 12.

you are missing the key point, it is a DECIMAL number!! you encode 1234
as 0x1234 which is not the value 0x1234. if i add 6 to that value, in
bcd you want 0x1240 while in hex you get 0x123a. carry occurs at 10,
like in the arithmetic you learned in grade school. :-)

the hex digits a-f are not used for values, but only for the sign
nibble. pack does not have a bcd format. the only way to properly
convert is to unpack the nibbles using a hex format and then do the
decimal math to get the number into a proper binary integer. so
remember, each digit in bcd can only be 0-9.

not only did i write the any2any library (a 13 x 13 matrix of conversion
subs), but the decimal package as well. think about doing all the common
math functions in bcd in software. only the ibm 360 (and descendents),
the vax and a few others did this in hardware. no risc machines could do
it directly since by definition, decimal instructions are cisc.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: 28 Jul 1999 16:58:11 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: ebcdic packed numbers
Message-Id: <7nncr3$bah$1@lublin.zrz.tu-berlin.de>

Uri Guttman  <uri@sysarch.com> wrote in comp.lang.perl.misc:
>>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
>
>  AS> Uri Guttman  <uri@sysarch.com> wrote in comp.lang.perl.misc:
>  >> on it. i did a pl/i any 2 any converter many years ago and know this
>  >> stuff too well.
>
>  AS> Oh yes... pl/i (or pl/1, nobody ever knew) inherited bcd from cobol.
>
>officially, IBM uses PL/I. our compiler on unix was the pl1 command. i
>heard they copyrighted all the values to PL/100!

Heh... talk about greedy.  Syntax error in PL/LXXIII, let's
see what PL/LXXIV does....

>  AS> [_The Mythical Man Month_]

>i read brooks for the philosophy, not the technology. very insightful
>and a must read for all software engineer wannabes. but skip his
>selection of tools and languages, he is definitely stuck in the 60's.

Sure.  It's a reprint of the original, plus a few later essays.
_No Silver Bullet_ and... I forget.

>on a similar note, check out mjd's page on the perl of the 60's:
>
>http://www.plover.com/~mjd/perl/perl.html#perl67

Bookmarked, thanks.

Anno


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

Date: Wed, 28 Jul 1999 16:14:38 GMT
From: renorum@my-deja.com
Subject: eval
Message-Id: <7nna98$38d$1@nnrp1.deja.com>

I am trying to use eval to call a certain subroutine depending on the
value of a given variable:

          eval($action());

where $action could be either "add" or "delete" or "edit".  I have
written the subroutines add(), delete() and edit().


Am I using this correctly? (because it doesn't seem to be working)  Is
this not what eval is used for?  Is there some better way to effect
this result (other than the obvious
          if ($action eq "add") { add(); }
          elsif ($action eq "delete") { delete(); }     ...etc, etc.)

Any help greatly appreciated.  Thanks.

Roger Norum


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Wed, 28 Jul 1999 15:15:03 GMT
From: ryan7879@my-deja.com
Subject: Re: Help removing special characters from a string
Message-Id: <7nn6pg$qq$1@nnrp1.deja.com>

Thank you all.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Wed, 28 Jul 1999 15:50:22 GMT
From: SaraNOS@ixPAMquick.com (Sara London)
Subject: HELP! tied DB_RECNO ->put() fails with R_IAFTER
Message-Id: <379f20b1.89406812@nnrp1.farm.idt.net>

Hi! I am trying to manipulate a  file opened via _tie_ with DB_RECNO.

My ->get($key, $value) and ->put($key, $value) commands work fine, but
->put($key, $value, R_IAFTER) and ->put($key, $value, R_IBEFORE) do
not! A status value of -1 is returned and the insertion is not
successful.

->put()'s documentation says that it will behave differently with
R_IBEFORE or R_IAFTER by modifying $key to contain the inserted line's
number. I suspect this has something to do with the problem since
->put() works without the $flag parameter.

Any ideas? Here is a code excerpt:

 ...
my(@lines,$upto_line, $the_file, $the_status);
use Fcntl;                                     
use DB_File;

$the_file = tie(@lines, "DB_File", $the_path, O_RDRW | O_CREAT, 0640,
$DB_RECNO);
 ...
my $target_line = 9;
my $new_content = "This line to insert.";
$the_status = $the_file->put($target_line,$new_content,R_IAFTER);
print "response: $the_status, returned line: $target_line.";
 ...
untie(@lines);

************
When this code is executed, $the_status == -1 and $target_line is
still 9 and the file remains unchanged. (When I remove the R_IAFTER
the code executes and replaces the line.)

I will be grateful for any insight that you might have.

Thank you, 
Sara
SaraNOS@ixPAMquick.com


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

Date: 28 Jul 1999 16:59:25 GMT
From: campbell-lange@easynet.co.uk (Rory C-L)
Subject: help: push array refs into hash, sort by refs in hash
Message-Id: <campbell-lange-2807991759030001@campbell-lange.easynet.co.uk>

I have a sets of records some of which belong to the same "issue number"

i.e.
Issue     Date     Number          Revision
636/1999     23/2/99  A/LB/10/00/229  D                        
780/1999     21/4/99  A/LB/10/00/249  C 
874/1999      1/6/99  A/LB/10/01/003  R                          
780/1999     14/1/99  A/LB/10/02/028  C                                
487/1998     4/12/98  A/LB/10/04/021  J 

I'd like to sort the records by number, collected by Issue.
I split the records into issue and @rest.
Then I want to $hash{$issue} = [@rest], unless $hash{$issue} already exists,
in which case I'm using $hash{$issue} .= [@rest]. However THEN I have two
refs appended to each other, rather than an array of refs.
Should I initialise $hash{$issue} = []; then push subsequent array refs to it?
I'm a bit confused.

A related sort question:

I have a hash structured like this:

   key   value (ref to anonymous array) 
    |      |
    x    (anonymous) array with refs to 1 .. n anonymous arrays
           |
         array array array
           |
         first element
         
         
I'd like to sort a hash by the 1st element of the 1st array of the array
referenced by value.
The structure of the element is a set of numbers followed by a '/' then
some letters. Its only the numbers I'm interested in.

Thanks for any help
Rory

-- 
Rory Campbell-Lange
The Campbell-Lange Workshop


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

Date: 28 Jul 1999 15:13:05 GMT
From: Steffen Beyer <sb@sdm.de>
Subject: Re: how to print an hexadecimal with more than 32 bits
Message-Id: <7nn6m1$i50$1@solti3.sdm.de>

In article <379EC8E2.E7E7EA53@hl.siemens.de>, Michel Combes <michel.combes@hl.siemens.de> wrote:

> Hello perl-gurus,

> I do have an interresting problem
> but I can't figure out how to solve it
> Any help is more than welcomed

> Problem :
> ---------
> I have an integer on more than 32b (2**33-2 for instance)
> Question : how to print it in hex format ?
> (note I'm running perl on a 32b-architecture machine!)

> Trial of solution :
> -------------------
> for $e (30..34) {
>   $l = 2**$e - 2;

>   printf("a big number             = %s\n",$l);
>   # saturated to 0xFFFF.FFFF
>   printf("this doesn't work        : %016x\n",$l);
>   $lsb = $l & (2**32-1);
>   $msb = $l >> 32;

>   printf("this doesn't work either : %08x.%08x\n",$msb,$lsb);

> }


> Thanks for your proposal.

> Michel
> --
> " Do not follow where the path may lead. Go instead
>     where there is no path and leave a trail. "

In short, "use Bit::Vector;".
See my sig below where to download this module from.

-------------------- cut here -------------------- cut here --------------------

How do I convert from hexadecimal to decimal:

1) $dec = 0xDEADBEEF;
2) $dec = hex("DEADBEEF");
3) $dec = unpack("N", pack("H8", substr("0" x 8 . "DEADBEEF", -8)));
4) use Bit::Vector;
   $vec = Bit::Vector->new_Hex(32, "DEADBEEF");
   $dec = $vec->to_Dec();

How do I convert from decimal to hexadecimal:

1) $hex = sprintf("%X", 3735928559);
2) $hex = unpack("H*", pack("N", 3735928559));
3) use Bit::Vector;
   $vec = Bit::Vector->new_Dec(32, -559038737);
   $hex = $vec->to_Hex();

How do I convert from octal to decimal:

1) $dec = 033653337357; # note the leading '0'
2) $dec = oct("33653337357");
3) use Bit::Vector;
   $vec = Bit::Vector->new(32);
   $vec->Chunk_List_Store(3, split(//, reverse "33653337357"));
   $dec = $vec->to_Dec();

How do I convert from decimal to octal:

1) $oct = sprintf("%o", 3735928559);
2) use Bit::Vector;
   $vec = Bit::Vector->new_Dec(32, -559038737);
   $oct = reverse join('', $vec->Chunk_List_Read(3));

How do I convert from binary to decimal:

1) $dec = unpack("N", pack("B32",
      substr("0" x 32 . "11011110101011011011111011101111", -32)));
2) use Bit::Vector;
   $vec = Bit::Vector->new_Bin(32, "11011110101011011011111011101111");
   $dec = $vec->to_Dec();

How do I convert from decimal to binary:

1) $bin = unpack("B*", pack("N", 3735928559));
2) use Bit::Vector;
   $vec = Bit::Vector->new_Dec(32, -559038737);
   $bin = $vec->to_Bin();

The remaining transformations (e.g. hex -> oct, bin -> hex, etc.)
are left as an exercise to the inclined reader. :-)

(Note: The advantage of the Bit::Vector module is that it works with
numbers of ANY size.)

-------------------- cut here -------------------- cut here --------------------

Hope this helps.

Best regards,
-- 
    Steffen Beyer <sb@engelschall.com>
    http://www.engelschall.com/u/sb/whoami/
    http://www.engelschall.com/u/sb/download/
    http://www.perl.com/CPAN/authors/id/STBEY/


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

Date: 28 Jul 1999 16:09:25 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to print an hexadecimal with more than 32 bits
Message-Id: <7nn9vl$b97$1@lublin.zrz.tu-berlin.de>

Michel Combes  <michel.combes@hl.siemens.de> wrote in comp.lang.perl.misc:
>Hello perl-gurus,
>
>I do have an interresting problem
>but I can't figure out how to solve it
>Any help is more than welcomed
>
>Problem :
>---------
>I have an integer on more than 32b (2**33-2 for instance)
>Question : how to print it in hex format ?
>(note I'm running perl on a 32b-architecture machine!)
>
>Trial of solution :
>-------------------
>for $e (30..34) {
>  $l = 2**$e - 2;
>
>  printf("a big number             = %s\n",$l);
>  # saturated to 0xFFFF.FFFF
>  printf("this doesn't work        : %016x\n",$l);
>  $lsb = $l & (2**32-1);
>  $msb = $l >> 32;
>
>  printf("this doesn't work either : %08x.%08x\n",$msb,$lsb);
>
>}

Well, you can do the conversion piecemeal:

sub tohex {
  my $n = shift;
  my ( $m, $hex);
  while ( $n ) {
    $m = $n;
    $n = int $n/16;
    $hex .= sprintf '%x', $m - 16*$n;
  }
  reverse $hex;
}

Anno


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V9 Issue 283
*************************************


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