[18745] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 913 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 16 14:06:27 2001

Date: Wed, 16 May 2001 11:05:15 -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: <990036314-v10-i913@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 16 May 2001     Volume: 10 Number: 913

Today's topics:
        $myexp =~ s/\%/[aeiou]/; ???? <gerhard.schwarz@fpg.de>
    Re: $myexp =~ s/\%/[aeiou]/; ???? <peb@bms.umist.ac.uk>
    Re: $myexp =~ s/\%/[aeiou]/; ???? (Greg Bacon)
    Re: $myexp =~ s/\%/[aeiou]/; ???? nobull@mail.com
        Any UK Perl Gurus out there? <mark.hughes@internetfahrenheit.com>
    Re: Any UK Perl Gurus out there? nobull@mail.com
    Re: Bits and bytes (James Weisberg)
        cron stdout stderr and email <john@princenaseem.com>
    Re: cron stdout stderr and email nobull@mail.com
        DBD and oracle 8.1.7 <duncanl@bisnet.net>
    Re: DBD and oracle 8.1.7 <brian@stevens.com>
        Enforcing arguments <pgarrett@cdc.net>
    Re: Enforcing arguments nobull@mail.com
    Re: HELP: modifying a referenced array from a library s (Bruno Boettcher)
        Hex values <gibbonsw@americasm01.nt.com>
    Re: Hex values (Tad McClellan)
    Re: Hex values <sb@mcasia.imperia.net>
        How to invoke another script in a CGI script? <dontuspamme@nospammers.com>
        importing var's help wanted <gpitman@nbdot.net>
        Initialisation of object <michael@stroeck.com>
        Interactive program with command line history/vi mode-- <makesh@agere.com>
    Re: Interactive program with command line history/vi mo (Steven M. O'Neill)
    Re: Interactive program with command line history/vi mo nobull@mail.com
    Re: Measuring the time (Craig Berry)
    Re: Measuring the time (Eric Bohlman)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 16 May 2001 17:08:11 +0200
From: Gerhard Schwarz <gerhard.schwarz@fpg.de>
Subject: $myexp =~ s/\%/[aeiou]/; ????
Message-Id: <3B0297DB.DB90663B@fpg.de>

Hi, 

While trying to learn some Perl, I've found this expression in some
example code:

$myexp =~ s/\%/[aeiou]/;

I haven't found the meaning of that "%" (even on perldoc.com). 
Maybe someone could explain it to me?


TIA,
Gerhard


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

Date: Wed, 16 May 2001 16:24:42 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: $myexp =~ s/\%/[aeiou]/; ????
Message-Id: <3B029BBA.57E37C1B@bms.umist.ac.uk>

Gerhard Schwarz wrote:
> 
> Hi,
> 
> While trying to learn some Perl, I've found this expression in some
> example code:
> 
> $myexp =~ s/\%/[aeiou]/;
> 
> I haven't found the meaning of that "%" (even on perldoc.com).
> Maybe someone could explain it to me?

Hi Gerhard,

I would scrap the example code and go elsewhere.  There are plenty of
good books and online tutorials to learn from.

But to answer you'r question if $myexp is a string containing something
like 

"hi there you just scored 100%"

then doing $myexp =~ s/%/[aeiou]/;

would change it into "hi there you just scored 100[aeiou]"

so you can see, this doesn't do what was probably intended.

also note that you don't need the '\' infront of the % sign.

Just one question.  Are you sure you've posted the correct code?

Paul


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

Date: Wed, 16 May 2001 15:54:47 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: $myexp =~ s/\%/[aeiou]/; ????
Message-Id: <tg58m75gjbpm98@corp.supernews.com>

In article <3B029BBA.57E37C1B@bms.umist.ac.uk>,
    Paul Boardman  <peb@bms.umist.ac.uk> wrote:

: Gerhard Schwarz wrote:
:
: > While trying to learn some Perl, I've found this expression in some
: > example code:
: > 
: > $myexp =~ s/\%/[aeiou]/;
: 
: I would scrap the example code and go elsewhere.  There are plenty of
: good books and online tutorials to learn from.
: 
: But to answer you'r question if $myexp is a string containing something
: like 
: 
: "hi there you just scored 100%"
: 
: then doing $myexp =~ s/%/[aeiou]/;
: 
: would change it into "hi there you just scored 100[aeiou]"
: 
: so you can see, this doesn't do what was probably intended.

I think you're jumping to a hasty conclusion.  SQL uses % as a wildcard,
e.g., select * from table where name like "%perl%".  The scalar to be
mutated is called $myexp, and that suggests that the code is building
a regular expression.

Here's a more general guarantee from the perlre manpage:

    Unlike some other regular expression languages, there are no
    backslashed symbols that aren't alphanumeric.  So anything that
    looks like \\, \(, \), \<, \>, \{, or \} is always interpreted as a
    literal character, not a metacharacter.  This was once used in a
    common idiom to disable or quote the special meanings of regular
    expression metacharacters in a string that you want to use for a
    pattern. Simply quote all non-alphanumeric characters:

        $pattern =~ s/(\W)/\\$1/g;

Greg
-- 
Fenster: I had a guy's fingers in my asshole tonight.
Hockney: Is it Friday already?


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

Date: 16 May 2001 17:50:40 +0100
From: nobull@mail.com
Subject: Re: $myexp =~ s/\%/[aeiou]/; ????
Message-Id: <u9heylw84f.fsf@wcl-l.bham.ac.uk>

Gerhard Schwarz <gerhard.schwarz@fpg.de> writes:

> While trying to learn some Perl, I've found this expression in some
> example code:
> 
> $myexp =~ s/\%/[aeiou]/;
> 
> I haven't found the meaning of that "%" (even on perldoc.com). 
> Maybe someone could explain it to me?

It means "%"

In a Perl regular expression or interpolative string context[1] _any_
punctuation character preceded by a backslash always just means
itself.

As it happens the % character is not special and so would also mean
itself even without the backslash.  However, the author did not want
to waste effort remembering the fact that % was not special.

IIRC Tad believes that the redundant backslash in the above code makes
it less readable.  I believe it has no effect on readability or makes
it more readable.  Tad and I are both really too experienced to judge
this.  As a newcommer you are actually better qualified (sic).
So... do you think it aids or impares readability?

Note: PSI::ESP tells me that the above line of code is taken from a
script that is builing a string in $myexp that will later be used as a
regular expression.  This explains why you are seeing stuff that looks
like it is a regex on the RHS of s///.

[1] The LHS of s/// is both of these.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 16 May 2001 15:44:10 +0100
From: "Mark Hughes" <mark.hughes@internetfahrenheit.com>
Subject: Any UK Perl Gurus out there?
Message-Id: <2owM6.3771$Yh2.83610@NewsReader>

Hi

We have a Perl application that is functionally sound and are looking for a
Perl guru in the UK who really understands and has experience of scalabilty
and performance issues using this language.

If you are interested please drop me a line so that we can chat...!

Thanks
Mark Hughes




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

Date: 16 May 2001 17:55:32 +0100
From: nobull@mail.com
Subject: Re: Any UK Perl Gurus out there?
Message-Id: <u9d799w7wb.fsf@wcl-l.bham.ac.uk>

"Mark Hughes" <mark.hughes@internetfahrenheit.com> writes:

> We have a Perl application that is functionally sound and are looking for a
> Perl guru in the UK who really understands and has experience of scalabilty
> and performance issues using this language.
> 
> If you are interested please drop me a line so that we can chat...!

If all you want is a chat why is location significant?

If you are posting a job ad then please go away.  Posting job ads in
Usenet groups is highly frowned upon.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 16 May 2001 16:02:58 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Re: Bits and bytes
Message-Id: <SwxM6.5377$DW1.238227@iad-read.news.verio.net>

Dave Bailey <dave@sydney.daveb.net> wrote:
>On Tue, 15 May 2001 23:11:53 GMT, James Weisberg <chadbour@wwa.com> wrote:
>>Below is a simple program which creates a 32bit vector for long integer
>>storage:
>>#! /usr/local/bin/perl -w
>>
>>my $vector= 0; vec($vector, 0, 32) = $ARGV[0];
>>my $value = decode($vector);
>>
>>print "integer value is: $value\n";
>>
>>sub decode {
>>   my @s = reverse split //, unpack("B32", shift); # portable? fast?
>>      $" = ""; print "[$#s] bitstr: (@s)\n";
>>
>>      my($i,  $j,  $v, $p);
>>   for(  $i = $j = $v = 0, $p = 1; $j < $#s; $j++, $p <<= 1 ) {
>>         $v|= $p if($s[$i++]);                     # fiddle 2^p
>>   }
>>
>>   return $v;
>>}
>
>You don't need this function.  Replace it with vec($vector,0,32) in
>your example.

   Right, but I need a decoding function for the bitstring I am
constructing. The above was just an example of how that might work
once I know how many bits I need to sift thru to calculate a value.

>>Also, a vector will be dozens of bytes wide, and will contain instructions
>>on how subsequent values are coded. For instance, somewhere in the vector
>>I might have an instruction to read the next 8 bits and turn them into
>>an integer value. Another instruction might require reading the next
>>16 bits for a value.
>
>This sort of thing always works much easier if you settle on a fixed
>element width and accept the (probably slight) size penalty.  You can
>mix and match if you want, but you have to interpret the bitstring in
>terms of the *smallest* element size you intend to store in it.

   This much I have done. The idea is to tailor the bitstring to
reflect the nature of the data being stored. For instance, -1 is the
only negative number I wish to store and it and 0 are the two most
common values. Here is what I have come up with to encode a bitstring:


I = II =  2 bits for coding instruction
0 = 00 =  0 Value
1 = 10 = -1 Value
2 = 01 =    Nonzero packet flag + 00 + 4 bits for flag value. Fill 8S -1s.
3 = 11 = HH  = 2 bits for value header
     0 = 00# = Read next 04 bits and add 1:         # 1 byte
           #0000| =   0  +1 =  1
           #1000| = 2^0  +1 =  2
           #0100| = 2^1  +1 =  3
           #0010| = 2^2  +1 =  5
           #0001| = 2^3  +1 =  9
           #1111| = 2^4-1+1 = 16
     1 = 10# = Read next 08 bits and add 17:        # 1 btyes, 1 nybble
           #0000|0000# =   0  +17 =   17
           #1000|0000# = 2^0  +17 =   18
           #0000|1000# = 2^4  +17 =   33
           #1111|1111# = 2^8-1+17 =  272
     2 = 01# = Read next 16 bits and add 273:       # 2 bytes, 1 nybble
           #0000|0000#0000|0000 =   0   +273 =   273
           #1000|0000#0000|0000 = 2^0   +273 =   274
           #0000|1000#0000|0000 = 2^4   +273 =   289
           #0000|0000#1000|0000 = 2^8   +273 =   529
           #0000|0000#0000|1000 = 2^12  +273 =  4369
           #1111|1111#1111|1111 = 2^16-1+273 = 65808
     3 = 11# = Read next 24 bits and add 65809:     # 3 bytes, 1 nybble
           #0000|0000#0000|0000#0000|0000# =   0   +65809 =    65809
           #1000|0000#0000|0000#0000|0000# = 2^0   +65809 =    65810
           #0000|1000#0000|0000#0000|0000# = 2^4   +65809 =    66825
           #0000|0000#1000|0000#0000|0000# = 2^8   +65809 =    66065
           #0000|0000#0000|1000#0000|0000# = 2^12  +65809 =    69905
           #0000|0000#0000|0000#1000|0000# = 2^16  +65809 =   131345
           #0000|0000#0000|0000#0000|1000# = 2^20  +65809 =  1114385
           #1111|1111#1111|1111#1111|1111# = 2^24-1+65809 = 16843024


   Let me try to explain that briefly. The first two bits are what I
call an instruction (II). If II = 00, a 0 is encoded. If II = 10, a -1
is encoded. That right there saves a *lot* of space because I can now
store four 0 or -1 values in a single byte (10001000) = (-1,0,-1,0).
Now II = 01 is a special instruction which says the entire record is
bogus. I won't bore you with details here, except to say that I don't
need to encode any values in this case because they would all be -1.
And then finally II = 11 means that a real value is encoded; and they
can be encoded in 4 different ways.
   A 2 bit header (HH) is used to determine how many more bits encode
the value. HH = 00 means the value is encoded in the next 4 bits. This
brings me to the first byte, which I denote with a '|'. HH = 10 means
to read the next 8 bits, which brings me 1 byte and 1 nybble down the
bitstring, which I denote with a '#'. And so on.
   This technique allows me to encode values from [-1,16843024] which
should cover anything I need. If it doesn't, I can modify the 11 HH to
read out to 28-32 bits.
   Since the above doesn't gaurentee the record ends on a byte boundary,
there may be some trailing zeros (up to 6), but my decoding function can
handle that because it knows how many values it should have interpolated
from this bitstring and stops.


   So you see, I may have an arbitrarily long bitstring, encoding some
number of elements, and now I need to walk down that string and figure
out the values. I've already coded both functions to fetch and store
the values, but I was wondering if there was a faster way to turn a
bitstring into a value. And that's where my program above comes into
play. Really want I want to know is if I have to use split() or substr()
to walk down the bitstring to see which 0's and 1's are set. Perl is
not my first language so maybe there is a better way. Still, if you
have a better suggestion on how to go about the whole procedure, I am
all ears as well.

>Suppose
>that size is 8 bits.  Then 16 and 32 bit values may be stored at offsets
>in the string which are not multiples of 16 and 32 bits, respectively,
>because of the existence of 8-bit elements.  Thus, you will need to
>write some code to handle storage and retrieval of 16 and 32 bit values
>at offsets which are an arbitrary multiple of 8 bits.  Depending on the
>needs of your program, this may exact a performance penalty.  In any
>case, try something like below:
>
>#!/usr/bin/perl -w
>
>my $vector = '';
>
>vec_store(\$vector,0,8,123);
>vec_store(\$vector,8,16,12345);
>vec_store(\$vector,24,32,1234567);
>
>print vec_fetch($vector,0,8), "\n";
>print vec_fetch($vector,8,16), "\n";
>print vec_fetch($vector,24,32), "\n";
>
># $v is a *reference* to the bit vector.
># $o is the offset in *bits* (must be a multiple of 8).
># $b is the width in *bits* of the value being stored.
># $x is the number being stored.
>
>sub vec_store {
>  my ($v,$o,$b,$x) = @_;
>
>  map{vec($$v,($o>>3)+$_,8)=($x>>($_<<3))}(0..($b>>3)-1);
>}
>
># $v is the bit vector.
># $o is the offset in *bits* (must be a multiple of 8).
># $b is the width in *bits* of the value being fetched.
>
>sub vec_fetch {
>  my ($v,$o,$b) = @_;
>
>  my $x;map{$x|=(vec($v,($o>>3)+$_,8))<<($_<<3)}(0..($b>>3)-1);$x;
>}

   The problem with the fetch function, in terms of how I need to use it,
is that the caller must know a priori how many bits need fetching (for $b).
My scheme above encodes 2, 4, 8, 16, and 24. The storage function is called
to store data to disk; and then the fetch function is used by a completely
independent program to retreive the data. So the size of the data element
must be encoded in the bitstring itself. What I have achieved above is
some pretty good compression, at the expense of some processing. Now I
just want to see if I can process a bit faster. If you are interested, I
can post both pieces of code and explain how they work.



-- 
World's Greatest Living Poster


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

Date: Wed, 16 May 2001 15:32:26 +0100
From: "JohnShep" <john@princenaseem.com>
Subject: cron stdout stderr and email
Message-Id: <EcwM6.3708$Yh2.83442@NewsReader>

My ISP has provided me with a cron directory but I don't receive any output.
I would like to redirect stdout and stderr and email the output to myself
afterwards. Any ideas how to go about this ?

John




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

Date: 16 May 2001 18:05:37 +0100
From: nobull@mail.com
Subject: Re: cron stdout stderr and email
Message-Id: <u9ae4dw7fi.fsf@wcl-l.bham.ac.uk>

"JohnShep" <john@princenaseem.com> writes:

> My ISP has provided me with a cron directory but I don't receive any output.
> I would like to redirect stdout and stderr and email the output to myself
> afterwards. Any ideas how to go about this ?

Examples of redirecting the standard file drescriptors to a file can
be found in "perldoc -f open".

Examples of sending mail from Perl can be found in the FAQ "How do I
send mail?".  However if you just want to mail a file then you should
possibly simply use system() to execute the appropriate host operating
system shell command.

You could even combine information from the above two sources and
redirect STDERR/STDOUT directly to a sendmail process.

Note: if you want your redirection to act on STDERR outpurt from the
compliation phase you'll need to put the redirection in a BEGIN{} block.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 16 May 2001 08:08:15 -0500
From: "Lance Duncan" <duncanl@bisnet.net>
Subject: DBD and oracle 8.1.7
Message-Id: <dZuM6.4$8q.274@client>

I am trying to complile gnu perl 5.005.03 with DBD-Oracle-1.06 and Oracle
8.1.7 on HP-UX 11.  The compile fails, even when I link statically.  Does
anyone know what modifications I need to make to the DBD files in order to
get the compile to work?




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

Date: Wed, 16 May 2001 08:38:47 -0600
From: Brian Stevens <brian@stevens.com>
Subject: Re: DBD and oracle 8.1.7
Message-Id: <3B0290F7.603F2C79@stevens.com>

Lance Duncan wrote:
> 
> I am trying to complile gnu perl 5.005.03 with DBD-Oracle-1.06 and Oracle
> 8.1.7 on HP-UX 11.  The compile fails, even when I link statically.  Does
> anyone know what modifications I need to make to the DBD files in order to
> get the compile to work?

Can you inlude the error messages?  If it's failing during the "make
install", that's usually easy to fix.  If it's failing during the
build, there are tons of things that could be wrong.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Brian Stevens                 STEVENS.COM, Inc.
  brian@stevens.com                 (303)638-1366
        Systems Administration Consultant
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: Wed, 16 May 2001 11:53:40 -0400
From: Philip Garrett <pgarrett@cdc.net>
Subject: Enforcing arguments
Message-Id: <ABBF97ECCFAAB43F.3653A529C8077730.6A8C6323F08E4CBA@lp.airnews.net>


I'm trying to enforce that at least one argument be passed to a
subroutine, and I'd like to catch violations at compile time.  Can it be
done with subroutine prototypes without forcing scalar context?

I've tried using just (@), but that pretty much only removes the need for
parentheses around arguments -- it doesn't enforce that something be
passed.  I've also tried ($;@), but that forces the list into scalar
context.  I would prefer not to have to pass a "real" array if possible. 

Thanks for your help,
Philip Garrett




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

Date: 16 May 2001 17:49:44 +0100
From: nobull@mail.com
Subject: Re: Enforcing arguments
Message-Id: <u9itj1w85z.fsf@wcl-l.bham.ac.uk>

Philip Garrett <pgarrett@cdc.net> writes:

> I'm trying to enforce that at least one argument be passed to a
> subroutine, and I'd like to catch violations at compile time.  Can it be
> done with subroutine prototypes without forcing scalar context?

No.

Think about what you are asking.  You want a function that takes a
single list argument and you want to deftect at compile time if that
list is empty.  In general you cannot know at compile time if a
list-context expression will be empty at run-time.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 16 May 2001 14:38:13 GMT
From: bboett@erm6.u-strasbg.fr (Bruno Boettcher)
Subject: Re: HELP: modifying a referenced array from a library subroutine...
Message-Id: <9du3cl$ht$1@news.u-strasbg.fr>

In article <9dtrte$aek$1@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>Then please show your code.  The method I suggested works fine for me.
yes sorry my error....
found that i assigned to the ref the array, instead of just copying the
reference.... hence the copy later on....

works now...


-- 
bboett at erm1 dot u-strasbg dot fr
http://erm6.u-strasbg.fr/~bboett
==============================================================
Unsolicited commercial email is NOT welcome at this email address


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

Date: Wed, 16 May 2001 09:53:18 -0400
From: "Gibbons, William [CAR:VC21:EXCH]" <gibbonsw@americasm01.nt.com>
Subject: Hex values
Message-Id: <3B02864E.48626F15@americasm01.nt.com>

Hi,

This is probably a very trivial question but I was just wondering if
anyone knows how I go about manipulating hex values in perl.  I know how
to convert a hex value to an int but how do I, for example, add two hex
values without first converting each to an int.  Also, how do I convert
dec to hex?  Any references on this would be great.

Thanks in advance,

Will




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

Date: Wed, 16 May 2001 10:30:33 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Hex values
Message-Id: <slrn9g53o9.nb0.tadmc@tadmc26.august.net>

Gibbons, William [CAR:VC21:EXCH] <gibbonsw@americasm01.nt.com> wrote:
>
>This is probably a very trivial question but I was just wondering if
>anyone knows how I go about manipulating hex values in perl.  


This can be a very confusing concept to suss out, so precise 
terminology is pretty much required if we're to avoid going
in circles. I see two misused terms above that ought to be
cleared up:

1) surely you meant "in Perl" rather than "in perl"?

   (see the Perl FAQ, part 1:
      What's the difference between "perl" and "Perl"?
   )

   If you're interested in the internals, then the p5p mailing list
   would be a much better place to ask than here on Usenet.


2) there *are no* "hex values" in Perl.

   Perl has "numbers" and "numeric operators" for doing stuff to numbers.

   Perl understands many _representations_ of the *same* "number", eg:

      0b1010 == 012 == 0x0A == 10 == 10.0 == 5 + 5 
      #1        #2     #3      #4    #5      #6

   Those are a few of the _representations_ of the abstract concept
   often called "ten". (though using "==" with floating point
   numbers, as in #5, is dangerous)


>I know how
>to convert a hex value to an int 


A "hex value" (#3) *is* an "int" (a number).

I figure your use of "hex value" is not what I outlined above.

I think your "hex value" is a "hex string" (not a number), and
that you are saying you know how to

   $num = hex '0x0A';  # convert a string in hex representation into a number

Is that what you mean?


>but how do I, for example, add two hex
>values without first converting each to an int.  


"hex values", being numbers, can make use of Perl's numeric operators:

   0x5 + 0x5 == 10;  # aka: 0x0A


"hex strings" is what you seem to be asking about though.

Addition is not defined for strings, only for numbers. If you want
to treat the strings as numbers, then yes, you must convert the
strings to numbers before applying the addition operation.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 16 May 2001 18:55:28 +0200
From: Steffen Beyer <sb@mcasia.imperia.net>
Subject: Re: Hex values
Message-Id: <0ebud9.4p.ln@imperia.net>

Tad McClellan <tadmc@augustmail.com> wrote:

> [ Lots of nit-picking deleted :-) ]

> Addition is not defined for strings, only for numbers. If you want
> to treat the strings as numbers, then yes, you must convert the
> strings to numbers before applying the addition operation.

< still more intense nit-picking ON ;-) >

