[11543] in Perl-Users-Digest
Perl-Users Digest, Issue: 5142 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 15 20:07:24 1999
Date: Mon, 15 Mar 99 17:00:31 -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 Mon, 15 Mar 1999 Volume: 8 Number: 5142
Today's topics:
Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Pos (Remco Gerlich)
A perl equivalent to filec? (Nobody)
Re: Array lengths <aqumsieh@matrox.com>
Re: Complex Structure Question <aqumsieh@matrox.com>
Re: deleting an array of words from a string (George)
Re: Deleting the rest of the line... <juex@my-dejanews.com>
Re: Detecting a whitespace at the end of a string (Tad McClellan)
Exact match, but Insensitive <debot@xs4all.nl>
Re: Finding end of line (George)
Re: Finding end of line <jglascoe@giss.nasa.gov>
Re: hashes ???????? <cassell@mail.cor.epa.gov>
Heavy-duty reference use in database code (Sean McAfee)
Re: Help: Conditional use of packages in Perl (Tad McClellan)
Re: How do you create an mSQL database... (John Stanley)
Re: inv. cos <cassell@mail.cor.epa.gov>
Re: liars vs. non-liars (was Re: does perl discourage o (Randal L. Schwartz)
Re: Memory management & Perl to C extensions (Ilya Zakharevich)
Re: need better way to print external file withen perl <syt@email*@sp\am|@|spa/m@*.com>
Re: Need Faster Approach (Randal L. Schwartz)
Re: Need Faster Approach <jglascoe@giss.nasa.gov>
Network Traffic Monitor <scott.ranzal@mci.com>
Re: newbie question <cassell@mail.cor.epa.gov>
Re: NewbieQ: if ($dbhost && $dbname !~ m%[/@]%); (Tad McClellan)
Re: Passing Multiple Variables to a Sub (George)
Re: perl and y2k (was Re: The millennium cometh -- even <cassell@mail.cor.epa.gov>
Re: Please can we stop this PIII thread RIGHT HERE? As (James Stevenson)
Reading Directory <ps96@ecs.soton.ac.uk>
Re: Reading Directory <msholund@bigfoot.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Mar 1999 23:59:50 GMT
From: scarblac-spamtrap@pino.selwerd.cx (Remco Gerlich)
Subject: Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Posted Twice Weekly ***
Message-Id: <slrn7er7nf.78h.scarblac-spamtrap@flits104-37.flits.rug.nl>
jeff@axismutatis.net <jeff@axismutatis.net> wrote:
>Abigail wrote:
>> Your time is more important than other people time?
>
>If your time is so damned precious, perhaps you should leave this newsgroup?
>
FYI, this is the way I study Perl: I read Learning Perl, I read
all the FAQs, I lookup the docs on things I may want to use,
and _I read every single post Abigail puts in clpm_.
That's all I read in clpm, usually. I only saw your post because
Abigail replied to it. You can lurk for another year now.
--
Remco Gerlich scarblac (a) pino.selwerd.cx
Mail to my From: address is scanned briefly once a week.
The reply-to alias works without change, it is an alias
to check if spam mail is using the Reply-to: header.
------------------------------
Date: 15 Mar 1999 23:32:08 GMT
From: nobody@dewpoint.eng.sun.com (Nobody)
Subject: A perl equivalent to filec?
Message-Id: <7ck59o$kkf$1@engnews2.Eng.Sun.COM>
I want to write a perl script which accesses a name database. To facilitate
entering data about a person, I want to be able to hit the ESC key and have
it expand out as if using the "set filec" in .cshrc. It should search through
the database for possible names, fill out as much as possible, and continued
engagement of the ESC key should go down alphabetical order of possible
names.
Example: I type in "Sm" in the field, hit the ESC key and it will fill
out to Smith and then subsequent engagement of the ESC key gives me:
Smith, A
Smith, Ann
Smith, Arnold
Smith, B
Smith, Bill
Smith, Bob
Smith, Br
Smith, Brian
Smith, Bruce
...
Any ideas how this is done? Is this a perl question or an OS (or shell)
question?
EDEW
------------------------------
Date: Mon, 15 Mar 1999 22:58:55 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: Array lengths
Message-Id: <7ck3b9$nfg$1@nnrp1.dejanews.com>
In article <36EB08FB.DC1F54B@dowebpages.com>,
Bill Binkley <bwb@dowebpages.com> wrote:
> @ppw = ();
> @ppw[0]=();
You don't need to do that. It will generate a warning if you do.
> $ppw[0][0]="adm\/";
> $ppw[0][1]="adm.htm";
> $ppw[0][2]="detail.htm";
> $ppw[0][3]="help.htm";
> @ppw[1]=();
ditto.
> $ppw[1][0]="all\/";
>
> Length of @ppw can be obtained with $#ppw
Actually, $#ppw is the index of the last element of @ppw. Not the length.
> Is there a corresponding way to get the length of $#ppw[0] and
> $#ppw[1]
$length0 = scalar @{$ppw[0]};
$length1 = scalar @{$ppw[1]};
--Ala
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 12 Mar 1999 10:21:34 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Complex Structure Question
Message-Id: <x3ylnh2ensy.fsf@tigre.matrox.com>
lr@hpl.hp.com (Larry Rosler) writes:
> > Ala Qumsieh wrote:
> ...
> > > $data{$gate} = \@dests; # or = [@dests];
> > > $data{$gate}{$dest} = \@areas; # or = [@areas];
> > >
> > > Then, to access those arrays back, you need to dereference them:
> > >
> > > @dests = @{$data{$gate}};
> > > @areas = @{$data{$gate}{$dest}};
>
> There is great confusion here. The keys of %data are set up by the
> first store above to be references to arrays. The second store then
> treats them as references to hashes. The compiler complains "Can't
> coerce array into hash at ...".
I was seriously confused about this myself, but I tested it, and it
seems to work fine, although I don't know why. Look:
% perl -w
my %hash;
$hash{'a'} = 'a';
$hash{'a'}{'b'} = 'b';
print "$hash{'a'} and $hash{'a'}{'b'}.\n";
__END__
a and b.
But, under 'use strict' it complains:
Can't use string ("a") as a HASH ref while "strict refs" in use at - line 4.
IMHO, the behaviour (without use strict) is broken. The result should
be something like:
HASH(0xb851c) and b.
Is there a good explanation for this?
Ala
------------------------------
Date: Mon, 15 Mar 1999 19:16:20 -0500
From: fred222@mauimail.com (George)
Subject: Re: deleting an array of words from a string
Message-Id: <fred222-ya023580001503991916200001@news.bellatlantic.net>
> There are certain words that I would like to be taken out of a string
> as below:
> @ignore = (i, am, a);
> $string = "a boy am i";
> Currently, I'm using this simple (and wrong) method
> foreach (@ignore)
> {
> $string =~ s/^$_ //g;
> $string =~ s/ $_ //g;
> $string =~ s/ $_$//g;
> }
I do something like this, but killing the letters indiscriminatorily (i.e.
no "if its at the beginning" regular expressions..) - this ends up killing
some words in the middle of other words, i.e. "ass" might kill
"assumption", or a host of other words, which is irritating. Mine is to
kill bad words in jokes, and replace the killed words with a number of *'s
equal to the number of letters in the killed word. Although it's hardly
any different, and a little ugly, here's what I have:
foreach $badword_to_kill (@badword_array) {
$badword_replacement = $badword_to_kill;
$badword_replacement =~ s/[a-zA-Z0-9]/*/g;
$the_joke_array[5] =~ s/$badword_to_kill/$badword_replacement/ig;
$the_joke_array[8] =~ s/$badword_to_kill/$badword_replacement/ig;
}
@badword_array is an array of badwords, $the_joke_array[5] is the joke
text, and $the_joke_array[8] is the joke's title. The /ig ignores case and
allows the process to kill multiple copies of the badword, of course
(wouldn't be good if it only killed the first badword! ;-)
Hope this helps, (probably won't, oh well >;)
George (who is intoxicated with perl :)
yurtle@bellatlantic.net
--
Just another hacking head >l-d
------------------------------
Date: Mon, 15 Mar 1999 16:24:34 -0800
From: "J|rgen Exner" <juex@my-dejanews.com>
Subject: Re: Deleting the rest of the line...
Message-Id: <7ck87q$kae@news.dns.microsoft.com>
Jonathan Feinberg <jdf@pobox.com> wrote in message
news:m367858ovx.fsf@joshua.panix.com...
> "David Falconer" <webmaster@guestcities.com> writes:
>
> > So each time it comes across the word TRUCK it deletes all
> > characters after that for the rest of the line.
> >
> > I checked out the Perl FAQ, but it didnt seem to have quite what I am
after.
What's wrong with
s/TRUCK.*$/TRUCK/
You may want to add some checking to ensure, that the characters before and
after TRUCK are not letters or other word characters if you insist on TRUCK
being a stand-alone word.
BTW: this is one of the most trivial regular expressions and it has little
to do with Perl in the first place
jue
--
J|rgen Exner
------------------------------
Date: Mon, 15 Mar 1999 11:03:00 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Detecting a whitespace at the end of a string
Message-Id: <kvajc7.fu5.ln@magna.metronet.com>
kate_stafford@my-dejanews.com wrote:
: The program that is generating the group names sticks a whitespace
: or sometimes 2 at the end of the string that I wish to chop.
: I'm sure I'm missing something completly obvious, but I haven't been able to
: catch it yet.
As the Perl FAQs are fairly obvious, I believe that you are correct :-)
Perl FAQ, part 4:
"How do I strip blank space from the beginning/end of a string?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 16 Mar 1999 01:17:14 +0100
From: Frank de Bot <debot@xs4all.nl>
Subject: Exact match, but Insensitive
Message-Id: <36EDA30A.A5EDB2F1@xs4all.nl>
How can I search for an exact match, but insensitive.
I know you can compare strings on 2 ways:
if ($a eq "X") { } and ($a =~ /X/i) I the second case I can chose if
it must be capital sensitive or not. But I can't with the first one.
Example:
This is the Input : LITTLE . In the database is " little " (Lower
Case) . I don't want it "react" on Lit, but only Little or LITTLE or
LiTtLe .
------------------------------
Date: Mon, 15 Mar 1999 19:10:24 -0500
From: fred222@mauimail.com (George)
Subject: Re: Finding end of line
Message-Id: <fred222-ya023580001503991910240001@news.bellatlantic.net>
In article <7cjj51$84a$1@nnrp1.dejanews.com>, mmartina@my-dejanews.com wrote:
> I an trying to scan characters in one at a time using getc(). This is working
> but I an unable to determine when I hit the end of line character. I am
> running perl5 on a HP Unix machine. Any suggestions.
I could be horribly wrong, but I think the end-of-line "character" is
actually two characters (backslash-n, or "\n") and therefore going through
the text character by character wouldn't pick it out (it would only see a
single backslash, followed by a single n). You could do something where it
would store the last character found also, and then if it finds an 'n' it
would then check if the last one was a '\', and then know that it had found
a newline. Or you could just split the text by the default newlines with
the code:
@new_split_db = split(/\n/,$our_text);
and then do whatever you need to do with each cell of the array created.
Hope this helps, and hope I'm not entirely off base ;-) .. of course the
newline might be different, i.e. with Mac platforms it's like \012 or \015
or something like that :)
Cheers,
George
--
Just another hacking head >l-d
------------------------------
Date: Mon, 15 Mar 1999 19:40:33 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: George <fred222@mauimail.com>
Subject: Re: Finding end of line
Message-Id: <36EDA881.F7E19E71@giss.nasa.gov>
[courtesy copy of post sent to cited author]
George wrote:
>
> I could be horribly wrong, but I think the end-of-line "character" is
> actually two characters (backslash-n, or "\n") and therefore going through
ouch! You are indeed horribly wrong ;^)
The newline character, usually written "\n", is
a single character. It has ascii value 10.
perldoc -f chr
perldoc -f ord
print "foo\n" if chr 10 eq "\n";
print "bar\n" if 10 == ord "\n";
print 'length of "\n" is ', length("\n"), ".\n";
> Hope this helps, and hope I'm not entirely off base ;-) .. of course the
> newline might be different, i.e. with Mac platforms it's like \012 or \015
> or something like that :)
print "achoo!\n" if "\012" eq "\n";
Jay Glascoe
--
"Poit!"
--Pinky
------------------------------
Date: Mon, 15 Mar 1999 15:29:21 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: hashes ????????
Message-Id: <36ED97D0.54ADC73E@mail.cor.epa.gov>
pdz@barclab.com wrote:
> Can anyone explain how hashes works, and how to use them.
> Thanks
I don't think anyone can explain this any better than the pages
and pages of Perl docs already do. If you read through the
'perldata' man page (or type 'perldoc perldata' to read it), and
it still doesn't make sense, I suggest you get a copy of Randal
Schwartz's Learning Perl.
A hash is the kind of thingie you've used all your life, if you
think about it for a moment. A dictionary is like a hash: you have
key/value pairs (the word and the definition); you look up the
key to find the value. A library's reference catalogue is like
a hash. So is a cookbook. Just don't make a hash of looking up
a recipe for hash. :-)
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 16 Mar 1999 00:38:12 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Heavy-duty reference use in database code
Message-Id: <UJhH2.11626$Ge3.46115290@news.itd.umich.edu>
Yesterday I found myself writing some code that used more layers of references than
anything I'd done previously. It's odd-looking and yet strangely elegant, so I thought
I'd post it for comments or just to be gawked at.
My module accesses a database. To simplify making queries, I wrote the following
subroutine:
sub do_query {
my $sql = shift;
my $sth = prepare $dbh $sql; # $dbh is a global database handle
my ($row, @rows);
execute $sth;
push @rows, [ @$row ] while $row = fetch $sth;
\@rows;
}
This worked well, but eventually I found myself wanting to be able to group the result
set by one or more columns. For instance, if a table called TABLE looked like this:
FOO BAR BAZ
===============
1 2 3
1 0 0
2 4 7
2 4 9
3 9 8
...I wanted to group the query on the FOO column, producing a result set that looked
like this:
%result_set = (
"1" => [ [ 2, 3 ], [ 0, 0 ] ],
"2" => [ [ 4, 7 ], [ 4, 9 ] ],
"3" => [ [ 9, 8 ] ]
);
Ie, the keys of %result_set are all of the unique values of FOO, and the corresponding
values are arrays of the rows with that value of FOO, with the FOO value itself spliced
out (since FOO is the key, it would be redundant to leave it in).
Although less common, I also wanted to be able to group on multiple columns; for
instance, on both FOO and BAR in the above table:
%result_set = (
"1" => {
"2" => [ [ 3 ] ],
"0" => [ [ 0 ] ]
},
"2" => {
"4" => [ [ 7 ], [ 9 ] ]
},
"3" => {
"9" => [ [ 8 ] ]
}
);
Here's the algorithm I came up with:
my ($sql, @group) = @_; # @group is array of columns to group on, eg. qw(FOO BAR)
my $sth = prepare $dbh $sql;
if (@_ == 1) {
# do old non-grouping do_query
} else {
my ($x, $key, $row, $group $group2, @names, %index, %groups);
# First, some setup:
@names = @{$sth->{NAME}};
$index{$names[$_]} = $_ foreach 0 .. $#names;
# We need to adjust the indices of the grouping columns, since they'll be
# spliced out:
foreach $group (@group) {
foreach $group2 (@group) {
$index{$group2}-- if $index{$group2} > $index{$group};
}
}
# Now for the interesting part:
while ($row = fetch $sth) {
my @row = @$row;
$x = \\%groups;
foreach $group (@group) {
$key = splice @row, $index{$group}, 1;
$x = \$$x->{$key};
}
push @$$x, \@row;
}
return \%groups;
}
Autovivification creates all of the hashes and arrays! Sweet!
--
Sean McAfee mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!
------------------------------
Date: Mon, 15 Mar 1999 11:00:23 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Help: Conditional use of packages in Perl
Message-Id: <nqajc7.fu5.ln@magna.metronet.com>
edward@echarge.com wrote:
: I've got a strange problem that I hope somebody can help me with. I'm trying
: to find some way to conditionally include particular packages in Perl. I
: tried something like the following but it didn't work.
: if (condition is true)
: use package1;
: else
: use package2;
: It appears that Perl simply ignores the if statements and imports both
: packages regardless.
if() happens at runtime.
"use" happens at compile time.
ie. the "use" has already been done by the time perl evaluates the if().
: Please let me know if anyone has a solution.
Put the whole thing in a BEGIN block.
Or, do require/import like perlfunc says in the description for use.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 15 Mar 1999 23:49:36 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: How do you create an mSQL database...
Message-Id: <7ck6ag$9g9$1@news.NERO.NET>
In article <36EDE285.A5C0C2F9@kawo2.rwth-aachen.de>,
Alex Farber <alex@kawo2.rwth-aachen.de> wrote:
>Steve Swett wrote:
>> ....for use with Perl CGI scripts and the DBI module on a Unix server?
>> I've seen lots of documentation on how to Connect to a database, how to
>> create/update table, how to Disconnect, etc. -- but how do you initially
>> create the database?
>
>Well, I don't have mSQL, but I have MySQL, and it comes
>with a mysqladmin program. So if I call something like:
>
> system ( 'mysqladmin create test3' );
man msqladmin
or "msqladmin qwerty"
>it wiil create database "test3". I have yet to see a program
>that really needs to create a database (is table not enough?)
And where do you think tables live if not in a database?
------------------------------
Date: Mon, 15 Mar 1999 16:06:59 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: inv. cos
Message-Id: <36EDA0A3.788D0D77@mail.cor.epa.gov>
Jarkko Hietaniemi wrote:
> "David L. Cassell" <cassell@mail.cor.epa.gov> writes:
> > Didn't I mention Math::Trig? Hmm.. let's see what I said...
> > Nope. Oops. BTW, you might want to send a note to
> > perlfaq-suggestions so they add it into the FAQ. It's not in
> > there either (at least not in my copy).
>
> Consider upgrading, it's in there, in my copy which is Perl 5.005_02.
Love to. Plan to. I'm currently trying to convince the network
sysadmin to let me on the servers so I can... And since I'm not
part of the sysadmin group, it may take a while. I'm trying to
tantalize our boss with past issues of TPJ, and so... :-)
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 15 Mar 1999 15:06:04 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: liars vs. non-liars (was Re: does perl discourage obfuscated code?...)
Message-Id: <m14snmmjz7.fsf@halfdome.holdit.com>
>>>>> "Russell" == Russell Schulz <Russell_Schulz@locutus.ofB.ORG> writes:
Russell> merlyn@stonehenge.com (Randal L. Schwartz) writes:
>> More particularly, I don't call people "liars".
Russell> I asked Randal about this in mail, and his reply was that
Russell> although he said I was lying (and yes, you can see that in
Russell> Deja News), he doesn't think in doing so he called me a liar,
Russell> which he defined in his mail to be a brand new (to me anyway)
Russell> meaning of the word which didn't include saying I was lying.
Russell> well, I'm glad _that_ is cleared up. :-|
OK, just so you don't make me sound like a nut :), here's what I said
in private email:
I didn't call you a liar. I said that what you said are lies. That's
different (at least to me it is). You extrapolated that. :)
To me, a "liar" is someone that frequently, intentionally, knowingly
tells lies for malicious personal gain. So, it's more than just
telling lies, it's doing it with a purpose and consistency. For all I
know, you didn't know that I would view your statements as lies, so I
see no malice there. It's not a statement of character. It's an
assessment of mine about some things you said, not about you.
And you seem to have a habit of paraphrasing things to put stuff in
people's mouths. I suggest you stop that. And maybe I'm more
sensitive to it than most, because law enforcement officers
extra-contextually paraphrasing things I said made me look like a
criminal to a jury, and I'm not interested in repeating that.
print "Just another Perl hacker and convicted felon,"
--
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: 16 Mar 1999 00:07:41 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Memory management & Perl to C extensions
Message-Id: <7ck7cd$mg0$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Helena Jeeves
<hjeeves@us.ibm.com>],
who wrote in article <7cjpv2$p26$1@poknews.pok.ibm.com>:
> Devel::Peek doesn't tell me anything about the contents of
> a blessed object.
?!?!?!?! Devel::Peek reports all the info (sometimes more ;-) Perl
has about the value.
> It tells me what KIND of blessed object I
> have, but I haven't figured out how to get it to tell me
> anything else. I have to use the 'get' methods I wrote for my
> routine.
> As a further to this problem, I have cleaned up the variable
> usage considerable, I have ended up making all the extension
> structures/blessed objects in question global (which goes
> against my morals, but it's the only thing that runs
> consistently.) I found out early on that using any of these
> variables in a 'my' context meant their memory space was
> not repsected in the least,
?!?!?!?! Can you talk in adult terms, please?
> and that I lost more than half
> the data returned from the call to the C program.
C program? What are you talking about?
Lost? What are you talking about?
> env "PERLDB_OPTS=f=6 N" perl -d <routine call>
>
> then it dies on trying to access one of the extension structures.
Dies? What are you talking about?
Ilya
------------------------------
Date: Mon, 15 Mar 1999 17:29:15 -0600
From: "Jim" <syt@email*@sp\am|@|spa/m@*.com>
Subject: Re: need better way to print external file withen perl file
Message-Id: <7ck547$600$1@news3.infoave.net>
thanks much for the suggestion, however I like sami's last suggestion the
best, it's easier for me to understand, I like to understand everything I
do, I'm sure you do too.
--
Jim
----------------------------------------
Jay Glascoe <jglascoe@giss.nasa.gov> wrote in message
news:36ED8882.AFDA1492@giss.nasa.gov...
>[courtesy copy of post sent to cited author]
>
>Jim wrote:
><snip>
>> [...] Is there a better way to do this
>> similar to this:
>>
>> print <<__END__ ;
>> contents of text file recognized like they are here
>> __END__
>
>here's a possible solution, building on Sami's suggestion:
>
>no strict 'refs'; # turn off strict references
>while (<FILE>) {
> s/(^|[^\\])\$(\w+)/$1 . ${$2}/ge;
> s'\\\$'$';
> print;
>}
>use strict 'refs'; # turn 'em back on
>
>
>Or, you can do a "use/require/do" type thing:
>
>
>--- file "foo.pm" --------
>package foo;
>
>sub the_string {
> package main;
>my $string =<< "FOOZBALL";
>the value of \$biz is "$biz"
>and \@foo is "@foo"
>FOOZBALL
> return $string;
>}
>
>1;
>--------------------------
>#! /usr/local/bin/perl -w
>
>use strict;
>use vars qw(@foo $biz);
>
>@foo = qw(1 2 buckle my shoe);
>$biz = "3 4 close the door";
>
>use foo;
>
>print foo::the_string();
>--------------------------
>
> Jay Glascoe
>--
>"Just say 'Poit!'"
> --Pinky
------------------------------
Date: 15 Mar 1999 15:11:55 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Need Faster Approach
Message-Id: <m1zp5el550.fsf@halfdome.holdit.com>
>>>>> "frogsmock" == frogsmock <frogsmock@my-dejanews.com> writes:
frogsmock> Suppose a long comma-delimited string (say 100,000 items
frogsmock> for the sake of argument). Now suppose you want to grab 50
frogsmock> items from the middle of this string (like if you're
frogsmock> displaying search results 50 at a time). Does anyone out
frogsmock> there have a particularly speedy approach to this problem?
frogsmock> Right now I am reading all 100,000 items into an array by
frogsmock> using 'split' on the comma delimiter, then I'm using
frogsmock> 'splice' to grab my 50 result items into a "results" array.
Don't use splice. Just use an array slice. splice() needs to hack
the long array. Also look at the 3-arg split.
But the real question is.... why does this need to be fast? Are you
doing it repeatedly? If so, don't store the data that way!
print "Just another Perl hacker,"
--
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: Mon, 15 Mar 1999 18:50:13 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: frogsmock@my-dejanews.com
Subject: Re: Need Faster Approach
Message-Id: <36ED9CB5.36E6FC2E@giss.nasa.gov>
[courtesy coppy of post sent to cited author]
hi Jim,
frogsmock@my-dejanews.com wrote:
>
> Here's the way I see it: if I want, for example, records 75,000 - 75,050 out
> of 100,000, one obvious place to save time is by ignoring everything after
> 75,050 (but I don't know how to do that using my 'split' approach). However,
> what I'm hoping for is a faster way (impossible?) to get to the 75,000th item
> instead of splitting off each preceding item.
$string = join ",", (1..100000);
@foo = split /,/, $string, 75_051;
@biz = @foo[-50 .. -1];
print "@biz\n";
>
> Thanks!
I also thought about this nasty thing ;^)
$string = join ",", (1..100000);
$rev_string = reverse $string;
@biz = map { scalar reverse } (split /,/, $rev_string, 25_002)[reverse -51 .. -2];
It's funkier, but it's a lot slower than the other guy.
Jay Glascoe
--
"Narf!"
--Pinky
------------------------------
Date: Tue, 16 Mar 1999 00:38:10 GMT
From: "Scott Ranzal" <scott.ranzal@mci.com>
Subject: Network Traffic Monitor
Message-Id: <SJhH2.7546$oe3.66289@PM01NEWS>
All
Looking for tools that would help with monitoring congestion on a network.
For example, we use a deployment system for application deployments and
would like monitor how effective these deployments are. Any modules or
scripts I could muss with would be helpful.
thanks in advance
scott
scott.ranzal@mci.com
------------------------------
Date: Mon, 15 Mar 1999 15:00:32 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: newbie question
Message-Id: <36ED9110.98D26C46@mail.cor.epa.gov>
Chen Li wrote:
> I want to generate some data, the data has a certain distribution
> according to time, if there is an existent statistic module can do this?
> If not how to do that? Thanks a lot.
Perl has a lot of modules that do math/stat manipulations. Even complex
numbers and matrices. But there's no way of telling whether there is a
Perl module to do what you want, since you haven't given us any information.
If you're really trying to generate a probabilistic time series, perhaps
you need to try another newsgroup for better results. Perhaps sci.stat.math
or sci.stat.consult . If you know the distribution(s) and structure already,
and just want to implement it in Perl, then tell us more.
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 15 Mar 1999 12:47:42 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: NewbieQ: if ($dbhost && $dbname !~ m%[/@]%);
Message-Id: <u3hjc7.m06.ln@magna.metronet.com>
Steven T. Hatton (hattons@cpkwebser5.ncr.disa.mil) wrote:
: From that script I found a line that doesn't make a lot of
: sense to me:
: $dbname = $dbname . '@' . $dbhost if ($dbhost && $dbname !~ m%[/@]%);
: Obviously this is an assignment of a concatonated string to $dbname.
: This assignment only works if ($dbhost && $dbname !~ m%[/@]%) evalueates
: to true. I assume that $dbhost evaluates to true if it is declared(?)
^^^^^^^^
I think "defined" is what you are looking for there.
: and non-zero. Is this right?
No, since $dbhost='' is defined and non-zero, yet false.
The usual sequence for determining "truth" in Perl is:
1) if it is not a string, convert it to a string.
2) if it is one of the two strings '' or '0' it is false,
everything else is true
: I also assume $dbname !~ m%[/@]%
: evaluates to true if $dbname does not match m%[/@]%.
A more natural way (to me anyway) to say it is:
"true if $dbname contains neither slash nor at sign"
: What I completely
: don't understand is " m%[/@]% " What the heck does this mean?
It is just using alternative pattern delimiters, as described
in perlop.pod:
"With the C<m> you can use any pair of non-alphanumeric,
non-whitespace characters as delimiters"
So it is the same as:
m/[\/@]/
or
/[\/@]/
but is easier to read, understand and maintain.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 15 Mar 1999 18:56:52 -0500
From: fred222@mauimail.com (George)
Subject: Re: Passing Multiple Variables to a Sub
Message-Id: <fred222-ya023580001503991856520001@news.bellatlantic.net>
In article <36ECA582.C92FEA88@counter.w-dt.com>, Mike
<support@counter.w-dt.com> wrote:
> How do I pass multiple variables to a sub procedure? I have a file I
> want to open for read/write access but how do I insert the stuff in the
> middle that I want it to update without entering it. ie, I want a sub
> that just opens a file for read/write access so I don't have to write
> the code into my program in many places in my program instead I just
> want to refer to the sub but how do I pass the stuff I want to update
> (ussually more than one thing is updated).
> Thanks!
Mmm.. well, try
#... main program ... call the subroutine like:
&openit(JOEFILE,/home/httpd/html/file.txt);
#... subroutine ...
sub openit ($filehandle,$path) {
open($filehandle,"+<$path");
#... and so forth
}
I could have made some horrible horrible mistake, of course, but other than
that I think something along those lines ought to work. :-)
Cheers,
George
--
Just another hacking head >l-d
------------------------------
Date: Mon, 15 Mar 1999 15:59:31 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: perl and y2k (was Re: The millennium cometh -- eventually)
Message-Id: <36ED9EE3.EBD48C44@mail.cor.epa.gov>
Russell Schulz wrote:
[a whole bunch of stuff that I'm snipping]
> again: this is why I disagree with the FAQ. I have never seen a pencil
> that would surprise a user (who, shockingly, hadn't memorized its manual)
> by writing 100 when referring to 2000.
>
> but I think this has been gone over enough times; I know it's a problem
> inhereted from C; I know some people think every user should memorize the
> manual for every function they use; I know some people think there is no
> problem with writing `100' for a 2-digit year in 9 months. and I know
> there are people who think `tough noogies'.
Oh no! He's right! All programming languages are Y2K noncompliant, since
someone somewhere can misuse them! Quick, abandon your computers, turn off
your electricity, and run for the hills! I hear Theodore Kaczinski's shack
isn't being used right now...
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 15 Mar 1999 23:52:55 +0000
From: James@DX2.home (James Stevenson)
Subject: Re: Please can we stop this PIII thread RIGHT HERE? As it's off-topic for everybody!
Message-Id: <slrn7er7an.k7i.James@DX2.home>
On Mon, 15 Mar 1999 12:51:05 -0700, Kenny A. Chaffin <kenny@kacweb.com> wrote:
>In article <01be6f1a$1298f700$2a01a8c0@arc7>, binary@eton.powernet.co.uk
>says...
>> Subject line says it all - we've been through this subject ad nauseam
>> already, after all.
>>
>>
>
>you must be from the .c newsgroup.....
>
>--
>KAC Website Design
>Custom Programming, Web Design, and Graphics
>kenny@kacweb.com - http://www.kacweb.com
Hi
just to add to the point
it would be impossible to do
eg would it know what os you are running???
talk the the correct cp stack etc......
And of course it has a serial number so there
can work out who steals them if ppl do that sort of thing :)
cya
--
Check Out: http://www.users.zetnet.co.uk/james/
E-Mail: mistral@zetnet.co.uk
------------------------------
Date: Mon, 15 Mar 1999 23:51:36 +0000
From: Patrick Sinclair <ps96@ecs.soton.ac.uk>
Subject: Reading Directory
Message-Id: <Pine.LNX.3.96.990315235016.24470A-100000@tarrant.ecs.soton.ac.uk>
How can I make a perl script that acts more or less like a "dir" or "ls"
command?
Thanks
Patrick Sinclair
------------------------------
Date: Mon, 15 Mar 1999 19:49:42 -0500
From: Mark Sholund <msholund@bigfoot.com>
Subject: Re: Reading Directory
Message-Id: <36EDAAA6.A88306ED@bigfoot.com>
This is off the top of my head but I think the general idea is there.
#!/usr/bin/perl
($dir = $ARGV[0]) || ($dir = ".");
open(DIR,$dir);
@files = readdir(DIR);
print "@files\n;
exit 0;
------------------------------
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 5142
**************************************