[9210] in Perl-Users-Digest
Perl-Users Digest, Issue: 2805 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 7 13:07:28 1998
Date: Sun, 7 Jun 98 10:00:32 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 7 Jun 1998 Volume: 8 Number: 2805
Today's topics:
- sort with DBM key output... - <james@cydaps.co.uk.NOSPAM>
Re: Array help (Jonathan Stowe)
Re: Date fomatting. (Gabor)
Re: Date fomatting. ptimmins@netserv.unmc.edu
Re: delete slice in list <aqumsieh@matrox.com>
Exercise in Llama Book <timbenjamin@mcmail.com>
Re: How to install PERL with user account? (Jonathan Stowe)
Re: How to install PERL with user account? (Jim Michael)
Re: Idiom for updating file? (Craig Berry)
Re: Is PERL case sensitive? (Larry Rosler)
Re: newbie ques: Here Documents ptimmins@netserv.unmc.edu
Re: newbie question on pattern matching (Jonathan Stowe)
Re: newbie question on pattern matching <xuchu@iscs.nus.edu.sg>
Re: newbie question on pattern matching (Xuming Wang)
Re: newbie question on pattern matching (Bob Trieger)
perl binary problems? <mathias@singapura.singnet.com.sg>
Re: perl binary problems? <tchrist@mox.perl.com>
Re: Problem with re-iterating if loops... <merlyn@stonehenge.com>
Re: Problem with re-iterating if loops... <tchrist@mox.perl.com>
Re: Q: puzzled: regex with inperpolation (Ronald J Kimball)
Q: sorting table %book by $title dow.jones@home.se
Question about =~ <finkeppy@finaid.indstate.edu>
Re: Question about =~ <tchrist@mox.perl.com>
Re: Removing a character from a string <aqumsieh@matrox.com>
Re: Removing a character from a string <aqumsieh@matrox.com>
Re: Removing a character from a string <aqumsieh@matrox.com>
Re: rounding down a decimal to 2 points without OOP?? <aqumsieh@matrox.com>
Re: Stupid syntax question <aqumsieh@matrox.com>
Re: Switching PERL scripts from UNIX to NT- Help! (Bob Trieger)
Re: Tutor? (Gary M. Greenberg)
Re: Win95 problems for Perl? Need assistance here! (Gary M. Greenberg)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 7 Jun 1998 15:24:04 +0100
From: "James" <james@cydaps.co.uk.NOSPAM>
Subject: - sort with DBM key output... -
Message-Id: <897229567.5993.0.nnrp-07.c2de3f1b@news.demon.co.uk>
Hi,
I was wondering if anyone would be able to help me? I have been though all
the help files and FAQs etc but with no luck.. My problem is that I have a
dbm file that
is used to store information about keyword searches. The information input
(simplified) looks like this:
$keyword = <STDIN>;
chop($keyword);
$hits = 22;
$time = time;
dbmopen(%keywords, "keywords.dbm",0666);
$keywords{$keyword} = $hits . "\t" . time;
dbmclose(%keywords);
Now we have the following data in the database (as an example):
Name Data
Key
html 3 890656634
c++ 5 890292893
graphics 4 878888878
Now, if you print this data out like this:
dbmopen(%last_good, "keywords.dbm",0666);
foreach $name (sort keys(%last_good)) {
@items = (split(/\t/, $last_good{$name}));
$hits = $items[0];
$time = localtime($items[1]);
$hours = (time - $items[1]) / 3600;
print "Keyword: $name - Hits: $hits - Last Search: $time - Hours since last
search: $hours\n";
}
it creates the list in alphabetical order based on the $name field. What I
want to be able to do is to view the list based on the $hits in the value
field of the DBM file but I cannot figure out how to do this with sort as
the $name and $hits must relate to one another, ie html has 3 hits at
890656634 etc. I have tried merging the data to create a new array with
$hits, $name and $time listed together but this does not appear to work
either. Does anyone know how I can deal with this??
Thanks very much for any help with this!
James
james@cydaps.co.uk.NOSPAM (please remove .NOSPAM if replying by email)
------------------------------
Date: Sun, 07 Jun 1998 13:10:16 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Array help
Message-Id: <357a90ae.11324711@news.btinternet.com>
On Sun, 07 Jun 1998 02:21:18 -0400, Francis L. Hartley wrote :
>Hello all,
>I know you guy's get a lot of foolish requests but, believe me I have
>tried many other sources and I would not ask this if I were not
>desperate.
>
<snip>
And the Perl question is ?
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: 7 Jun 1998 13:14:46 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: Date fomatting.
Message-Id: <slrn6nl53e.ooq.gabor@vnode.vmunix.com>
In comp.lang.perl.misc, Nick Nottleman <Nick1pub@worldnet.att.net> wrote :
# I am creating a script that polls to see if a file exists and then
# e-mails it if it does exist. I have been able to make everything work
# except that the files that I need to search for are created with the
# current date in this format:
# yymmdd
# So I need to be able to make perl look for the file.
# I have tried a bunch of things and the only thing that I even remotely
# came close with was Time::CTime which gave me way too much info.
# Sorry for posting a dumb question!
# Thanks for any input in advance!
# Nick
opendir DIR, "/path/to/files/" or die "$!";
@files = grep /^\d{6}$/,readdir DIR;
closedir DIR;
for (@files) {
# $_ is file name
# do whatever with it
}
Is this what you were looking for ?
gabor.
--
"It is easier to port a shell than a shell script."
-- Larry Wall
------------------------------
Date: Sun, 07 Jun 1998 15:51:18 GMT
From: ptimmins@netserv.unmc.edu
Subject: Re: Date fomatting.
Message-Id: <6lectm$c1n$1@nnrp1.dejanews.com>
In article <6ld405$t0k@bgtnsc03.worldnet.att.net>,
Nick Nottleman <Nick1pub@worldnet.att.net> wrote:
[snip]
> I guess I should have phrased the question better, I can tell if the
> file exists if I hard code it, but I need to assign some sort of
> variable to look for these files every day. i.e
> $filname = yymmdd
>
Numerous ways to do this, I'm sure. Here's one:
@mytime = localtime();
$temp_month = $mytime[4];
$temp_day = $mytime[3];
$temp_year = $mytime[5];
# got to add 1 to months since they are referred to as 0-11 instead of 1-12
$temp_month = $temp_month + 1;
# pad months before October with a preceding zero
if ($temp_month < 10) {
$temp_month = "0".$temp_month;
} else {
$temp_month = $temp_month;
}
# pad days before the tenth with a preceding zero
if ($temp_day < 10) {
$temp_day = "0".$temp_day;
} else {
$temp_day = $temp_day;
}
# here is your mmddyy format for $filename
$filename = $temp_month.$temp_day.$temp_year;
Hope that helps.
Patrick Timmins
U. Nebraska Medical Center
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Sun, 07 Jun 1998 11:42:08 -0700
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: delete slice in list
Message-Id: <357ADF00.9A777EF5@matrox.com>
Use splice() !
Xah Lee wrote:
> How can I
> delete a sequence of elements of a **LIST** in one line? (one semicolone)
> To
> illustrate, the following drop the last 3 elements using two lines.
>
> my @aa = split(m( ),'Dvorak keyboard is wonderful. Eh eh eh?');
> my @result = @aa[0 .. $#aa-3];
>
> where I wished something like
>
> my @result =
> ... split(m( ),'Dvorak keyboard is wonderful. Eh eh eh?') ...;
>
> Thanks.
>
> Xah, xah@best.com
> http://www.best.com/~xah/SpecialPlaneCurves_dir/specialPlaneCurves.html
> Q: is there a language that's completely ideom/sugar-syntax free?
------------------------------
Date: Sun, 07 Jun 1998 16:58:49 +0100
From: Tim Benjamin <timbenjamin@mcmail.com>
Subject: Exercise in Llama Book
Message-Id: <357AB8B9.C1CFFBE4@mcmail.com>
Hello
I'm a bit of a novice with Perl, so forgive me if I commit a faux pas.
I was doing exercise 2, chapter 5 (Hashes), when something odd happened.
My answer went like this:
print "please type a list of words, end in CTRL-Z:\n";
chomp(@words=<STDIN>);
%results=();
foreach $word (@words){
$results{$word}=$results{$word}+1;
}
foreach $word (sort keys(%results)){
print "The number of times you typed \"$word\" was
$results{$word}.\n";
}
which worked fine, (for the "extra challenge" bit), but if you take out
the "sort" in line 10, the program ignores some words beginning with x
and y when you type them in. So, if you typed "a b a a x x" (all
seperate words" you get the result "a" 3 times; "b" 1 times; and no
mention of "x". Have I done something wrong? I am using the Win32 port,
the most recent.
Thanks,
Tim Benjamin.
------------------------------
Date: Sun, 07 Jun 1998 13:10:13 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: How to install PERL with user account?
Message-Id: <357a8e26.10676870@news.btinternet.com>
On Sun, 7 Jun 1998 14:27:12 +0200, Boomer wrote :
>Subject: How to install PERL with user account?
That is Perl when talking about the language and perl when talking
about the interpreter.
>Hello.
>
>I would like to hear if it is possible to install PERL on the webserver,
>where my site is located?
>
Yes how to do so should be documented in a README file with your
distribution.
>It is a IIS server, and the so-called administrator simply can't figure
>out to setup PERL. (I've been waiting a month now).
>
I'd sack the administrator. There is a wealth of documentation
available on the subject.
>So, is it possible for me to install PERL to my own directory, and start
>using the cool scripts?
>
Well yes and no. You can install Perl in any place you want in the
usual way. However in order to use Perl for CGI then you will need to
be able to configure the server software which is generally not
available to the general user. What that configuration is is outside
the scope of this newsgroup however it is documented in the IIS
on-line manual.
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Sun, 7 Jun 1998 16:03:43 GMT
From: genepool@netcom.com (Jim Michael)
Subject: Re: How to install PERL with user account?
Message-Id: <genepoolEu6vA8.Jt4@netcom.com>
Boomer (boomer@boomer.dk) wrote:
: Hello.
Howdy.
: I would like to hear if it is possible to install PERL on the webserver, =
: where my site is located?
: It is a IIS server, and the so-called administrator simply can't figure =
: out to setup PERL. (I've been waiting a month now).
It would probably be beneficial to do the research to show the admin how
the installation is done.
Cheers,
Jim
--
INTERVIEWER: So have you experience with GUI operating systems?
CANDIDATE: Well, I was the chief operator of the computer
operated french fry system at McD's. It was very gooey.
INTERVIEWER: Great! You can start out as the NT administrator.
------------------------------
Date: 7 Jun 1998 02:09:49 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Idiom for updating file?
Message-Id: <6lcspe$e56$1@marina.cinenet.net>
Larry Rosler (lr@hpl.hp.com) wrote:
: Not losing data is certainly 'slightly better'! I assume that's what you
: meant.
Yeah, I'd kind of prefer not to lose data. :) Thanks, Tom and Larry -- I
feel much more confident, now. BTW, just as a datapoint, on my system
(Solaris 5.6) it *is* necessary to do the rewind.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Sun, 7 Jun 1998 09:14:10 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Is PERL case sensitive?
Message-Id: <MPG.fe45c0f4c402315989691@nntp.hpl.hp.com>
In article <6ldfvk$t8b$2@marina.cinenet.net>, cberry@cinenet.net says...
> Larry Rosler (lr@hpl.hp.com) wrote:
> : In article <Pine.BSI.3.96.980606193640.639B-100000@pentagon.io.com>,
> : rlogsdon@io.com says...
> : > PERL is an acroynm for "Practical Extraction and Report Language". It's
> : > common practice to capitalize acronyms.
> :
> : Not when they achieve currency. For example, BASIC, COBOL and FORTRAN
> : are now universally Basic, Cobol and Fortran. And if it ever was PERL,
> : now it's Perl.
>
> Yes, but poor C and C++ are still entirely uppercase. Blatant
> discrimination, if you ask me. :-)
>
> (And yes, I know C isn't an acronym. But also, FORTRAN wasn't an acronym
> either, but rather a compression of 'FORmula TRANSlation'. Nor was COBOL,
> actually a compression of COmmon Business Oriented Language. So perhaps
> 'ForTran' and CoBOL would be the proper names.)
ac-ro-nym n. A word formed from the initial letters of a name, such as
WAC for Women's Army Corps, or by combining initial letters or parts of a
series of words, such as *radar* for *ra*dio *d*etection *a*nd *r*anging.
Having rejected C and C++ from my list of examples, I'm now sorry I also
rejected Pascal. We could have had some fun creating a phrase for that
to be an acronym of. I've seen such a formation called a 'retronym' but
that neologism also has other definitions.
--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: Sun, 07 Jun 1998 13:18:22 GMT
From: ptimmins@netserv.unmc.edu
Subject: Re: newbie ques: Here Documents
Message-Id: <6le3ut$36v$1@nnrp1.dejanews.com>
In article <6ldgem$mpt$2@jelerak.scrye.com>,
angst <angst@scrye.com> wrote:
>
> Timothy Lowe <timlowe@u.washington.edu> wrote:
> : I've just started learning Perl and have run across a problem. I am trying
> : to create a web page and am using the following code:
>
> : print "Content-type: text/html\n\n";
> : print<<"HTML";
> : <html>
> : <head><title>This is a Web Page</title></head>
> : <body>
> : <h2>Welcome to the Web Page</h2>
> : </body>
> : HTML
> : Here is the error I am getting:
> : Can't find string terminator "HTML" anywhere before EOF
>
> It's looking for the terminator "HTML". You gave it the terminator
> HTML. When you're talking about labels, those two aren't
> the same thing (i think). try replacing print <<"HTML" with
> print <<HTML. Also, make sure the HTML on a line by itself is
> not indented (ie, the H is the first character on the line).
>
> --
> Erik Nielsen <eln@rmci.net>
[snip]
For this example here-docs "HTML" and HTML are equivalent (as are one or two
other methods). See pages 43 and 44 of the Blue Camel. It is the fact that
the final HTML tag is indented that is killing it ... put the HTML terminator
at the front of the line, and with nothing else on the line (not even
trailing white space).
Patrick Timmins
U. Nebraska Medical Center
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Sun, 07 Jun 1998 13:10:11 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: newbie question on pattern matching
Message-Id: <357a8abf.9863815@news.btinternet.com>
On 7 Jun 1998 11:58:25 GMT, wings wrote :
>what's the best debugger in perl now (for win32 platform)?
perl -d
> and btw, is there a 'readline' function that can read a line from
> a file in perl? coz i want to do this now:
>
<snip>
>
> seems there's some problems w/ my codes.. where's wrong? thx for
> any enlightment.
>
Yes there is bit of a problem here I'd say.
I'm curious as to what $_ = join('\n',); is supposed to achieve.
At no point are you actually reading from your input file. You need
to do something like:
use strict;
open (FP1,"test") || die "cannot open file\n";
while(<FP1>)
{
# do stuff with $_
}
close(FP1);
I think you had better do some more study of the documentation.
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: 7 Jun 1998 14:03:37 GMT
From: wings <xuchu@iscs.nus.edu.sg>
Subject: Re: newbie question on pattern matching
Message-Id: <6le6jp$cbt2@id4.nus.edu.sg>
sorry, some line of my codes provided previously was mistyped, the new
version followed:
: test file:
: xxxx <TOPICS="YES" NEWID="1">
: <TOPIC>wings</TOPIC>
: asdjfas
: xxxx <BODY>i am wings </BODY>
: asdfas axxx <TOPICS="NO" NEWID="2">
: xxxyyy <BODY>i am not wings </BODY>
: i wanna extract only bodies if TOPICS="YES".. here is what i wrote:
: use strict;
: open (FP1,"test") || die "cannot open file\n";
: $_ = join('\n',);
: my $i = 0;
: while ((/TOPICS="YES"/) && (s#NEWID="(\d+)"##si)) {
: $i = $1;
: s#(.*?)##si;
^^^^^^^^^^^^
s#<body>(.*?)</body>##si;
: open (FP,"+>d:/tmp/r.".$i) or die "cannot open file to write.\n";
: print FP "$1\n";
: close (FP);
: }
: close(FP1);
: seems there's some problems w/ my codes.. where's wrong? thx for
: any enlightment.
--
wings
------
You cannot learn anything unless you almost know it already.
Email: xwings@usa.net, xuchu@iscs.nus.edu.sg
ICQ UIN: 1440319
http://gump.iscs.nus.edu.sg
------------------------------
Date: Sun, 07 Jun 1998 13:32:08 GMT
From: xuming@email.unc.edu (Xuming Wang)
Subject: Re: newbie question on pattern matching
Message-Id: <357c8aed.58052824@152.2.25.74>
[posted and mailed]
sounds like homework... so I won't write any code here :-)
wings <xuchu@iscs.nus.edu.sg> wrote:
>what's the best debugger in perl now (for win32 platform)?
are there many debuggers? I only know the one described in perldebug.
either find the HTML version of this file under perl directory or use
command 'perldoc perldebug'.
> and btw, is there a 'readline' function that can read a line from
> a file in perl? coz i want to do this now:
yes, there is a 'readline' function. and it also read the newline
character so you don't need to join lines with "\n".
since this is very basic. you should get the book "Learning Perl" --
but I wonder whether they have it in Singapore. reading the Perl
documents also answers most of your questions.
> use strict;
> open (FP1,"test") || die "cannot open file\n";
when you write die message for file operation, better include $! which
contents the error message in plain english. and don't put "\n" at the
end.
> $_ = join('\n',);
although you son't know how to read a file, I guess your plan is to put
whole file to $_ here. make sure your source file isn't big.
> my $i = 0;
> while ((/TOPICS="YES"/) && (s#NEWID="(\d+)"##si)) {
> $i = $1;
> s#(.*?)##si;
you cleared $_ and put everything to $1. this works just it's a waste of
time and memory.
> open (FP,"+>d:/tmp/r.".$i) or die "cannot open file to write.\n";
^^
+> is for write and read. seems you only need write.
> print FP "$1\n";
> close (FP);
> }
> close(FP1);
>
>
> seems there's some problems w/ my codes.. where's wrong? thx for
> any enlightment.
it's not clear what you want to print to the new file exactly when you
said only want to extract bodies of 'TOPICS="YES"'. your code prints
everything except 'NEWID="(\d+)"' of the old file to new file (after all
other errors have been corrected).
and please indent your code properly.
HTH!
--
Xuming Wang
------------------------------
Date: Sun, 07 Jun 1998 15:48:21 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: newbie question on pattern matching
Message-Id: <6lecr4$ok2$1@ligarius.ultra.net>
[ posted and mailed ]
xuming@email.unc.edu (Xuming Wang) wrote:
-> wings <xuchu@iscs.nus.edu.sg> wrote:
-> > open (FP1,"test") || die "cannot open file\n";
->
-> when you write die message for file operation, better include $! which
-> contents the error message in plain english. and don't put "\n" at the
-> end.
Why not put the newline character in die message? If you don't you end up with
the prompt at the end of the error instead of on a new line.
Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-239-0341
and hang up when the recording starts. "
------------------------------
Date: 7 Jun 1998 15:02:34 GMT
From: Mathias Koerber <mathias@singapura.singnet.com.sg>
Subject: perl binary problems?
Message-Id: <6lea2a$fq7$1@mawar.singnet.com.sg>
I have some problems with the binary '&' operator in perl:
>From a debugger session:
DB<9> print $par
2716203648
In hex this is: A1E5FA80
but:
DB<10> printf "%-10.10lx",$par
007fffffff
DB<11> print ($par & 0xff000000)
2130706432
DB<12> print ($par & 0x00ff0000)
16711680
DB<13> print ($par & 0x0000ff00)
65280
DB<14> print ($par & 0x000000ff)
255
DB<15>
These values are all wrong. What is going on?
Here is the perl -V output:
$ perl -V
Summary of my perl5 (5.0 patchlevel 4 subversion 0) configuration:
Platform:
osname=linux, osvers=2.0.30, archname=i586-linux
uname='linux dnssec1 2.0.33 #1 tue jan 6 09:38:29 sgt 1998 i586 '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=y useperlio= d_sfio=
Compiler:
cc='cc', optimize='-O2', gccversion=2.7.2.1
cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
stdchar='char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=4, usemymalloc=n, randbits=31
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lndbm -lgdbm -ldbm -ldb -ldl -lm -lc
libc=/lib/libc.so.5.4.23, so=so
useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Built under linux
Compiled at Mar 6 1998 13:39:26
@INC:
/usr/lib/perl5/i586-linux/5.004
/usr/lib/perl5
/usr/lib/perl5/site_perl/i586-linux
/usr/lib/perl5/site_perl
--
Mathias Koerber | Tel: +65 / 471 9820 | mathias@staff.singnet.com.sg
SingNet NOC | Fax: +65 / 475 3273 | mathias@koerber.org
Q'town Tel. Exch. | PGP: Keyid: 768/25E082BD finger mathias@singnet.com.sg
2 Stirling Rd | 1A 8B FC D4 93 F1 9A FC BD 98 A3 1A 0E 73 01 65
S'pore 148943 | Disclaimer: I speak only for myself
The use of COBOL cripples the mind; its teaching should therefore be
regarded as a criminal offense. -- E W Dijkstra
------------------------------
Date: 7 Jun 1998 16:44:17 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl binary problems?
Message-Id: <6leg11$9vg$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
mathias@singnet.com.sg writes:
:I have some problems with the binary '&' operator in perl:
:
:These values are all wrong. What is going on?
You're getting hosed by the 31->32 bit boundary. It really isn't wise to
play bit games with floating-point numbers, you know! Notice how
(1 << 35) is 8, not 34_359_738_368, as you might expect. It wraps at
32 bits.
However, the current development release does this:
DB<6> printf "%-10.10lx",$par
00a1e5fa80
DB<7> print ($par & 0x000000ff)
128
DB<8> printf "%-10.10lx",$par
00a1e5fa80
DB<9> print ($par & 0xff000000)
2701131776
DB<10> print ($par & 0x00ff0000)
15007744
DB<11> print ($par & 0x0000ff00)
64000
DB<12> print ($par & 0x000000ff)
128
--tom
--
"No, I'm not going to explain it. If you can't figure it out,
you didn't want to know anyway..." --Larry Wall
------------------------------
Date: Sun, 07 Jun 1998 16:21:31 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Problem with re-iterating if loops...
Message-Id: <8c7m2tyygt.fsf@gadget.cscaper.com>
>>>>> "Tom" == Tom Christiansen <tchrist@mox.perl.com> writes:
Tom> for ($query_type) {
Tom> return /^title$/ && 2 ||
Tom> /^artist$/ && 3 ||
Tom> /^medium$/ && 6 ||
Tom> /^comment$/ && 9 ||
Tom> /^categegory$/ && 10;
Tom> }
Ewww. Didn't anyone ever teach you NOT to use A && B || C as if-then-else
because it doesn't scale to the times when B returns false? Ewww.
If you're gonna show people this you need to use the canonical
scalable form:
return
/^publisher$/ ? 0 :
/^title$/ ? 2 :
/^artist$/ ? 3 :
/^medium$/ ? 6 :
/^comment$/ ? 9 :
/^category$/ ? 10 :
die "bad value: $_";
There. Now 0 is a valid return form, and we have a die catching "other".
Moral: *don't* use A && B || C for if-then-else. Use A ? B : C, as
Ritchie (via Wall) intended.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 85 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 7 Jun 1998 16:28:07 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Problem with re-iterating if loops...
Message-Id: <6lef2n$8ho$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Randal Schwartz <merlyn@stonehenge.com> writes:
:Ewww. Didn't anyone ever teach you NOT to use A && B || C as if-then-else
:because it doesn't scale to the times when B returns false? Ewww.
But they didn't.
:Moral: *don't* use A && B || C for if-then-else. Use A ? B : C, as
:Ritchie (via Wall) intended.
Don't think so. I know quite exactly what I'm doing. That's like saying
"don't use while if $x{K} because you should always say if exists $x{$K}".
Which would also be going too far.
#!/usr/bin/perl
# os_snipe - redirect to a Jargon File entry about current OS
#################################################
# redirect the point-and-drool masses elsewhere #
#################################################
for ($ENV{HTTP_USER_AGENT}) {
$quiplet = /Mac/ && 'm/Macintrash.html'
||
/Win(dows )?NT/ && 'e/evilandrude.html'
||
/Win|MSIE|WebTV/ && 'm/MicroslothWindows.html'
||
/Amiga/ && 'a/amoeba.html'
||
/IBM/ && 'i/IBM.html'
||
/Linux/ && 'l/Linux.html'
||
/HP-UX/ && 'h/HP-SUX.html'
||
/SunOS/ && 's/ScumOS.html'
||
/AIX/ && 'a/AIDX.html'
||
/SCO/ && 'o/OpenDeathTrap.html'
||
/VMS/ && 'v/VMS.html'
||
/OSF/ && 'f/FUDwars.html'
||
/BSD/ && 'b/BSD.html'
||
/OS\/?2/ && 'o/OS2.html'
||
/X11/ && '/u/Unix.html'
||
'a/AppendixB.html';
}
printf STDERR "bados: sending %s to %s\n",
$ENV{HTTP_USER_AGENT}, $quiplet;
print "Location: http://www.wins.uva.nl/~mes/jargon/$quiplet\n\n";
__END__
--
"...we will have peace, when you and all your works have perished--and
the works of your dark master to whom you would deliver us. You are a
liar, Saruman, and a corrupter of men's hearts." --Larry Wall in perl/taint.c,
------------------------------
Date: Sun, 7 Jun 1998 12:24:21 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Q: puzzled: regex with inperpolation
Message-Id: <1da95cq.1uwb4cs1rvdo3wN@bay1-212.quincy.ziplink.net>
[posted and mailed]
Xah Lee <xah@shell13.ba.best.com> wrote:
> my $str = 'xxxxxxxxxxxx';
> my $patternString = q{(\Q.m\E|\Q.nb\E)$};
> if ($str =~ m/${patternString}/) {print 'matched';} else {print 'no match';};
>
> for what $str such that it will match?
$str = 'Q#mE';
$str = 'Q@nbE';
Why?
First, when you assign to $patternString, you are using the single-quote
operator, q//, which does not recognize \Q, \E, etc. In such cases, the
single-quote operator leaves the character sequence untouched. So the
value of $patternString is '(\\Q.m\\E|\\Q.nb\\E)$'.
(Note that '\\Q' is equivalent to '\Q'.)
Second, when you interpolate $patternString in m//, there is only one
level of interpolation. So, the pattern that is passed to the regex
engine is '(\Q.m\E|\Q.nb\E)$'.
Third, the regex engine does not recognize \Q, \E, etc. In such cases,
the regex engine matches the literal character. So, the pattern that
the regex engine tries to match is '(Q.mE|Q.nbE)$'.
To solve this problem, use the double quote operator, qq//, when
assigning to $patternString.
$patternString = qq{(\Q.m\E|\Q.nb\E)\$};
Note that the final $ must now be preceded by a backslash.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sun, 07 Jun 1998 16:46:22 GMT
From: dow.jones@home.se
Subject: Q: sorting table %book by $title
Message-Id: <6leg4u$fl0$1@nnrp1.dejanews.com>
Hallo.
I have a structure that looks like this
%book = {$isbn -> [$author, $title]}
I want to print out everything in %book like this
while (($isbn, $reference) = each %book)
{
print STDOUT >>HTML;
<TR>
<TD>$isbn</TD>
<TD>$reference->[0]</TD>
<TD>$reference->[1]</TD>
</TR>
HTML
}
The question is, how do I sort %book by $title.
Thank you
// Dow.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Fri, 05 Jun 1998 08:25:08 -0500
From: Keppy Boone <finkeppy@finaid.indstate.edu>
Subject: Question about =~
Message-Id: <3577F1B4.C20A9C52@finaid.indstate.edu>
I am having some difficulty getting a search to work given a string.
ex.
$_ =~ /look/i; # works fine.
$search = "/look/i";
$_ =~ $search; #Doesn't work.
Any Ideas will help.
Please email me at ccboone@amber.indstate.edu
Charles Boone
------------------------------
Date: 7 Jun 1998 16:29:50 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Question about =~
Message-Id: <6lef5u$8ho$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Keppy Boone <finkeppy@finaid.indstate.edu> writes:
:I am having some difficulty getting a search to work given a string.
:
:ex.
:
:$_ =~ /look/i; # works fine.
Yes, but is certainly ugly. Why you would *ever* use "$_ =~"
is beyond me. It's the default.
:
:$search = "/look/i";
:$_ =~ $search; #Doesn't work.
You're putting the slashes in the wrong place,
and you're not remembering how to embed options.
See perlre.
$search = "(?i)look";
if (/$search/) { do something here }
--tom
--
X-Windows: "The first fully modular software disaster.
--Jamie Zawinski
------------------------------
Date: Sun, 07 Jun 1998 11:36:24 -0700
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Removing a character from a string
Message-Id: <357ADDA8.F11B1932@matrox.com>
Ed Weinberg wrote:
> On Fri, 5 Jun 1998 12:24:00 -0700, "Martine Habib"
> <mhabib@microsoft.com> wrote:
>
> >If I have a string $string = "this&that";
> >I want to remove the ampersand, and end up with $string = "thisthat";
> >
> >How can I do this in perl ?
> >Thanks for any help,
>
> this will substitute "" for the first "&" from anywhere in that
> string:
> $string =~ s/&//;
>
> -- Ed Weinberg,
You might want to use the /g modifier there.
But, a faster solution would be :
$string =~ tr/&//;
Ala
------------------------------
Date: Sun, 07 Jun 1998 11:37:13 -0700
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Removing a character from a string
Message-Id: <357ADDD9.FC30E2A4@matrox.com>
Ala Qumsieh wrote:
> Ed Weinberg wrote:
>
> > On Fri, 5 Jun 1998 12:24:00 -0700, "Martine Habib"
> > <mhabib@microsoft.com> wrote:
> >
> > >If I have a string $string = "this&that";
> > >I want to remove the ampersand, and end up with $string = "thisthat";
> > >
> > >How can I do this in perl ?
> > >Thanks for any help,
> >
> > this will substitute "" for the first "&" from anywhere in that
> > string:
> > $string =~ s/&//;
> >
> > -- Ed Weinberg,
>
> You might want to use the /g modifier there.
> But, a faster solution would be :
>
> $string =~ tr/&//;
>
> Ala
Oooopps!
$string =~ tr/&//d;
of course ;-)
------------------------------
Date: Sun, 07 Jun 1998 11:38:34 -0700
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Removing a character from a string
Message-Id: <357ADE2A.A619986D@matrox.com>
Ala Qumsieh wrote:
> Ed Weinberg wrote:
>
> > On Fri, 5 Jun 1998 12:24:00 -0700, "Martine Habib"
> > <mhabib@microsoft.com> wrote:
> >
> > >If I have a string $string = "this&that";
> > >I want to remove the ampersand, and end up with $string = "thisthat";
> > >
> > >How can I do this in perl ?
> > >Thanks for any help,
> >
> > this will substitute "" for the first "&" from anywhere in that
> > string:
> > $string =~ s/&//;
> >
> > -- Ed Weinberg,
>
> You might want to use the /g modifier there.
> But, a faster solution would be :
>
> $string =~ tr/&//;
>
> Ala
Oooooppps!
$string =~ tr/&//d;
of course ;-)
------------------------------
Date: Sun, 07 Jun 1998 11:34:47 -0700
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: rounding down a decimal to 2 points without OOP??
Message-Id: <357ADD47.8578313@matrox.com>
You might want to try
printf "%1.2f", $number;
Stephan Carydakis wrote:
> Hello All,
>
> PROBLEM: can I round(to 2 decimal points) a scalar without
> "use Math::BigFloat".Is there a simpler way in Perl do do this??
>
> I can round up to the closest integer using sprintf, but this is not
> what I need.
>
> Could someone give me any info as to this?? Anything would help.
>
> I'm running Perl5 for win32(95a :-[). I have been using Perl for CGI
> development using a Netscape Fast Track Server.
>
> I've have been trying to teach my self Perl since the start of the year
> using the "legendary" book 'Programming Perl'(my brain is frying, but
> I'm loving it :]).
>
> thanks in advance
> _________________
> Stephan Carydakis
> mailto: steph@hotkey.net.au
------------------------------
Date: Sun, 07 Jun 1998 11:49:06 -0700
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Stupid syntax question
Message-Id: <357AE0A2.260108@matrox.com>
gateway wrote:
> I just started learning Perl, so forgive me if this is stupid. I can't
> seem to get the syntax right. what I want to do is use a loop to cycle
> through all elements in an array, one at a time, using a variable as the
> array index (ie &array[$counter]). can someone clear this up for me.
> I'm sorry if this sounds simple, but I've tried everything I can think of.
Did you try reading *ANY* book on Perl? This is a trivial question, and any
book should have the answer in the first 10 pages or so! I suggest you bother
yourself and read a bit before posting again.
> Zen
If you want to access a scalar, then your variable has to start with a $ ...
@array is an array .. but array[$index] is a scalar so it has to be accessed
as so:
$array[$index]
Heplful hint: Check out the foreach statement.
Ala
------------------------------
Date: Sun, 07 Jun 1998 12:54:35 GMT
From: voting.smoker@juicepigs.com (Bob Trieger)
Subject: Re: Switching PERL scripts from UNIX to NT- Help!
Message-Id: <6le2le$is8$1@ligarius.ultra.net>
[ posted and mailed ]
"Chris" <cnott@b-c-web.com> wrote:
->
-> I have this same problem. What is the proper format of the hash/bang line?
-> My attempts at re-writing this script have produced 2 results.
->
-> 1st - the browser does not interpret it as a script and displays the full
-> contents of the script in the browser window.
What leads you to think that this is a problem with the hashbang line or
anything with perl at all? Perl does not have a browser window.
-> 2nd - I get an error telling me my script did not return a valid set of
-> headers and that there is no such file or directory.
Perl does not have headers. A CGI program written in perl can print headers to
an HTTP server. Therefore you should check your server documentation for CGI.
and if you still can't find your solution try posting to:
news:comp.infosystems.www.authoring.cgi or a group dedicated to your HTTP
server.
-> Forgive this newbie question, but, please, help!
Not this morning, there have been too many of them.
Good luck
Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-239-0341
and hang up when the recording starts. "
------------------------------
Date: Sun, 07 Jun 1998 14:46:26 GMT
From: garyg@gator.net (Gary M. Greenberg)
Subject: Re: Tutor?
Message-Id: <6Jxe1.647$%a.562694@news.randori.com>
Birgitt Funk <ngouah@erols.com> wrote:
> Gary M. Greenberg wrote:
[snip]
> I like your answer.
>
> But ... if you would analyze what you said, you
> will see that someone who has *no* programming background and
> has/had no job related exposure to system administration
> on any OS ... can hardly make it within a year, if you have
> to squeeze it into your other daily duties.
>
> Trying to do just what you suggested, structuring your
> learning process for someone who has had *zero* exposure,
> I came up with:
>
> 1. work through one structured introductory programming
> book and/or classes using a language like let's say Pascal
> (how about Fortran BTW?)
I'd guess the language per se is irrelevant, so sure Fortran too.
BTW, back to the original poster:
How about learning REXX; seems like there'd be local expert help
available to ya ;-)
[snip possible path to success]
> IMHO nobody should make anyone believe that this
> is a matter of a one year learning process in your free time,
> if you don't have job related exposure or tasks to go with it.
>
> Wrong ?
Not likely.
>
> Birgitt Funk
Again, for the original poster:
How are your problem solving skills (PSS)? To me, PSS are the critical
factor to being a good programmer. Before I strike the 1st keystroke of
source code, I've already outlined a method for arriving at a solution
to the problem at hand. After that, even if I don't know how to code
what I'm trying to do, I know what I'm looking for when I start
researching for existing modules, methods, requests, library function
calls, or what have you (even && especially someone else's solution to a
similar problem).
I know I'm never going to know all that I need to know to be a great
programmer, so I've learned to do the best that I can by standing on the
shoulders of giants ;p
Regards, Gary
gary -=- The C Programmers' Reference -=-
http://www.gator.net/~garyg/C/c.html
-=- Avenue Programmers' Classes' Requests -=-
http://www.gator.net/~garyg/class.htm
------------------------------
Date: Sun, 07 Jun 1998 14:51:43 GMT
From: garyg@gator.net (Gary M. Greenberg)
Subject: Re: Win95 problems for Perl? Need assistance here!
Message-Id: <3Oxe1.651$%a.562694@news.randori.com>
Perhaps you should post some of the Perl scripts that are giving your
trouble, especially if they're small.
Cheers,
gary -=- The C Programmers' Reference -=-
http://www.gator.net/~garyg/C/c.html
-=- Avenue Programmers' Classes' Requests -=-
http://www.gator.net/~garyg/class.htm
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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 V8 Issue 2805
**************************************