In fact you are wrong.

Pure numbers do NOT exist in computers, they have ALWAYS SOME kind of
representation, and the calculations (like addition) are ALWAYS
performed based on some representation.

Perl happens to be written in C, which uses two's complement binary
representation (and IEEE floating point representation, which is
just another form of two's complement binary representation) for
its numbers, internally.

This actually doesn't need to be so, mainframes used to perform
their calculations in "binary coded decimal" (BCD) strings, and
if Perl ran on such a mainframe, it might do so, too!

(BTW the Math::BigInt module used to do just that!)

So in fact the first poster's question was totally sensible,
and anyway there was no need for "patronizing" him (sorry, I
don't know a better term right now) about what he'd done wrong in
such a great length, when it was obvious what he meant, how to
transform numbers between different representations.

< still more intense nit-picking OFF >

But to answer the original question:

> how do I, for example, add two hex
> values without first converting each to an int.
> Also, how do I convert dec to hex?

Well, you just can't add two hex values without first converting
them into an int (read: the internal two's complement binary
representation), because that's what the parser already does
when he sees something like 0xFB9C in your program text.

Even the characters \xFB \x9C would be immediately converted
into the internal representation.

But since this is so, you don't need to worry about it either! :-)
It will not take any longer to perform the addition!

To convert from dec to hex, use sprintf("%04X", $int) -
see "perldoc perlfunc" for more info about "sprintf()".

Hope this helps. :-)

Best regards,
-- 
    Steffen Beyer <sb@engelschall.com>
    http://www.engelschall.com/u/sb/whoami/ (Who am I)
    http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
    http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)


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

