[8515] in Perl-Users-Digest
Perl-Users Digest, Issue: 2132 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 19 02:18:09 1998
Date: Wed, 18 Mar 98 23:00:32 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 18 Mar 1998 Volume: 8 Number: 2132
Today's topics:
<> for binary file, line length, unpack,read (Darwin O.V. Alonso)
Re: [Q] MacPerl - How to use libraries? <madebeer@igc.apc.org>
Re: A Perl version of Crypt <dformosa@st.nepean.uws.edu.au>
Re: A Perl version of Crypt (Martin Vorlaender)
Re: building for perl 5.004_04 on NT (Tye McQueen)
Re: calculating distance between strings (fortune cooki (Daniel R. Kegel)
Challenge your programming skill <kiml@zplace.com>
Re: Easy regex question <rick.delaney@shaw.wave.ca>
Re: Extracting HTML <TITLE>...</TITLE> using Perl? djhoward@uiuc.edu
Help (Birjinder Singh Anant)
Re: Large integer keys in hash - perl5 <uri@sysarch.com>
Re: ls -l to an array and pull 3 columns on data <hightowr@probe.net>
Re: Need help parsing a text file <rjk@coos.dartmouth.edu>
Perl 5 Tutorials <cellis@voyageur.ca>
Re: Perl for DOS/Windows 3.x <pathos97@samsung.co.kr>
Re: Problem of auto-increment in s///; <rick.delaney@shaw.wave.ca>
Re: Qui sera assez fort pour repondre a ca ?? (Stefaan A. Eeckels)
Re: regexp question -- making $replacestring = '$1' wor (Martin Vorlaender)
Re: removing everything between < and > <tchrist@mox.perl.com>
Re: removing everything between < and > (Abigail)
same ndbm dbs on both hpux 9.05 and 10.20? (Christopher Ryan Sidi)
Re: Splitting a string to make keys to a hash <rick.delaney@shaw.wave.ca>
Re: Splitting a string to make keys to a hash (Mike Heins)
Re: Trimming a Variable <rjk@coos.dartmouth.edu>
Re: Troubles "perl"ifying a shellscript that uses pipes (Martin Vorlaender)
unpack loops (Darwin O.V. Alonso)
Re: Using perl code as a config file syntax? (Or, can r <uri@sysarch.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Mar 1998 04:36:21 GMT
From: dalonso@u.washington.edu (Darwin O.V. Alonso)
Subject: <> for binary file, line length, unpack,read
Message-Id: <6eq7c5$10hs$1@nntp6.u.washington.edu>
I am reading a binary file, and a proper implementation of
the following pseudo code works:
#1
#Open and get record lengths
( open IN, "$ARGV[0]" ) || die "couldn't open $ARGV[0]:$!";
read IN,$tmp, 4;
( $rec_length ) = unpack("i", "$tmp" );
#Read Record
seek IN, 0, 0; read IN,$record, $rec_length;
close IN;
#Parse record with multiple unpacks
$nsk = 8; $nat = 100;
@foo = unpack("x$nsk s$nat", "$record"); $nsk += 2*$nat;
However, variations on
#2
$line = <IN>;
$nsk = 8; $nat = 100;
@foo = unpack("x$nsk s$nat", "$line"); $nsk += 2*$nat;
eventually fail, because $line does not contain the entire record
(i.e. in my case, length $line gives 11202, and length $record gives 18372).
So, given this little information:
What does $line = <IN>; do with a binary file.
Does #1 (above) seem the best way to do this?
Is there a way or a reason to use only read or unpack (but not both)?
Thanks
Darwin
------------------------------
Date: Wed, 18 Mar 1998 18:30:39 -0800 (PST)
From: Michael de Beer <madebeer@igc.apc.org>
Subject: Re: [Q] MacPerl - How to use libraries?
Message-Id: <APC&1'0'50775d8d'7a7@igc.apc.org>
I don't know for sure, but here are two ideas:
* Maybe you are making a run-time version, and perl didn't copy those
libraries into the run-time. If so, copy those libraries to the
directory with the run-time.
* Maybe the modules are messed up. See if they compile or reinstall
MacPerl.
-Michael
------------------------------
Date: 19 Mar 1998 04:26:38 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: A Perl version of Crypt
Message-Id: <890281598.856434@cabal>
In <35106783.CA258AAF@usa.net> Sneex <chasecreek.systemhouse@usa.net> writes:
>CRYPT is Built into Perl, no need to post it :-)
Crpyt is built into the OS. Often the cypt liberaise are unadvalable.
--
Please excuse my spelling as I suffer from agraphia see the url in my header.
Never trust a country with more peaple then sheep.
Support NoCeM http://www.cm.org/
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: Thu, 19 Mar 1998 04:21:03 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: A Perl version of Crypt
Message-Id: <35108f1f.524144494f47414741@radiogaga.harz.de>
Stephen Wood (swood@microsoft.com) wrote:
: Someone once posted a Perl version of crypt to this newsgroup. Could you
: please repost?
It's at http://www.pdv-systeme.de/users/martinv/Crypt.pm
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
Ceterum censeo | work: mv@pdv-systeme.de
Redmondem delendam esse. | http://www.pdv-systeme.de/users/martinv/
| home: martin@radiogaga.harz.de
------------------------------
Date: 18 Mar 1998 19:41:37 -0600
From: tyde@medtrodnet.cdom (Tye McQueen)
Subject: Re: building for perl 5.004_04 on NT
Message-Id: <6ept4h$k35@fohnix.metronet.com>
) > > - All links in the HTML version of the doc were "broken". I suspect
) >
) "Uwe Honekamp" <uwe.honekamp@etas.de> writes:
) > dito. The browser well-understands /F|/dir1/dir2/.../file.html.
[...]
Frank@but_dont_use_this.address writes:
) And please note I had a path //F|/dir1/dir2/.../file.html.
) (Two slashes at the beginning)
Note a previous posting of mine (see http://www.dejanews.com)
that included a Perl script to transform all of these into
relative paths so that they will work even after you move the
whole directory tree and will work if you put them on a real
Web server or access them via a network share, etc.
I really think the relative paths should be the default for
these reasons (and they look nicer).
--
Tye McQueen Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
Remove d's from address to reply (sorry for the inconvenience).
------------------------------
Date: 19 Mar 1998 06:39:00 GMT
From: dank@alumnae.caltech.edu (Daniel R. Kegel)
Subject: Re: calculating distance between strings (fortune cookies)
Message-Id: <6eqei4$85d@gap.cco.caltech.edu>
sitaram@diac.com (Sitaram Chamarty) writes:
>>>Simon Oosthoek wrote:
>>>> I'm looking for a program/script/whatever that can calculate the
>>>> distance between two text-strings.
>
>One more hint: look for the description or definition of "Soundex"
>...
>A long time ago I did some work on phonetic "nearness" and
>"syllable matching" using a DP algorithm of some sort
Ah, yes, dynamic programming. Also known as time warping or Vitterbi
decoding. Great stuff.
I used it in speech recognition and in reducing the number of data points
needed to represent a coastline to a given accuracy once.
Kind of expensive for finding similar stories
in a pile of 40,000, but computers are pretty fast these days...
- Dan
------------------------------
Date: Wed, 18 Mar 1998 21:35:34 -0800
From: Kim Lo <kiml@zplace.com>
Subject: Challenge your programming skill
Message-Id: <3510AEA6.DF610245@zplace.com>
Perl programmers,
I am facing with the challenge of writing a program to find the closest
customer name based on an input zipcode. I have the data file containing
zipcode, state, longitude and latitude in a database already.
My approach to this problem is very simple however I want to find out
from you programmers if this is the most efficient way to do it. Here're
the steps:
1. Get the long and lat based on the input zipcode
2. For each customer do
a. Get customer zipcode and determine long and lat
b. Delta long and lat from step1 and 2a. Get the absolute value
c. Convert the long and lat into an R value using pythagore
theorem (R^2=x^2+y^2)
3. Sort the R value and the smallest R will contain the closest customer
to the input zipcode.
The problem I am having with this algorithm is that it could take a long
time to compute as the number of customers grow. To minimize computing,
I thought of just getting customers from the same state as the input
zipcode and compute those only. The caveat to this approach is that for
someone that lives closeby 2 states (especially on the East Coast), this
may return incorrect result.
Any feedback is welcome.
------------------------------
Date: Wed, 18 Mar 1998 21:47:14 -0500
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Easy regex question
Message-Id: <35108732.1E5A0F12@shaw.wave.ca>
Chris wrote:
>
> I have a regex question that for some reason is stumping me:
>
> How the heck do I match a word?
>
> For example, I want to check for 0 or 1 instances of the word 'teapot'.
> /teapot?/ doesn't work, since it checks for 'teapo' and an optional t.
> /[teapot]/ is of course also not quite right. What the heck is my
> problem? My perl book is packed away in my brother's basement, the
> perlop help page doesn't help with this, and I looked at www.perl.org
> for an FAQ but I couldn't find one mentioned.
>
The page you want is perlre.
/(teapot)?/ matches 0 or 1 occurence of 'teapot'. I assume you will add
some other stuff to the regexp or it will match everything.
/\w+/ will match a general word, where a word contains letters, numbers
or underscores.
HTH
--
Rick
------------------------------
Date: 19 Mar 1998 04:02:51 GMT
From: djhoward@uiuc.edu
Subject: Re: Extracting HTML <TITLE>...</TITLE> using Perl?
Message-Id: <6eq5db$ec$1@vixen.cso.uiuc.edu>
Matt Sephton <u5ms@csc.liv.ac.uk> wrote:
> How would I go about extracting the HTML tag <TITLE>...</TITLE> using
> Perl? Would a regular expression suffice?
### Working code snippet;
# http://www.dannyland.org/~dannyman/warez/daze-lib.txt
open(HTML, "$base_dir/$file") or warn "Error opening $file: $!"; {
$file_string = join($",<HTML>);
if( $file_string =~ /<title>(.*?)<\/title>/is ) {
$title = $1; $title =~ s/\n//g; }
if( $file_string =~ /<meta name="description" content="(.*?)">/is ) {
$description = $1; $description =~ s/\n//g; }
--
//Dan -=- This message brought to you by djhoward@uiuc.edu -=-
\\/yori -=- Information - http://www.uiuc.edu/ph/www/djhoward/ -=-
aiokomete -=- Our Honored Symbol deserves an Honorable Retirement
------------------------------
Date: 19 Mar 1998 06:49:26 GMT
From: bsanant@uclink.berkeley.edu (Birjinder Singh Anant)
Subject: Help
Message-Id: <6eqf5m$jl9$1@agate.berkeley.edu>
Hi,
I've been trying to debug this program for the past couple of days to no
avail. I can't figure out what's wrong. If someone could help, I would be
grateful. I took part of the program (as seen below) and made it
self-contained, but even this part doesn't work. The error message I get
is:
Use of uninitialized value at ./split.pl line 10<BIRJ> chunk 1(-6)
birj.txt is just a file that has the same look as a CSV file, only a lot
smaller than the ones I'm working with. Individual fields are delimited
by commas, and text is surrounded by quotation marks. Quotations within
fields have two sets of quotations around them
Thanks in advance.
Birjinder
#!/usr/bin/perl -w
#bsa 98.03.16
#This is part of a script which processes a CSV text dump from Microsoft
#Access.
#The CSV format Access puts out is a little bit weird - quotes with text
#strings
#are doubled, and database fields which are set to numberic or date value
#are
#not quoted...
open (BIRJ, "/home/birjinder/public_html/birj_cgi/birj.txt");
while (<BIRJ>) {
my(@records) = &splitLine($_);
print $records[0], "\n";
}
close (BIRJ);
exit(0);
#splitLine returns an array made from elements on the line
sub splitLine {
my($field) = "";
my($char) = "";
my($nextChar) = "";
my($j) = 0;
my(@array);
my($inQuote)=0;
while(1){
if ($nextChar eq "") {
$char = getc();
}else {
$char = nextChar;
$nextChar = "";
}
if ($char eq ","){
if ($inQuote == 1){
$field .= $char;
}else{
$array[$j++] = $field;
$field = "";
}
}
elsif ($char eq "\"") {
if ($inQuote == 1){
$nextChar = getc();
if ($nextChar eq "\""){
$field .= $char;
$nextChar = "";
}else{
}
}else{
$inQuote = 1;
}
}
elsif ($char eq "\n"){
if ($inQuote == 1){
$field .= $char;
}else {
return (@array);
}
}
elsif ($char eq "") {
return (@array);
}
else {
$field .= $char;
}
}
}
------------------------------
Date: 18 Mar 1998 22:54:51 -0500
From: Uri Guttman <uri@sysarch.com>
To: Jerry Pendergraft <jerry.pendergraft@endo.com>
Subject: Re: Large integer keys in hash - perl5
Message-Id: <x7g1kfibck.fsf@sysarch.com>
Jerry Pendergraft <jerry.pendergraft@endo.com> writes:
> I recently ran across a strange behavior in perl5.
> If one reads input consisting of numbers represented as:
> 0x0
> 0xffff
> 0x7fffffff
> 0x80000000
> 0x80000001
>
> print "0x0\n" if defined($hash{0x0});
> print "0xffff\n" if defined($hash{0xffff});
> print "0x7fffffff\n" if defined($hash{0x7fffffff});
> print "0x80000000\n" if defined($hash{0x80000000});
> print "0x80000001\n" if defined($hash{0x80000001});
>
> Produces only:
> 0x0
> 0xffff
> 0x7fffffff
if you print the keys to the hash, you will see the problem.
foreach $key ( keys %hash ) {
print "'$key' => '$hash{$key}'\n" ;
}
'2147483649' => '1'
'65535' => '1'
'0' => '1'
'2147483647' => '1'
'2147483648' => '1'
0x80000000, 0x80000001 are converted to floats and then to 2147483648,
2147483649 which don't match.
if you want your behavior, use strings by quoting the keys in the
hash. you shouldn't rely on integers as stable keys when you are near or
on overflow values.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---- 8 Years of Perl Experience, Available Immediately
uri@sysarch.com --------- Resume and Perl Example at http://www.sysarch.com
Use the Best Search Engine on the Net -------- http://www.northernlight.com
------------------------------
Date: Wed, 18 Mar 1998 22:48:45 -0600
From: Dave Hightower <hightowr@probe.net>
Subject: Re: ls -l to an array and pull 3 columns on data
Message-Id: <3510A3A7.25F28629@probe.net>
schwern@starmedia.net wrote:
> Avoid unnecessary system calls. Use readdir, opendir and stat.
>
> opendir(DIR, $dirname) || die $!;
> foreach my $filename (readdir(DIR)) {
> @stat = stat $filename;
> # do something with @stat...
> }
>
> stat returns everything that ls -l does, and more and in a consistant format.
>
> In article <6ebe4u$c0e$1@nnrp1.dejanews.com>,
> grindrod@tfn.com wrote:
> >
> > I am trying to send the output of the ls -l command to and array or
> filehandle
> > and the print only 3 of the 9 columns of the output for each line.
Hmmmm. Why?
I would do something like
chomp(@array = `ls -l | cut -f1,2,3`)
Is that less efficient? Obviously it not true perl-ese, but which is faster?
Dave
------------------------------
Date: Thu, 19 Mar 1998 01:50:23 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
To: Barry Brown <bbrown@sna.com>
Subject: Re: Need help parsing a text file
Message-Id: <3510C034.C70F2EA2@coos.dartmouth.edu>
[posted and mailed]
Barry Brown wrote:
>
> I want to turn this:
>
> Some text
> %{ statement 1 }%
> Some more
> text
> %{ statement 2}%%{ statement 3 }%
> %{multi-line
> statement 4}%text%{ statement 5 }%
>
> into an array, @prog, of array refs:
>
> $prog[0] = [$TEXT, "Some text\n"]
> $prog[1] = [$STMT, "statement 1"]
> $prog[2] = [$TEXT, "\nSome more\ntext\n"]
> $prog[3] = [$STMT, "statement 2"]
> $prog[4] = [$STMT, "statement 3"]
> $prog[5] = [$TEXT, "\n"]
> $prog[6] = [$STMT, "multi-line\nstatement 4"]
> $prog[7] = [$TEXT, "text"]
> $prog[8] = [$STMT, "statement 5"]
> $prog[9] = [$TEXT, "\n"]
>
> (or something close to this)
>
> Because of these, simple pattern matching with .*? doesn't work, since
> "." never matches a newline.
Haven't read much of the documentation, have you?
The /s modifier allows '.' to match a newline.
/abc.*def/s;
> I tried a more complex match like
> /((.|\n)*?)%{\s*((.|\n)*?)\s*}%/ after snarfing the entire file into a
> variable, but the nested parentheses seem to confound the assignments to
> $1 and $2. (Side note: Programming Perl doesn't seem to explain how $1,
> $2, ... are assigned when parentheses are nested.)
You have Programming Perl... How could you not know about /s?
And it does explain nested parentheses. 2nd Ed, page 65:
Pairs of parentheses are numbered by counting left parentheses from the left.
Thus, in your regex:
/((.|\n)*?)%{\s*((.|\n)*?)\s*}%/
1111111111 3333333333
222222 444444
Also, on page 64:
This side effect can be suppressed by using (?:...) instead, which has only
the grouping semantics -- it doesn't store in anything in $1, $2, and so on.
> A RE like ([.\n]*?) doesn't work, either.
[.\n] doesn't work as you expected because '.' isn't special in a character
class. [.\n] will match either a literal dot or a newline. Also in the documentation...
> I've also tried using loops with index and substr, but I end up with
> icky boundary conditions that I haven't been able to resolve cleanly.
>
> Is there an easier way? Or will I just have to slog through it and
> maybe do something like split the file into an array of single
> characters with @arr = split('', $_) so I can walk through it a
> character at a time?
Goodness no!
# input in $_
@stmt_or_text = qw(STMT TEXT); # flags for statements and text
$is_stmt = /^%\{/; # is first element a statement?
@prog =
map {
$is_stmt ^= 1; # toggle $is_stmt
[ $stmt_or_text[$is_stmt], $_ ] # anon array: [ FLAG, string ]
}
split /%\{|\}%/; # split on %{ and }%
Tested. Works with null text '}%%{' and null statements '%{}%' because split
returns null strings where they occur.
--
_ / ' _ / - 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: Wed, 18 Mar 1998 22:58:52 -0600
From: "J.E." <cellis@voyageur.ca>
Subject: Perl 5 Tutorials
Message-Id: <3510A60C.3403@voyageur.ca>
I was wondering where I could find a good Perl 5 tutorial that wouldn't
be too Unix-specific to be applicable to Perl Win32, and that is
downloadable. I have Perl 5 for Win32, so a Win32 specific tut would be
ideal. Thank you for your time and help!
Hookflash
------------------------------
Date: Tue, 17 Mar 1998 11:56:31 +0900
From: "Merlin" <pathos97@samsung.co.kr>
Subject: Re: Perl for DOS/Windows 3.x
Message-Id: <6eko0r$9jv$1@news.att.co.kr>
Flavio Pereira @L(0!) <6ejthf$mmr$1@news.fr.internet.bosch.de> 8^=CAv?!<-
@[<:GO?4=@4O4Y...
>Hi !
>
> Does anybody knows where I can find Perl package for DOS/Windows 3.x ?
>I know nothing about this language but I really need it now.
> Some documentation is also important.
> Thanks for any help.
>
>Flavio.
You can visit here...
http://www.activestate.com/software/Perl_for_Win32.htm
There is a perl debugger for windoz...
If you find some documentations...visit here
http://www.perl.org
------------------------------------------
Yu Don, Network Analyst
Information Network Center
Samsung SDS
R.o.Korea
------------------------------------------
------------------------------
Date: Wed, 18 Mar 1998 22:07:55 -0500
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Problem of auto-increment in s///;
Message-Id: <35108C0B.74F00968@shaw.wave.ca>
Wei Tang wrote:
>
> Hi,
>
> I want to auto-increment a variable in s///. I got the following running
> fine under Perl4. But I got an error when using Perl5:
> ...
> Can't modify constant item in postincrement at count.pl line 6, near
> "cnt++"
>
> #!/usr/local/bin/perl -w
>
> $cnt = 0;
> $str = "one two three four five";
> print "$str \n";
> $str =~ s/(\w+)/$1_${cnt++}/g;
This actually works under perl4? Ugh. Try this:
$str =~ s/(\w+)/"$1_" . $cnt++/ge;
HTH
--
Rick
------------------------------
Date: 19 Mar 1998 06:32:16 GMT
From: Stefaan.Eeckels@ecc.lu (Stefaan A. Eeckels)
Subject: Re: Qui sera assez fort pour repondre a ca ??
Message-Id: <6eqe5g$jt9$1@justus.ecc.lu>
In article <Pine.OSF.3.95.980318130659.23558C-100000@primal.ucdavis.edu>,
Jason Christian <jason@primal.ucdavis.edu> writes:
>
> C'est peut-etre vrai pour 'la majeure partie des "gurus" actifs,' mais
> c'est certainement faux pour le guru majeur, M. Tom Christiansen. Mais
> si tu lui ecrit dans une langue non-anglaise, il faut etre pret a lire sa
> reponse dans une bouillabaisse de ses langues non-anglaises.
>
> Heureusement il n'a pas sorti cette fois son suepanol (dialecte
> formidable de la famille ibero-scandinave).
But then, Tom is not only a Perl guru, he's one of those
polymaths that prove that the rest of us only use about
10% of our 'little grey cells'. Somehow it seems fitting
that Perl (designed by a linguist) begot Tom as its
figurehead ;-)
--
Stefaan
--
PGP key available from PGP key servers (http://www.pgp.net/pgpnet/)
___________________________________________________________________
"Don't worry about people stealing your ideas. If your ideas
are any good, you'll have to ram them down people's throats."
-- Howard Aiken
------------------------------
Date: Thu, 19 Mar 1998 06:09:44 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: regexp question -- making $replacestring = '$1' work
Message-Id: <3510a898.524144494f47414741@radiogaga.harz.de>
Charles Herold (cherold@pathfinder.com) wrote:
: I have a script that reads a search and replace string from a text file.
: The text file is like this:
: this, that(.*?)the other
: $1
: After opening the text file, the script does this:
: $search = <INPUT>;
: $replace = <INPUT>;
: Obviously what I want is for
: test = "this, that and the other";
: test =~ s/$search/$replace/;
: to result in test containing " and ", but what it actually contains is "$1".
Besides chomp()ing $search and $replace, and using '$test' instead of
'test', adding /ee options to the s/// does the job.
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
Ceterum censeo | work: mv@pdv-systeme.de
Redmondem delendam esse. | http://www.pdv-systeme.de/users/martinv/
| home: martin@radiogaga.harz.de
------------------------------
Date: 19 Mar 1998 02:27:49 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: removing everything between < and >
Message-Id: <6epvr5$gh2$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, j.kiser@ix.netcom.com writes:
:$line =~ s/<.+?>//g;
$line = 'This <IMG SRC="/path" ALT="> "> is bad for you.';
or even
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"
-- This is an annoying comment > --
>
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
echo "ICK, NOTHING WORKED!!! You may have to diddle the includes.";;
--Larry Wall in Configure from the perl distribution
------------------------------
Date: 19 Mar 1998 04:46:31 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: removing everything between < and >
Message-Id: <6eq7v7$e7v$1@client3.news.psi.net>
Jeffee Kiser (j.kiser@ix.netcom.com) wrote on MDCLXI September MCMXCIII
in <URL: news:35107A04.1B4C@ix.netcom.com>:
++
++ Another solution without using the HTML::Parse package approach would be
++ to change your search and replace statement to this:
++
++ $line =~ s/<.+?>//g;
Even Mosai^H^H^H^H^HNetscape parses better nowadays.
Some cases where your approach fails:
<IMG SRC = "foo.gif" ALT = "A > B">
<!-- <A comment> -->
<script>if (a<b && a>c)</script>
<IMG SRC = "foo.gif"
ALT = "Flurp!">
<# Just data #>
<![INCLUDE [CDATA [ >>>>>>>>>>>> ]]>
Abigail
--
perl -we '%_ = map {local $_ = $_; y/a-z/n-za-m/; ($_, $_)} @_ = map {lc} <>;
print grep {$_{$_}} @_' < /usr/dict/words
------------------------------
Date: 19 Mar 1998 04:13:57 GMT
From: gt6161c@acmez.gatech.edu (Christopher Ryan Sidi)
Subject: same ndbm dbs on both hpux 9.05 and 10.20?
Message-Id: <6eq625$sv1@catapult.gatech.edu>
Can I use the same ndbm databases (*.pag and *.dir) on hpux 9.05 and 10.20
machines with perl5? I believe it's the same cross-mounted partition; no
ftpping is involved.
If I can't, would converting over to BSD-DB work on both?
I've searched everything, including the HPUX10.20 transition website
(http://software.external.hp.com/OS_transition/UNDRSTND.HTM) and can't
find anything confirming or denying that I can do this. I've done several
tests (mostly reading and printing from perl5 on hpux9, and perl5 on
hpux10.20 and diffing the results) that suggest I can but I want to be
sure. I can't afford to have my db silently corrupted. (We're moving to
oracle soon, but must move to 10.20 first).
Thanks,
Chris
--
gt6161c@prism.gatech.edu
No Anti-Spam address 'cause I bet there are 12 year old kids correcting
people's email addresses for less than a dollar a day.
------------------------------
Date: Wed, 18 Mar 1998 21:02:15 -0500
From: Rick Delaney <rick.delaney@shaw.wave.ca>
To: Matthew Cravit <mcravit@shell3.ba.best.com>
Subject: Re: Splitting a string to make keys to a hash
Message-Id: <35107CA7.408F9EC7@shaw.wave.ca>
Matthew Cravit wrote:
>
> I'm trying to split a string, and use the elements of the split as keys
> to a hash. That is, if I have, for example, the string
>
> "foo:bar:baz=99"
>
> I'd like $SomeHash{foo}{bar}{baz} to be 99. The number of components in
> the string will vary; otherwise this would be fairly trivial. There could
> (at present) be as few as one and as many as 6 or 7 components before the
> equals sign.
>
> Can anyone suggest an elegant way of handling this?
>
I think this will work (it does for the case presented), but I've screwed
up references before. Re-read perlref. I'm going to (again).
@items = split /[:=]/, 'foo:bar:baz=99';
$val = pop @items;
$key = shift @items;
for (reverse @items) {
$val = {$_ => $val};
}
$SomeHash{$key} = $val;
print "$SomeHash{foo}{bar}{baz}\n";
HTH
--
Rick
------------------------------
Date: 19 Mar 98 04:27:52 GMT
From: mikeh@minivend.com (Mike Heins)
Subject: Re: Splitting a string to make keys to a hash
Message-Id: <35109ec8.0@news.one.net>
Rick Delaney <rick.delaney@shaw.wave.ca> wrote:
> Matthew Cravit wrote:
>>
>> I'm trying to split a string, and use the elements of the split as keys
>> to a hash. That is, if I have, for example, the string
>>
>> "foo:bar:baz=99"
>>
>> I'd like $SomeHash{foo}{bar}{baz} to be 99. The number of components in
>> the string will vary; otherwise this would be fairly trivial. There could
>> (at present) be as few as one and as many as 6 or 7 components before the
>> equals sign.
>>
>> Can anyone suggest an elegant way of handling this?
>>
> I think this will work (it does for the case presented), but I've screwed
> up references before. Re-read perlref. I'm going to (again).
> @items = split /[:=]/, 'foo:bar:baz=99';
> $val = pop @items;
> $key = shift @items;
> for (reverse @items) {
> $val = {$_ => $val};
> }
> $SomeHash{$key} = $val;
> print "$SomeHash{foo}{bar}{baz}\n";
I think this would work fine but you could only ever set one key
per top-level key.
A simple way is to use Perl.
#!/usr/bin/perl -w
use Safe;
$safe = new Safe;
%SomeHash = ();
$safe->share('%SomeHash');
$hashname = "SomeHash";
while(<DATA>) {
chomp;
@items = split /[:=]/, $_;
$val = pop @items;
$varname = '$' .
$hashname .
'{' .
(join "}{", @items) .
'}' ;
$code = <<EOF;
if(ref $varname) {
die "Attempted overwrite of hash";
}
$varname = $val;
EOF
;
$safe->reval($code);
if($@) {
warn "Hash key set failed:\n\n$code\n\nError:$@\n";
}
}
# This is only to print the results if you have Data::Dumper
use Data::Dumper;
$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 3;
print Dumper(\%SomeHash);
__END__
foo:bar:baz=99
foo:bar=98
foo:baz=97
Using the Safe module protects you against config file errors,
but %SomeHash must not be lexical as you cannot share it then.
You could obviously use eval instead.
If you need something more efficient, then you will have to
keep track of the keys yourself -- but trying to decide whether
a set is valid will be a bit of a nightmare.
--
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
There ain't nothin' in this world 131 Willow Lane, Floor 2 | || _ \
that's worth being a snot over. Oxford, OH 45056 | || |_) |
--Larry Wall <mikeh@minivend.com> |___| _ <
513.523.7621 FAX 7501 |_| \_\
------------------------------
Date: Thu, 19 Mar 1998 01:00:28 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Trimming a Variable
Message-Id: <3510B47E.A878D120@coos.dartmouth.edu>
Jonathan Stowe wrote:
>
> On Sat, 14 Mar 1998 12:01:53 -0500, Ronald J Kimball
> <rjk@coos.dartmouth.edu> wrote:
>
> >payne.jim@hq.navy.mil wrote:
> >>
> >> I want to only get 3 characters of a variable. Can anybody tell me how I can
> >> do this.
> >
> >That depends which three characters you want to get.
> >
> >Have you tried using substr()?
> >
>
> Or alternatively something like
>
> $variable =~ /^(.{1,3})/;
>
> $variable_with_no_more than_3_characters = $1;
>
> to get up to three from the beginning. You could likewise anchor to
> the end ($) of the string to get the last three characters.
I would strongly advise against using regexes for this task.
(BTW, you forgot to account for newlines in the string)
use Benchmark;
$str = "abcdefghijklmnopqrstuvwxyz";
timethese(20000, {
Substr => '$three = substr($str, 0, 3);',
Regex => '($three) = $str =~ /^(.{1,3})/s;',
});
timethese(20000, {
Substr => '$three = substr($str, -3) || $str;',
# if $str is less than 3 chars, substr will return undef
Regex => '($three) = $str =~ /(.{1,3})\Z(?!\n)/s;',
# if there's a newline, force it into $1
});
Benchmark: timing 20000 iterations of Regex, Substr...
Regex: 8 secs ( 3.77 usr 0.02 sys = 3.78 cpu)
Substr: 1 secs ( 0.65 usr 0.00 sys = 0.65 cpu)
Benchmark: timing 20000 iterations of Regex, Substr...
Regex: 34 secs (16.28 usr 0.10 sys = 16.38 cpu)
Substr: 2 secs ( 0.57 usr 0.00 sys = 0.57 cpu)
substr() is so much faster than a regex.
--
_ / ' _ / - 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: Thu, 19 Mar 1998 06:23:39 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Troubles "perl"ifying a shellscript that uses pipes
Message-Id: <3510abdb.524144494f47414741@radiogaga.harz.de>
Jonathan Rich (rich@polar.earth.nwu.edu) wrote:
: $n=5;
: system("echo This line has $n words | cat");
: This will work. Now suppose I want to interpolate in the value, $n+1.
: I try:
: system("echo This line has $n+1 words | cat");
: This doesn't work because of the quotes which prevent perl from doing
: the math I want.
See perlfaq4, "How do I expand function calls in a string?":
system("echo This line has ${\($n+1)} words | cat");
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
Ceterum censeo | work: mv@pdv-systeme.de
Redmondem delendam esse. | http://www.pdv-systeme.de/users/martinv/
| home: martin@radiogaga.harz.de
------------------------------
Date: 19 Mar 1998 04:37:59 GMT
From: dalonso@u.washington.edu (Darwin O.V. Alonso)
Subject: unpack loops
Message-Id: <6eq7f7$11qe$1@nntp6.u.washington.edu>
I am unpacking a "$record" containing a4 strings and signed
short variables.
To load an array, @num, with the $nat signed-shorts:
#1
@num = unpack("x$nsk s$nat", "$record"); $nsk += 2*$nat;
To load an array, @nam, with the $nat strings:
#2
for $i ( 0 .. $nat-1){
@t = unpack("x$nsk a4", "$record"); push(@nam,$t[0]); $nsk += 4;
}
( $nat = 1244)
Can #2 be made more concise, i.e. more like #1.
Thanks
Darwin
------------------------------
Date: 18 Mar 1998 22:11:38 -0500
From: Uri Guttman <uri@sysarch.com>
To: Zenin <zenin@archive.rhps.org>
Subject: Re: Using perl code as a config file syntax? (Or, can require return more then one value?)
Message-Id: <x7iupbidcl.fsf@sysarch.com>
Zenin <zenin@archive.rhps.org> writes:
> I'm trying to use a perl file as a config file. The file would look
> something like this:
>
> (
> FOO => [ 'some', 'foo', 'options' ],
> BAR => [ 'some', 'bar', 'options' ],
> );
>
> And be read with simply:
>
> my %config = require 'some.config';
why not do something like this:
my %config =
(
FOO => [ 'some', 'foo', 'options' ],
BAR => [ 'some', 'bar', 'options' ],
);
1 ; # needed to return true to require
And be read with simply:
require 'some.config';
the only problem is you can't set which var is being set in the main
file. it is in the required file only.
hth,
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---- 8 Years of Perl Experience, Available Immediately
uri@sysarch.com --------- Resume and Perl Example at http://www.sysarch.com
Use the Best Search Engine on the Net -------- http://www.northernlight.com
------------------------------
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 2132
**************************************