[12002] in Perl-Users-Digest
Perl-Users Digest, Issue: 5602 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 7 23:07:18 1999
Date: Fri, 7 May 99 20:00:20 -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 Fri, 7 May 1999 Volume: 8 Number: 5602
Today's topics:
Re: ?= Faster??? <devans@radius-retail.kom>
Re: About perlre... <devans@radius-retail.kom>
Re: Adding nonexistent functions to symbol table (Larry Rosler)
Re: Adding nonexistent functions to symbol table (Andrew Allen)
Re: aliasing hash elements <devans@radius-retail.kom>
Re: aliasing hash elements (Charles DeRykus)
Re: Always running (Rich Mulvey)
Authentication <netboy@bluedevil.org>
control-character vars... (Andrew Allen)
Copying Multidimensional Arrays <jasonl@rand.org>
Re: EXE file from a PERL <devans@radius-retail.kom>
Re: Find all files regardless of extension (Larry Rosler)
Re: Find all files regardless of extension <devans@radius-retail.kom>
Re: HASH references... <uri@sysarch.com>
How do I continue a line with a tr argument? <whm10@amdahl.com>
Re: How do I practice scripts? <devans@radius-retail.kom>
Re: How process a file? <devans@radius-retail.kom>
Re: ISO random sentence parser (like spew) (Randal L. Schwartz)
Re: multi-dimensional arrays <ebohlman@netcom.com>
Re: multi-dimensional arrays (Andrew Allen)
Re: multi-dimensional arrays (Larry Rosler)
Re: multi-dimensional arrays <design@raincloud-studios.com>
Re: Q on www.extropia.com cart <design@raincloud-studios.com>
Re: UNIX comands and switches in perl <devans@radius-retail.kom>
Re: UNIX comands and switches in perl <devans@radius-retail.kom>
Re: Weird problem with perl 5.003, Solaris 2.6 and VXFS (Jeffrey Keith Boulier)
Re: Why my? <uri@sysarch.com>
Re: Why my? (Benjamin Franz)
Re: Why my? (Kevin Reid)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 7 May 1999 16:53:19 +0100
From: "Dave Evans" <devans@radius-retail.kom>
Subject: Re: ?= Faster???
Message-Id: <7gv5bv$29221465@news.gomontana.com>
?= is for look-ahead, which tests the truth or otherwise of the next section
of the pattern. It has nothing to do with making the operation faster.
e.g.
#!/usr/bin/perl -w
$string="Match either this, or this.";
$string =~ /this/;
print "\$`=\"$`\"\n\$&=\"$&\"\n\$'=\"$'\"\n\n";
$string =~ /this\./;
print "\$`=\"$`\"\n\$&=\"$&\"\n\$'=\"$'\"\n\n";
$string =~ /this(?=\.)/;
print "\$`=\"$`\"\n\$&=\"$&\"\n\$'=\"$'\"\n\n";
$`="Match either "
$&="this"
$'=", or this."
$`="Match either this, or "
$&="this."
$'=""
$`="Match either this, or "
$&="this"
$'="."
The important difference is that when matching using /\./, the dot is
included in the matched text ($&).
However when it is part of the look-ahead /(?=\.)/ the match is checked
(i.e. the full stop had to be there), but it is not included in the matched
text ($&).
Make any sense?
gaving@my-dejanews.com wrote in message <7gsnjh$c7o$1@nnrp1.deja.com>...
>Hi, Well Im not exactly a perl newbie, but am quite baffled by something.
> i was reading through my reg expression book and noticed an interesting
tag.
> ?= Its for read ahead. So for shits and giggles I have it scan a 50000
blah blah blah
------------------------------
Date: Fri, 7 May 1999 15:48:21 +0100
From: "Dave Evans" <devans@radius-retail.kom>
Subject: Re: About perlre...
Message-Id: <7gv1hv$28ol3@news.gomontana.com>
I'm not quite clear what you are trying to achieve. Could you give some
more, clearer examples perhaps?
e.g.
Input: "This123is45 my34 input 22data"
Output: whatever you need the output to be. List each element of the list,
if you require a list as the result.
Federico Abascal wrote in message <3732BF38.1DCA91F8@gredos.cnb.uam.es>...
>Hello,
>I'm trying to learn about the perl regular expressions. Do you know how
>to break a string into tokens of letters and numbers.
>For example:
>"hello34 5hola 222 que tal3 ar22e you"
>in hello 34 5 hola 222 que tal 3 ar 22 e you
>or:
>"555 adios by45e"
>in 555 adios by 45 e.
>If it starts with numbers, /(\d+)(\D+)/g works ok. But if sometimes
>starts with letters, how to do?
>Thanks in advance,
>Fede
>
------------------------------
Date: Fri, 7 May 1999 17:36:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Adding nonexistent functions to symbol table
Message-Id: <MPG.119d26e0808948db989a09@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <37337D11.4979219E@one.net> on Fri, 07 May 1999 19:53:53 -
0400, Ben <neb@one.net> says...
> I have the code for a function in a scalar is there anyway to put
> this code in the current symbol table so I can use it like a normal
> function? Please email me at neb@one.net.
#!/usr/local/bin/perl -w
use strict;
my $code = 'sub foo { print "Hello, world!\n" }';
eval $code;
foo();
__END__
Add safety and error checks on the eval to make this a good program.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 8 May 1999 00:25:16 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Adding nonexistent functions to symbol table
Message-Id: <7h009c$f8h$3@fcnews.fc.hp.com>
Ben (neb@one.net) wrote:
: I have the code for a function in a scalar is there anyway to put
: this code in the current symbol table so I can use it like a normal
: function? Please email me at neb@one.net.
A colorful example from 'perldoc perlref':
The red() and green() functions would be very similar. To create
these, we'll assign a closure to a typeglob of the name of the
function we're trying to build.
@colors = qw(red blue green yellow orange purple violet);
for my $name (@colors) {
no strict 'refs'; # allow symbol table manipulation
*$name = *{uc $name} = sub { "<FONT COLOR='$name'>@_</FONT>" };
}
Andrew
------------------------------
Date: Fri, 7 May 1999 16:57:35 +0100
From: "Dave Evans" <devans@radius-retail.kom>
Subject: Re: aliasing hash elements
Message-Id: <7gv5jq$28tl1466@news.gomontana.com>
[mailed+posted]
Well if the values of the hash are references then just copy the reference,
and the thingy referenced will be the same.
If the values are not references, then, err, no ideas sorry. afaik it can't
be done.
RayG wrote in message ...
>i am trying to alias one hash element to another, such as $hash{a} is an
>alias to $hash{b}. my first thought was *hash{a} = \$hash{b}, but that
>does not work. i also tried using the Alias module from CPAN with no luck.
>any other ideas?
>
>thanks
>
------------------------------
Date: Sat, 8 May 1999 02:04:15 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: aliasing hash elements
Message-Id: <FBE5r3.MwH@news.boeing.com>
In article <Pine.GSO.3.96.990506122241.15456B-100000@cliff.eb.com>,
RayG <rgoldber@eb.com> wrote:
>i am trying to alias one hash element to another, such as $hash{a} is an
>alias to $hash{b}. my first thought was *hash{a} = \$hash{b}, but that
>does not work. i also tried using the Alias module from CPAN with no luck.
>any other ideas?
>
>
package MyHash;
require Tie::Hash;
@ISA = (Tie::StdHash);
sub STORE {
my($self, $key, $value) = @_;
if ($key ne 'a') {
$self->{$key} = $value;
$self->{a} = $self->{b} if $key eq 'b';
}
}
package main;
tie %hash, 'MyHash';
...
untie %hash;
hth,
--
Charles DeRykus
------------------------------
Date: Sat, 08 May 1999 02:44:46 GMT
From: richm@ucesucks.rochester.rr.com (Rich Mulvey)
Subject: Re: Always running
Message-Id: <slrn7j7cq3.16b.richm@ll.aa2ys.ampr.org>
On Tue, 04 May 1999 20:16:48 GMT, Khan <dnkhan@my-dejanews.com> wrote:
>Hi,
> I have a perl script on a unix (solaris) box that is always checking if a
>certain file exists in a directory or not. Besides this , there are other
>things it does which might cause the script to terminate.
>
>How do i ensure in Perl that when this process dies for whatever reason, it
>always gets restarted ? ( somehow emulate the parent child forking concept )
>
Not that is is a Perl question....
man inittab
- Rich
--
Rich Mulvey
http://mulvey.dyndns.com
Amateur Radio: aa2ys@wb2wxq.#wny.ny.usa
------------------------------
Date: Fri, 7 May 1999 22:25:39 -0400
From: "Brett Croman" <netboy@bluedevil.org>
Subject: Authentication
Message-Id: <926130483.445737@nntpcache1.nortel.net>
Greetings...
I have a need to authenticate logins, through an HTML form, using my Linux
passwd system.
More specifically.. I want someone to give the form a name/passwd and have
the perl script running as that user henceforth. For file management, and
whatnot...
I know how to manipulate files (somewhat), and I actually have the script
written and running nicely: provided that all files to be tweaked are chmod
a+rwx, or chowned to 'nobody'. That is, to say the least, a security hole.
The system is RedHat Linux 5.1, running the latest Apache server. No shadow
passwords to fight with...
I'd be most gratefull for a good help file over this, or better yet, direct
help.
Thanks,
--Brett
------------------------------
Date: 8 May 1999 00:06:50 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: control-character vars...
Message-Id: <7gvv6q$f8h$1@fcnews.fc.hp.com>
Wow-- you learn something new every day...
perl5 -e '$a="^X"; $b="\cX"; print "$$a-$$b\n"'
produces
-perl5
Makes sense... especially if you want to discourage casual symbolic
references to built-in variables ;)
Andrew
------------------------------
Date: Fri, 07 May 1999 17:12:30 -0700
From: Jason Lingel <jasonl@rand.org>
Subject: Copying Multidimensional Arrays
Message-Id: <37338071.2D067C15@rand.org>
How do you copy all of the values, not the memory addresses, from one
(multidimensional) array to another (multidimensional) array?
The syntax for accessing the elements of this array is:
$DFArr[$index][$i]->{'Xlnch'} = $Xlnch;
$DFArr[$index][$i]->{'Ylnch'} = $Ylnch;
$DFArr[$index][$i]->{'PKss'} = $PKss;
etc.
This doesn't work:
@DFNew = @DFArr;
because that references the same memory addresses, and doesn't copy the
values to new memory addresses.
Is there any way to do this easily?
Thanks in advance.
--
Jason Lingel
Microcomputer Consultant
RAND
email: jasonl@rand.org
(310) 393-0411, ext. 7990
Please note: Chain emails will not be responded to.
------------------------------
Date: Fri, 7 May 1999 16:33:45 +0100
From: "Dave Evans" <devans@radius-retail.kom>
Subject: Re: EXE file from a PERL
Message-Id: <7gv47f$28rq1462@news.gomontana.com>
Looks like they pay well! :-)
blazek@sisblansko.cz wrote in message <7guvfd$b9p$1@nnrp1.deja.com>...
>Recently I sent a question about making exe file from Perl. Some of you
>helped me and I would like to thank you all. But I would also like to thank
>Indy Singh from http://www.perl2exe.com who have helped me a lot. They make
a
>great product perl2exe for converting Perl scripts to exe files At present
I
>am testing it and it seems to be very good.
------------------------------
Date: Fri, 7 May 1999 17:06:14 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Find all files regardless of extension
Message-Id: <MPG.119d1fd2853646b5989a07@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <37356e3a.15212467@news.skynet.be> on Fri, 07 May 1999
22:51:40 GMT, Bart Lateur <bart.lateur@skynet.be> says...
> Larry Rosler wrote:
> >> opendir DIR,$dirpath;
> >> @matches = grep { /^filename\./ } readdir(DIR);
> >> closedir(DIR);
> >
> > my $PoB = $dirpath =~ /^[a-z]:/i && '(?i)'; # or something :-)
> > @matches = grep { /$PoB^filename\./o } readdir(DIR);
>
> Nah... You seem to have overlooked the fact that readdir() returns the
> bare filenames (aka "basename"). /^filename\./ is fine.
Nah... You seem to have overlooked the fact that readdir() returns the
bare filenames with whatever case was used when they were written. So
'FiLeNaMe.tXt' and 'fIlEnAmE.TxT' are the same friggin' file.
The following works just fine on my PoB system. Don't try this on your
Unix system.
#!/usr/local/bin/perl -w
use strict;
sub make_file {
local *FH;
my $name = shift;
open FH, ">$name" or die "Can't open '$name'. $!\n";
print FH "Hello, world!\n";
}
sub read_file {
local *FH;
my $name = shift;
open FH, "<$name" or die "Can't open '$name'. $!\n";
print while <FH>;
}
my $dir = 'test';
mkdir $dir, 0777 or die "Can't make '$dir'. $!\n";
chdir $dir or die "Can't chdir '$dir'. $!\n";
make_file('FOO.TXT');
read_file('foo.txt');
make_file('bar.txt');
read_file('BAR.TXT');
opendir DIR, '.' or die "Can't open '.'. $!\n";
{ local ($,, $\) = ("\n", "\n");
print grep /(?i)\.txt/, sort readdir DIR }
closedir DIR;
unlink qw( foo.txt bar.txt );
chdir '..' or die "Can't chdir '..'. $!\n";
rmdir $dir or die "Can't rmdir '$dir'. $!\n";
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 7 May 1999 16:28:19 +0100
From: "Dave Evans" <devans@radius-retail.kom>
Subject: Re: Find all files regardless of extension
Message-Id: <7gv3t9$28ga1461@news.gomontana.com>
[mailed+posted]
I've had problems with glob on Win32 platforms, for what it's worth. I
think the problem didn't happen if the parameter to "glob" was in the short
"8.3" format. Using opendir/readdir/closedir was the answer, but the only
catch here is that readdir also returns the "." and ".." directory entries.
Jonathan Stowe wrote in message <3732fb9e@newsread3.dircon.co.uk>...
>I have heard some people saying that glob() doesnt work properly on NT
>if that is the case you might need to examine the functions:
>
> opendir()
> readdir()
> closedir()
------------------------------
Date: 07 May 1999 22:47:17 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: HASH references...
Message-Id: <x7d80ctgzu.fsf@home.sysarch.com>
>>>>> "FWM" == Fuzzy Warm Moogles <tgy@chocobo.org> writes:
FWM> On Fri, 07 May 1999 19:11:55 GMT, "Charles R. Thompson"
FWM> <design@raincloud-studios.com> wrote:
>>> %hash=qw/a 1 b 2 c 3 d 4 e 5/;
>>
>> I've never seen that before. Interesting.
FWM> (The other) Larry would like to see hash slices get more exposure:
FWM> @hash{'a'..'e'} = 1..5;
a more general idiom since you usually have an array of keys:
@keys = 'a' .. 'e' ;
@hash{ @keys } = 1 .. @keys ;
or for 0 basing:
@hash{ @keys } = 0 .. $#keys ;
or for just exist testing:
@hash{ @keys } = () ;
i have been saying for as long (maybe longer) than larry that hash
slices are your friend. i use them regularly in many contexts. the above
ones are just nice initialization techniques.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Fri, 07 May 1999 17:39:32 -0700
From: Hal Mounce <whm10@amdahl.com>
Subject: How do I continue a line with a tr argument?
Message-Id: <373387C4.F1D7E83D@amdahl.com>
My first perl program, and I've hit a snag.
I want to build a 256 entry translate table. I couldn't figure out how
to continue a line of code, and wound up with the mess at the bottom of
this script, which works, but isn't very clean. (The general case would
fail, you gotta do the translate in one fell swoop.)
Any tips? I suspect the same problem crops up with regexs.
#!p5 -w
# dmp [filename(s)] hex dumps files or stdin with character translation
# 01/20/99 whm10 initial coding
# this next bit sets up some formatting constatnts we'll need later
on...
# $spformat[n] is the format for a printf line of n bytes (usually n=16,
a full line)
$spformat[0] = "I am a bug: data length is zero.";
#never used
$spformat[1] = ('%2.2X') . (" " x 33); #1
byte of data
$spformat[2] = ('%2.2X' x 2) . (" " x 31); #2
bytes of data
$spformat[3] = ('%2.2X' x 3) . (" " x 29);
$spformat[4] = ('%2.2X' x 4) . (" " x 27);
$spformat[5] = ('%2.2X' x 4) . " " . ('%2.2X') . (" " x 24);
$spformat[6] = ('%2.2X' x 4) . " " . ('%2.2X' x 2) . (" " x 22);
$spformat[7] = ('%2.2X' x 4) . " " . ('%2.2X' x 3) . (" " x 20);
$spformat[8] = ((('%2.2X' x 4) . " ") x 2) . (" " x 17);
$spformat[9] = ((('%2.2X' x 4) . " ") x 2) . ('%2.2X') . (" " x
15);
$spformat[10] = ((('%2.2X' x 4) . " ") x 2) . ('%2.2X' x 2) . ("
" x 13);
$spformat[11] = ((('%2.2X' x 4) . " ") x 2) . ('%2.2X' x 3) . ("
" x 11);
$spformat[12] = ((('%2.2X' x 4) . " ") x 3) . (" " x 8);
$spformat[13] = ((('%2.2X' x 4) . " ") x 3) . ('%2.2X') . (" " x
6);
$spformat[14] = ((('%2.2X' x 4) . " ") x 3) . ('%2.2X' x 2) . ("
" x 4);
$spformat[15] = ((('%2.2X' x 4) . " ") x 3) . ('%2.2X' x 3) . ("
" x 2);
$spformat[16] = ((('%2.2X' x 4) . " ") x 3) . ('%2.2X' x 4);
@ARGV = ('-') unless @ARGV; #if no filename given
use STDIN
while($filename = shift(@ARGV)) { #process the next file
in the list
open(IN, $filename) or warn "Can't open $filename: errno is $!\n";
$offset = 0; #keep track of byte
offset into this file
# read the next 16 bytes, hex print them with offset, hex data, acsii
and ebcdic translation
# the last read may return less than 16 bytes, so the formatting gets
tricky
while ($len = read IN, $buf, 16) {
@dmpint = unpack "C${len}", $buf; #1 to 16 byte array of
integers 0-255
# create ascii and ebcdic translations (loose the scary bytes)
$dmpascii = $buf;
$dmpebcdic = $buf;
$dmpascii =~ tr/\x20-\x7e/./c; # change non printable bytes to
dots
# bad things happen if these next few lines get out of order; should
have done it byte by byte
$dmpebcdic =~
tr/\x00-\x3f\x41-\x4b\x51-\x59\x62-\x6a\x70-\x78/./; # dot out 00-7F
$dmpebcdic =~ tr/\x40\x4c-\x4e\x50\x5a-\x61/
<(+&!$*);.\x2d\x2f/; # trans thru 61
$dmpebcdic =~
tr/\x6b-\x6f\x79-\x7f/,%_>?`:#@'="/; # trans thru 7F
$dmpebcdic =~
tr/\x80\x8a-\x90\x9a-\xa0\xaa-\xbf\xca-\xcf/./; # dot out 80-D0
$dmpebcdic =~
tr/\x4f\xa1\xc0\xd0\xe0/|~{}\x5c/; # odds and ends
$dmpebcdic =~
tr/\x81-\x89\x91-\x99\xa2-\xa9/a-z/; # get a-z
$dmpebcdic =~
tr/\xc1-\xc9\xd1-\xd9\xe2-\xe9\xf0-\xf9/A-Z0-9/; # get A-Z, 0-9
$dmpebcdic =~
tr/\xda-\xdf\xe1\xea-\xef\xfa-\xff/./; # dot out D1-FF
printf "%8.8X $spformat[$len] %-16.16s %-16.16s\n",
$offset, @dmpint, $dmpascii, $dmpebcdic;
$offset = $offset + $len;
}
}
------------------------------
Date: Fri, 7 May 1999 16:45:19 +0100
From: "Dave Evans" <devans@radius-retail.kom>
Subject: Re: How do I practice scripts?
Message-Id: <7gv4sq$28ku1464@news.gomontana.com>
[mailed+posted]
Laurie Dunn wrote in message <7gspgm$ks3$1@gxsn.com>...
> My ISP will not let me store scripts.
Does that mean that your ISP will not let you run scripts [on their server]
either? 'Cos if not then there's no point practicing is there?
------------------------------
Date: Fri, 7 May 1999 16:10:08 +0100
From: "Dave Evans" <devans@radius-retail.kom>
Subject: Re: How process a file?
Message-Id: <7gv31o$28nd4@news.gomontana.com>
First read and digest Mr. Bohlman's reply, for it contains at least some
words of wisdom. :-)
As a concise way of searching for things you could also do:
# Read the entire file into @lines
open(FILE, "file.txt") or die "I couldn't open the file!: $!";
@lines=<FILE>;
close(FILE);
# Count the lines matching some pattern
$Buffer = "$NameP $SurnameP";
$EverPlay = grep /$Buffer/, @lines;
There's more ways to do it than these; however if you read and understand
everything that's going on in Mr Bohlman's and my examples, you'll be making
good progress.
dtillaud@hotmail.com wrote in message <7guesk$sk0$1@nnrp1.deja.com>...
>hello
>
>I'd like to open a file and to check if a string is into this file.
------------------------------
Date: 07 May 1999 18:12:57 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: ISO random sentence parser (like spew)
Message-Id: <m1g158tld2.fsf@halfdome.holdit.com>
>>>>> "Gee" == Gee Starr <geestarr@geedev.com> writes:
Gee> I'm looking for a perl script that uses recursive grammar techniques to
Gee> generate random sentences. I've found several scripts that will throw up a
Gee> string of text chosen from a pre-made list, but I'd really like to find
Gee> something that generates sentences on the fly.
Gee> I know there've been a few non-perl solutions like Spew and the
Gee> Dada Engine; what I'm looking for doesn't have to be that complex
Gee> -- Don Cross's Javascript implementation is along the scale I'm
Gee> thinking.
Gee> Anybody here know of something like that?
OK, I took a whack at it, and after some private correspondance
with Gee to get a sample grammar, came up with the following.
You'll need Parse::RecDescent from the CPAN.
#!/usr/bin/perl
$|++;
use Parse::RecDescent;
my $parser = Parse::RecDescent->new(<<'END_OF_GRAMMAR');
grammar: rule(s) /\Z/ { [ map { $_->[0], $_->[1] } @{$item[1]} ] }
rule: identifier ":" defn ";" { [ $item[1], $item[3] ] }
| <error>
defn: choice (barchoice)(s?) { [ $item[1], @{$item[2]} ] }
barchoice: "|" choice
choice: item(s)
item: quoted_string | identifier | <error>
quoted_string: /"(.*?)"/s { " ".substr($item[1],1,-1) }
identifier: /[A-Za-z_]\w*/
END_OF_GRAMMAR
(my $parsed = $parser->grammar(join '', <DATA>)) or die "bad parse";
my $top = $parsed->[0];
my %defns = @$parsed;
for (1..5) {
show($top);
print "\n----\n";
}
sub show {
my $defn = shift;
die "missing defn for $defn" unless exists $defns{$defn};
my @choices = @{$defns{$defn}};
for (@{$choices[rand @choices]}) {
## should be a list of ids or defns
die "huh $_ in $defn" if ref $defn;
if (/^ (.*)/s) {
print $1;
} elsif (/^(\w+)$/) {
show($1);
} else {
die "Can't show $_ in $defn\n";
}
}
}
__END__
stanza: stanza exclaim stanza2 | stanza2;
stanza2: sentence comparison question | sentence comparison | comparison
comparison exclaim | address question question sentence;
sentence: sentence sentence2 | sentence2;
sentence2: "The " adjectiveNotHep personNotHep verbRelating "the "
adjectiveHep personHep ". " | "The " personHep verbRelating "the "
adjectiveNotHep ", " adjectiveNotHep personNotHep ". ";
question: question question2 | question2;
question2: ques_start adjectiveHep personNotHep "? " | ques_start
adjectiveNotHep personHep "? ";
comparison: comparison comparison2 | comparison2;
comparison2: "One says '" compNotHep "' while the other says '" compHep
"'. "|
"One thinks '" compNotHep "' while the other thinks '" compHep "'. "|
"They shout '" compNotHep "!' And we shout'" compHep "'. "|
"It's " compNotHep " versus " compHep "! ";
personNotHep: "capitalist" | "silk purse man" | "square" | "banker" |
"Merchant King" | "pinstripe suit" ;
personHep: "cat" | "beat soul" | "wordsmith" | "hep cat" | "free man" |
"street poet" | "skin beater" | "reed man" ;
adjectiveNotHep: "soul-sucking" | "commercial" | "cash-counting" |
"bloody-handed" | "four-cornered" | "uncool" | "love-snuffing";
adjectiveHep: "love-drunk" | "cool, cool" | "happening" | "tuned-in" |
"street wise" | "wise and learned";
verbRelating: "begrudges" | "fears" | "distresses" | "dodges" |
"dislikes" | "evades" | "curses" | "belittles" | "avoids" | "battles";
compNotHep: "recreation" | "isolation" | "tranportation" | "sacred nation"
| "complication" | "subordination";
compHep: "fornication" | "instigation" | "interpretation" | "elevation"
| "animation" | "inebriation" | "true relation";
ques_start: "Could there ever be a "|"How could there be a "|
"Can you picture a ";
address: "Catch this: " | "Listen, cats, " | "Dig it: " |
"I lay this on you: ";
exclaim: "Heavy, man. "|"Heavy. " | "Yow! " | "Snap 'em for me. " |
"Dig it. ";
--
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: Sat, 8 May 1999 00:02:11 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: multi-dimensional arrays
Message-Id: <ebohlmanFBE03n.M5x@netcom.com>
Max Lee <maxlee@barley.cs.jhu.edu> wrote:
: After creating a multi-dimensional array -- let's say a 2-D array --
: what's the simplest way of traversing it element by element without
: knowing in advance the number of rows or columns in the array? I would
: like to do something to the effect:
: For a 2-D array "@arr"
: for $x (0..some_number) {
: for $y (0..some_other_number) {
: print $arr[$x][$y];
: }
: }
The key to what you want to do is remembering that a "2-D array" is
really an ordinary 1-D array of references (one per row) to other arrays
(whose elements are the columns). Therefore, you can just use two
foreach() loops:
foreach $row (@arr) {
foreach $col (@$row) {
print $col;
}
}
perldoc perllol to make things clearer.
------------------------------
Date: 8 May 1999 00:16:55 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: multi-dimensional arrays
Message-Id: <7gvvpn$f8h$2@fcnews.fc.hp.com>
Max Lee (maxlee@barley.cs.jhu.edu) wrote:
: After creating a multi-dimensional array -- let's say a 2-D array --
: what's the simplest way of traversing it element by element without
: knowing in advance the number of rows or columns in the array?
Hmmm.. I'd probably do:
@array=([1,2],[3,4,5]);
@ap1=map([map {$_+1} @$_],@array);
$\="\n"; $,=","; print @$_ foreach @ap1;
---
2,3
4,5,6
---
If you're stuck on indexing, you could probably do:
for($i=0;$i<@array;$i++) {
for($j=0;$j<@{$array[$i]};$j++) {
print $array[$i][$j]+1,",";
}
print "\b \n"; # ;)
}
but I think that's mostly for people who can't give up C ;)
Andrew
------------------------------
Date: Fri, 7 May 1999 17:25:47 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: multi-dimensional arrays
Message-Id: <MPG.119d24682de2ea4f989a08@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7gvtsc$8bh@foobar.cs.jhu.edu> on 7 May 1999 23:44:12 GMT,
Max Lee <maxlee@barley.cs.jhu.edu> says...
> After creating a multi-dimensional array -- let's say a 2-D array --
> what's the simplest way of traversing it element by element without
> knowing in advance the number of rows or columns in the array? I would
> like to do something to the effect:
>
> For a 2-D array "@arr"
>
> for $x (0..some_number) {
> for $y (0..some_other_number) {
> print $arr[$x][$y];
> }
> }
for my $x (0 .. $#arr) {
for my $y (0 .. $#{$arr[$x]}) {
print $arr[$x][$y];
}
}
> In my particular case, I'm reading data into a 2D array from a file. Each
> element on a line (column) is separated by whitespace and each line
> constitutes a row of an array -- with each line and the number of
> lines in the file being of indeterminate length. Of course, I can
> determine the number of lines and elements per line while reading the
> file, but it seems a little awkward doing so, when with one-dimensional
> arrays, I can simply do a "foreach" statement or a "for ($x = 0; $x <
> @arr_1d; $x++)".
Just like above:
for (my $y = 0; $y < @{arr[$x]}; $y++) { ... }
But all this makes it look as though you are writing C, not Perl.
Functions such as map() make writing these loops unnecessary (and they
are slow because of all the index munging).
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 08 May 1999 00:56:46 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: multi-dimensional arrays
Message-Id: <iZLY2.778$vP2.138@news.rdc1.tn.home.com>
>After creating a multi-dimensional array -- let's say a 2-D array --
>what's the simplest way of traversing it element by element without
>knowing in advance the number of rows or columns in the array?
>arrays, I can simply do a "foreach" statement or a
>"for ($x = 0; $x < >@arr_1d; $x++)".
umm.. gosh that looks too much like C.
Try here for/foreach...
http://language.perl.com/newdocs/pod/perlfaq4.html
How do I process/modify each element of an array?
CT
------------------------------
Date: Sat, 08 May 1999 01:09:08 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: Q on www.extropia.com cart
Message-Id: <U8MY2.830$vP2.178@news.rdc1.tn.home.com>
>Anyone with experience with the shopping cart at www.extropia.com?
Holy eggplant. They are in Perl, they only *look* like spaghetti C code.
Those scripts may work (yeah.. I used um once), but they are a lonnnnngggg way
from optimal. Place printout of scripts on left. Camel book on right, and you
will have a wonderful learning experience ahead.
CT
------------------------------
Date: Fri, 7 May 1999 15:51:40 +0100
From: "Dave Evans" <devans@radius-retail.kom>
Subject: Re: UNIX comands and switches in perl
Message-Id: <7gv1o5$28ju1460@news.gomontana.com>
See the perlre documentation. Look up the "i" modifier (it's right at the
top of the page in my copy).
e.g. /pattern/i
Jerry Raynor @yahoo.com> wrote in message
<926088104.992.101@news.remarQ.com>...
>I'm trying to do a search using the grep command (which does case-sensitive
>searches) with the (-i) it would return all matches regardles of case. I'm
>just not sure how to format it.
------------------------------
Date: Fri, 7 May 1999 16:37:01 +0100
From: "Dave Evans" <devans@radius-retail.kom>
Subject: Re: UNIX comands and switches in perl
Message-Id: <7gv4eb$28p71463@news.gomontana.com>
[mailed+posted]
What Mr Bohlman means is that the pattern match operator ( /something/ ) can
be made to operate without respect to case. See the "perlre" man page for
the "/i" modifier. Alternatively passing *both* strings through lc() would
work, but be far less efficient.
Jerry Raynor @yahoo.com> wrote in message
<926090436.185.19@news.remarQ.com>...
>@data is a database of postings from users in various CaSe, other users are
>searching from a web page $searchstr also using various cAsE. Controling
>$searchstr using lc($searchstr) isn't going to help if that what you mean?
>
------------------------------
Date: 7 May 1999 20:41:49 -0400
From: jeffreyb@gwis2.circ.gwu.edu (Jeffrey Keith Boulier)
Subject: Re: Weird problem with perl 5.003, Solaris 2.6 and VXFS
Message-Id: <7h018d$d1i@gwis2.circ.gwu.edu>
In article <dkcombsFApwrG.E84@netcom.com>,
David Combs <dkcombs@netcom.com> wrote:
>> [a perl program runs faster after it has been copied. Reason: it is cached
>> in the memory.]
>
>Does this happen with everyone running 2.6?
>
>How about 2.7?
Sure. Sun says "free memory is wasted memory". Any memory not explicitly being in
use, Solaris will reserve as a disk cache. I can't remember back to the time when
Sun didn't do this. For that matter, pretty much any OS worth considering will cache
recently-accessed files or programs.
>(I am running 2.5.1, am thinking of switching to -- which
>one (if any) should it be?
Well, if you switch you probably should switch to Solaris 7, assuming your software
support people don't tell you otherwise. Sun did a reasonably good job with that
release, outside of the 'man' command being horribly slothful on the already-slow
sun4c and sun4m machines.
Yours Truly,
Jeff Boulier
--
Senior Systems Programmer
George Washington University / SCT Inc.
------------------------------
Date: 07 May 1999 22:37:52 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Why my?
Message-Id: <x7g158thfj.fsf@home.sysarch.com>
>>>>> "ETR" == Eric The Read <emschwar@rmi.net> writes:
ETR> I think I'll go home and write out "I will NOT use commas in qw lists"
ETR> 1000 times, or something. Sheesh.
print 'I will NOT use commas in qw lists' x 1000 ;
remember, one of the attributes of a good perl hacker is laziness!
:-)
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Sat, 08 May 1999 02:55:19 GMT
From: snowhare@long-lake.nihongo.org (Benjamin Franz)
Subject: Re: Why my?
Message-Id: <rINY2.10599$ny.834658@typhoon-sf.snfc21.pbi.net>
In article <xkfn1zgjxym.fsf@valdemar.col.hp.com>,
Eric The Read <emschwar@rmi.net> wrote:
>"Charles R. Thompson" <design@raincloud-studios.com> writes:
>> >I think I'll go home and write out "I will NOT use commas in qw lists"
>> >1000 times, or something. Sheesh.
>>
>> You'll just end up doing it with a loop. Admit it! :)
>
>No, I'll do it the hard way-- cut and pase. ;-)
That's hardly an improvement. You can do it in only 56 keystrokes
that way in most word processors.
--
Benjamin Franzy
------------------------------
Date: Fri, 7 May 1999 22:56:46 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Why my?
Message-Id: <1drgfav.1qnwje5eujab6N@[192.168.0.1]>
Eric The Read <emschwar@rmi.net> wrote:
> Duh, I always do that. -w always catches it for me, but it seems like
> nearly every time I use qw, I end up putting commas in between the
> items. This is why I always use -w and use strict. :)
I wish there was a way to turn off the warnings about , and # in qw(),
because sometimes I DO want to put those characters in the list.
--
Kevin Reid: | Macintosh:
"I'm me." | Think different.
$str = q<"\$str = q<$str>; print eval \$str;\n">; print eval $str;
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5602
**************************************