Date: Wed, 16 May 2001 10:55:24 -0700
From: "kalasend at YAHOO dot COM" <dontuspamme@nospammers.com>
Subject: How to invoke another script in a CGI script?
Message-Id: <W7zM6.36$DB3.6213@chrome-fe.eng.netapp.com>

hi,

    I found that in a CGI script, statements like these won't work:
            system("X Y Z") && die "$!\n";
    or,
            $all_files = `find .`;

    Problem could be that the CGI script is not associated with any shell?
(I made this assumption because the same CGI script works well when I did
"perl -w XXX.cgi" on the command line)

    Then how can I invoke other scripts when running as CGI?

thanks,
ben





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

Date: Wed, 16 May 2001 13:56:31 -0400
From: Gary Pitman <gpitman@nbdot.net>
Subject: importing var's help wanted
Message-Id: <3B02BF51.B8D275FF@nbdot.net>

I have several .cgi pages that pass info from one form to the next,
using some of the info on each page.
I am trying to make a shortcut to assigning each imported name/value
pair on each page. I can pass on the param hash with:

foreach $field (sort ($query->param))
{
      foreach $value ($query->param($field))
        {
          print $query->hidden("$field"," $value");
        }
}

but i would like to also make these variables usable in this form, i
tried several different syntax variations of:

foreach $field (sort ($query->param))
{
      foreach $value ($query->param($field))
        {
          ("\$"."$field"=$value);
        }   
}

I keep getting a bunch of "Can't modify concatenation" errors.

Any pointers would be appreciated,

Thank you.


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

Date: Wed, 16 May 2001 20:00:24 +0200
From: "Michael Ströck" <michael@stroeck.com>
Subject: Initialisation of object
Message-Id: <3b02c00d$1@e-post.inode.at>

Hi all !

At the moment, I do the following:

#########################################
my $msg = new ForumMessage;

$msg->{thread_id} = $cgi->param('thread_id');
$msg->{user_id} = $cgi->param('user_id');
$msg->{subject} = $cgi->param('subject');
$msg->{body} = $cgi->param('body');
#########################################

However, I'd like to do something like:

#########################################
my $msg = new ForumMessage;

$msg->{
                thread_id => $cgi->param('thread_id'),
                user_id => $cgi->param('user_id'),
            }
#########################################

But obviously that doesn't work. Can anybody tell
me how to do it ? ( I know I can do the following :
$msg = ForumMessage::new(thread_id => $cgi->param('thread_id'),....)
but I'd like to asign the values later :-)


Michael Ströck






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

Date: Wed, 16 May 2001 13:01:57 -0400
From: Makesh Kothandaraman <makesh@agere.com>
Subject: Interactive program with command line history/vi mode--help needed
Message-Id: <3B02B285.4735A896@agere.com>

Hi,

I am a novice to perl. I apologize if this question sounds too
elementary.

I am working on a interactive perl program that takes input from
<STDIN>. It processes the command by invoking a set of perl
subroutines. The program looks somewhat like:

while ($line ne "end")
        {
	print "Program>";
        $line=<STDIN>;
        chomp $line;
        .....
        }

What I would like to do is give the program user the ability
to access previous commands (command line history) and editing
ability using the vi editor. I would like this to be similar
to what my ksh does (ESC-k for previous command, ESC-J for
next command and so on). Could somebody suggest a way to do
this in my program?

Thanks a lot in advance.

--Makesh


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

Date: 16 May 2001 17:11:33 GMT
From: steveo@panix.com (Steven M. O'Neill)
Subject: Re: Interactive program with command line history/vi mode--help needed
Message-Id: <9ducc5$1gv$1@news.panix.com>

Makesh Kothandaraman  <makesh@agere.com> wrote:
>I am a novice to perl. I apologize if this question sounds too
>elementary.

Sounds more like high school to me.
-- 
Steven O'Neill                                      steveo@panix.com
                                                   www.cars-suck.org


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

Date: 16 May 2001 18:13:49 +0100
From: nobull@mail.com
Subject: Re: Interactive program with command line history/vi mode--help needed
Message-Id: <u94rulw71u.fsf@wcl-l.bham.ac.uk>

Makesh Kothandaraman <makesh@agere.com> writes:

> I am a novice to perl. I apologize if this question sounds too
> elementary.
> 
> I am working on a interactive perl program that takes input from
> <STDIN>. It processes the command by invoking a set of perl
> subroutines. The program looks somewhat like:
> 
> while ($line ne "end")
>         {
> 	print "Program>";
>         $line=<STDIN>;
>         chomp $line;
>         .....
>         }
> 
> What I would like to do is give the program user the ability
> to access previous commands (command line history) and editing
> ability using the vi editor. I would like this to be similar
> to what my ksh does (ESC-k for previous command, ESC-J for
> next command and so on). Could somebody suggest a way to do
> this in my program?

Use the Term::ReadLine module.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 16 May 2001 17:20:28 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Measuring the time
Message-Id: <tg5dmsti8s4tfd@corp.supernews.com>

Godzilla! (godzilla@stomp.stomp.tokyo) wrote:
: Would you like those of us who voice an opinion
: different than yours, to stitch a Star Of David
: upon our clothing in a clearly visible place?

I need a ruling from the refs...does this constitute a Hitler/Nazi
reference?  If so, I invoke the Usenet conversational protocol clause
stating that, once Hitler or Nazis are invoked in a (non-history-related)
discussion, that discussion can be reasonably assumed to have permanently
left the realm of rational debate. 

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: 16 May 2001 17:53:18 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Measuring the time
Message-Id: <9dueqe$5in$3@bob.news.rcn.net>

Craig Berry <cberry@cinenet.net> wrote:
> Godzilla! (godzilla@stomp.stomp.tokyo) wrote:
> : Would you like those of us who voice an opinion
> : different than yours, to stitch a Star Of David
> : upon our clothing in a clearly visible place?

> I need a ruling from the refs...does this constitute a Hitler/Nazi
> reference?  If so, I invoke the Usenet conversational protocol clause
> stating that, once Hitler or Nazis are invoked in a (non-history-related)
> discussion, that discussion can be reasonably assumed to have permanently
> left the realm of rational debate. 

Nugatory, since the mere presence of Godzilla in a discussion indicates 
the same thing.



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

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 913
**************************************


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