[15666] in Perl-Users-Digest
Perl-Users Digest, Issue: 3079 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 17 18:10:56 2000
Date: Wed, 17 May 2000 15:10:32 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <958601432-v9-i3079@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 17 May 2000 Volume: 9 Number: 3079
Today's topics:
NDBM Permission error?? <ksoares@beancreative.com>
Re: packing problem <rootbeer@redcat.com>
Passing Hash to Subroutine using Keys michaelgray@my-deja.com
Re: Passing Hash to Subroutine using Keys <aqumsieh@hyperchip.com>
Re: Passing Hash to Subroutine using Keys <lr@hpl.hp.com>
Re: Passing Hash to Subroutine using Keys <lr@hpl.hp.com>
Re: Perl and binary files <lr@hpl.hp.com>
Perl Module Install Problems <grichard@uci.edu>
Re: Perl on 98 <Allan@due.net>
Re: Perl on 98 <yahoo@hotmail.de>
Perl-W32 #EXEC error (Steve)
Re: Perl-W32 #EXEC error <rootbeer@redcat.com>
Re: Perl-W32 #EXEC error (Steve)
PerlIS printing out header info. (Steve)
Re: PerlIS printing out header info. <rootbeer@redcat.com>
Re: Protecting Source Code? (Craig Berry)
Re: Protecting Source Code? (Ilya Zakharevich)
Re: qr operator and a variable as a pattern <aqumsieh@hyperchip.com>
Re: qr operator and a variable as a pattern <lr@hpl.hp.com>
Re: qr operator and a variable as a pattern (Neil Kandalgaonkar)
Re: qr operator and a variable as a pattern (Tad McClellan)
Re: Randomised function <lr@hpl.hp.com>
Re: reading from a socket <rootbeer@redcat.com>
Re: regex mind bender (for me) <flavell@mail.cern.ch>
Re: regex mind bender (for me) <lr@hpl.hp.com>
Re: regex mind bender (for me) <aqumsieh@hyperchip.com>
Re: regex mind bender (for me) (Andrew Johnson)
Re: regex mind bender (for me) <flavell@mail.cern.ch>
Re: regex mind bender (for me) <lr@hpl.hp.com>
Re: Sendmail? jdaves@gilanet.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 17 May 2000 16:38:56 -0400
From: "Keith Soares" <ksoares@beancreative.com>
Subject: NDBM Permission error??
Message-Id: <si60mbtj8ta59@corp.supernews.com>
I am trying to work with an NDBM database, but I keep getting an error.
Since the database does not exist, I have coded it to create a new
database -- so why would it not allow access?
No new files exist in the 'cgi-bin' directory, so I am assuming it is not
really making the database for some reason.
Here's the code I am using:
---------------------------------------------
use NDBM_File;
$datafile = "maillist";
tie(%database, 'NDBM_File', $datafile, O_RDWR | O_CREAT, 0666) or $msg =
"Cannot tie to database $datafile: $!";
...processing...
untie %database;
---------------------------------------------
Here's the error I keep getting:
---------------------------------------------
Cannot tie to database maillist: Permission denied
---------------------------------------------
Any clues why this may be happening??
TIA
Keith
------------------------------
Date: Wed, 17 May 2000 12:18:23 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: packing problem
Message-Id: <Pine.GSO.4.10.10005171216490.25459-100000@user2.teleport.com>
On Wed, 17 May 2000, O'Mahony, Donal wrote:
> $FRTPmsg = pack "ia1024xa8xa7xiill", $ReqCode, $RTDir, $SiteID,
> $BatchNo,
> $SeqNo, $NumBatches, $F7Pid, $TimeStamp, "\n";
What's the "\n" doing there?
> The C program reads it ok except that $NumBatches is read as 65536. If
> I change $SeqNo to 1 it is also read as 65536. The $ReqCode is read ok
> as 1.
>
> Any idea why this is ?
I'd say that you're probably using the wrong format string, although it
looks as if it _should_ be right. Try this: Make a C program which packs
up the data properly, send that data to Perl, and see whether that format
string can _un_pack it properly. Also double-check that the packed string
from C is the same length as the one you're passing frem Perl. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 17 May 2000 18:19:42 GMT
From: michaelgray@my-deja.com
Subject: Passing Hash to Subroutine using Keys
Message-Id: <8funrb$mpk$1@nnrp1.deja.com>
> > &printit (\$infoformat);
> ^
> ^
> What type of variable is `infoformat' ?
>
> hth
> t
It should be referenced as a hash &printit (\%infoformat); but I just
tried that and go the same result. So my oringal post still stands...
Sorry about the typo. Thanks.
---- oringal post with fix ----
How do I pass this hash %infoformat to the subroutine called printit. I
dont get any errors but the print statement only prints a :. Can this
be done using foreach $keys (keys .....
# assign master hash (%infoformat) from from info hash
while (($fieldname) = each (%infoformat)){
while (($i,$j) = each(%info)) {
if ($fieldname eq $i) {
$infoformat{$fieldname} = $j;
}
}
}
#call printit
&printit (\%infoformat);
# print hash that is sent to it
sub printit {
%y = $$_[0];
foreach $key (keys %y) {
print $key . ": " . $y->{$key} . "\n";
}
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 17 May 2000 19:28:30 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Passing Hash to Subroutine using Keys
Message-Id: <7a66sdasdd.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>
mgray@wallacefloyd.com writes:
> How do I pass this hash %infoformat to the subroutine called printit. I
Did you read what is explained in perlsub? You also might find it
helpful to read perlref.
> dont get any errors but the print statement only prints a :. Can this
> be done using foreach $keys (keys .....
>
> # assign master hash (%infoformat) from from info hash
> while (($fieldname) = each (%infoformat)){
each(), in list context, returns a list of the next key-value pair. In
scalar context, it returns the next key. Here, you are using it in list
context to grab only the key, which could be done more easily by:
# put it in scalar context
while ($fieldname = each %infoformat) {
or
for my $fieldname (keys %infoformat) {
> while (($i,$j) = each(%info)) {
What is %info?
> if ($fieldname eq $i) {
> $infoformat{$fieldname} = $j;
> }
> }
> }
You don't need the second while() loop. It's completely unnecessary and
defeats the purpose of hashes:
for my $fieldname (keys %infoformat) {
$infoformat{$fieldname} = $info{$fieldname} if
exists $info{$fieldname};
}
Or even on one line (or Perl >= 5.005):
exists $info{$_} && ($infoformat{$_} = $info{$_}) for keys %infoformat;
> #call printit
> &printit (\$infoformat);
That should be a \%infoformat.
> # print hash that is sent to it
> sub printit {
> %y = $$_[0];
You want to assign a hash to a hash. So, you have to dereference your
hash ref first:
%y = %{$_[0]};
> foreach $key (keys %y) {
> print $key . ": " . $y->{$key} . "\n";
> }
> }
But, I would use the hash ref directly and save some memory:
sub printit {
my $hashref = shift;
for my $key (keys %$hashref) {
print "$key: $hashref->{$key}\n";
}
}
Or even:
sub printit {
print "$_ = $_[0]{$_}\n" for keys %{$_[0]};
}
--Ala
------------------------------
Date: Wed, 17 May 2000 12:32:52 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Passing Hash to Subroutine using Keys
Message-Id: <MPG.138c93c121fc141598aa93@nntp.hpl.hp.com>
In article <8funrb$mpk$1@nnrp1.deja.com> on Wed, 17 May 2000 18:19:42
GMT, michaelgray@my-deja.com <michaelgray@my-deja.com> says...
...
> # print hash that is sent to it
> sub printit {
> %y = $$_[0];
Why, oh why, don't people use all the diagnostic tools that Perl
provides?
The '-w' flag would have informed you that you are here assigning an odd
number of elements (in this case, a single scalar) to a hash.
To assign a hash, you have to say so:
my %y = %{$_[0]};
Note that I added the 'my' declaration in the expectation that not only
will you start to use the '-w' flag, but also the 'use strict;' pragma,
which will help prevent another load of bugs.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 17 May 2000 12:45:23 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Passing Hash to Subroutine using Keys
Message-Id: <MPG.138c96ad2962bfb598aa94@nntp.hpl.hp.com>
In article <8funrb$mpk$1@nnrp1.deja.com> on Wed, 17 May 2000 18:19:42
GMT, michaelgray@my-deja.com <michaelgray@my-deja.com> says...
...
> #call printit
> &printit (\%infoformat);
^
Using the & to call a subroutine isn't necessary or particularly stylish
in Perl 5.
> # print hash that is sent to it
> sub printit {
> %y = $$_[0];
> foreach $key (keys %y) {
> print $key . ": " . $y->{$key} . "\n";
> }
> }
More observations:
1. Proper indenting materially aids legibility.
2. You actually don't need to copy the hash just to print it. Use the
reference directly.
sub printit {
foreach my $key (keys %{$_[0]}) {
print $key . ": " . $_[0]->{$key} . "\n";
}
}
Or, much more succinctly,
sub printit {
print "$_: $_[0]->{$_}\n" for keys %{$_[0]};
}
In fact, it is so short now that you might want to throw a 'sort' ahead
of the 'keys'. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 17 May 2000 11:02:14 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Perl and binary files
Message-Id: <MPG.138c7e82b2ef79f498aa8f@nntp.hpl.hp.com>
In article <CXwU4.3822$7V2.161285@newsread2.prod.itd.earthlink.net> on
Wed, 17 May 2000 13:15:14 GMT, jake <jakemsr@earthlink.net> says...
>
> From: "Larry Rosler" <lr@hpl.hp.com>
>
> > It is silly to use 'line-at-a-time' I/O on a file that has no 'lines'.
> >
>
> Bald assertions don't cut it. This is supposed to be 'science', not
> religion.
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
>
> Sorry to use your words out of context, but I found it fitting.
> Jake
I'm flattered that you chose to remember my words and to reuse them,
however inappropriately. The first time you did so, though, without the
explanatory comment, it smacked of forgery.
Jeff Zucker has already responded. Let me say this if further
clarification is needed:
It is silly to do I/O that may -- at one extreme of luck -- cause
functions to be called to deal with one character at a time, because it
happens also to have the semantics of a newline character in a text
file, or -- at the other extreme of luck -- cause an entire file to be
slurped before being printed.
Neither of those extreme behaviors is at all likely, but the
introduction of the concept 'read-a-line, write-a-line' where there are
no lines is just -- ahem -- silly.
Silliness isn't an issue of science or religion. It is an issue of
taste and judgment.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 17 May 2000 11:11:39 -0700
From: "Gabe" <grichard@uci.edu>
Subject: Perl Module Install Problems
Message-Id: <8funj3$c7r$1@news.service.uci.edu>
I'm trying to install DBI. I get the following error upon running Make:
make: *** No rule to make target `blib/arch/auto/DBI/Driver.xst', needed by
`Perl.xsi'. Stop.
What does this mean and what do I do?
Gabe
------------------------------
Date: Wed, 17 May 2000 15:37:43 -0400
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Perl on 98
Message-Id: <8fusfb$593$1@slb7.atl.mindspring.net>
<amerar@my-deja.com> wrote in message news:8fulgr$ju2$1@nnrp1.deja.com...
: Simple question. I've never used Perl under Windows 98 before. How the
: heck are you aupposed to get the system date? Can't seem to figure that
: one out.......
I do it the Perl way. <g>
perldoc -f localtime;
Or perhaps you mean something else by system date.
: Please CC a copy to: amerar@ci.chi.il.us
Ok
HTH
AmD
--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
'Out, out brief candle!
Life's but a walking shadow,
a poor player, that struts and frets his hour upon the stage,
And then is heard no more; It is a tale, told by an idiot,
full of sound and fury, signifying nothing'
- MacBeth
------------------------------
Date: Wed, 17 May 2000 20:26:00 GMT
From: "Ummmzzzz" <yahoo@hotmail.de>
Subject: Re: Perl on 98
Message-Id: <sfDU4.4866$rB1.31131@nlnews00.chello.com>
I dunno .. i used the same scripts using system time with linux NT and 98 ..
all worked the same and fine .. i just dont feel like copy + pasting the
code .. but if ya look at www.wdvl.com and goto perl or cgi .. its somewhere
in there ..
=]
*slet*
Allan M. Due <Allan@due.net> wrote in message
news:8fusfb$593$1@slb7.atl.mindspring.net...
> <amerar@my-deja.com> wrote in message news:8fulgr$ju2$1@nnrp1.deja.com...
> : Simple question. I've never used Perl under Windows 98 before. How the
> : heck are you aupposed to get the system date? Can't seem to figure that
> : one out.......
>
> I do it the Perl way. <g>
> perldoc -f localtime;
>
> Or perhaps you mean something else by system date.
>
> : Please CC a copy to: amerar@ci.chi.il.us
>
> Ok
>
> HTH
>
> AmD
>
> --
> $email{'Allan M. Due'} = ' All@n.Due.net ';
> --random quote --
> 'Out, out brief candle!
> Life's but a walking shadow,
> a poor player, that struts and frets his hour upon the stage,
> And then is heard no more; It is a tale, told by an idiot,
> full of sound and fury, signifying nothing'
> - MacBeth
>
>
>
------------------------------
Date: Wed, 17 May 2000 20:34:49 GMT
From: stevec@computer-geeks.com (Steve)
Subject: Perl-W32 #EXEC error
Message-Id: <392301b3.96775846@news.geeksnet.com>
I'm getting a periodical error on my web pages where I call a .pl
script. The error is "#EXEC calls have been disabled for this virtual
path" I'm running Activestate build 613 on NT 4.0 SP5 and IIS 4.0.
Does anybody know what causes this and how to fix it? It is sporadic
and works most of the time.
Thanks,
Steve Cobb
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Wed, 17 May 2000 13:40:37 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Perl-W32 #EXEC error
Message-Id: <Pine.GSO.4.10.10005171339590.25459-100000@user2.teleport.com>
On Wed, 17 May 2000, Steve wrote:
> I'm getting a periodical error on my web pages where I call a .pl
> script. The error is "#EXEC calls have been disabled for this virtual
> path"
Sounds like a problem with your server. Perhaps you should search for the
docs, FAQs, and newsgroups about webservers. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 17 May 2000 20:43:27 GMT
From: stevec@computer-geeks.com (Steve)
Subject: Re: Perl-W32 #EXEC error
Message-Id: <3923043c.97424278@news.geeksnet.com>
Thanks Tom,
Any suggestions on where to start. I've reviewed all the links on the
Activestate web site.
Thanks,
Steve Cobb
On Wed, 17 May 2000 13:40:37 -0700, Tom Phoenix <rootbeer@redcat.com>
wrote:
>On Wed, 17 May 2000, Steve wrote:
>
>> I'm getting a periodical error on my web pages where I call a .pl
>> script. The error is "#EXEC calls have been disabled for this virtual
>> path"
>
>Sounds like a problem with your server. Perhaps you should search for the
>docs, FAQs, and newsgroups about webservers. Cheers!
>
>--
>Tom Phoenix Perl Training and Hacking Esperanto
>Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
>
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Wed, 17 May 2000 20:40:22 GMT
From: stevec@computer-geeks.com (Steve)
Subject: PerlIS printing out header info.
Message-Id: <392302bf.97043736@news.geeksnet.com>
When I try to run a perl script on my NT 4.0 SP5 IIS 4.o server with
PERLIS, it prints out the header information like "HTTP/1.1 200 OK
Date: Wed, xx 2000 20:22:30 GMT Server: Microsoft-IIS/4.0"
How can I turn this of?
Thanks,
Steve Cobb
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Wed, 17 May 2000 14:48:20 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: PerlIS printing out header info.
Message-Id: <Pine.GSO.4.10.10005171446550.25459-100000@user2.teleport.com>
On Wed, 17 May 2000, Steve wrote:
> When I try to run a perl script on my NT 4.0 SP5 IIS 4.o server with
> PERLIS, it prints out the header information like "HTTP/1.1 200 OK
> Date: Wed, xx 2000 20:22:30 GMT Server: Microsoft-IIS/4.0"
>
> How can I turn this of?
It sounds as if you want to make your webserver do something. Perhaps you
should search for the docs, FAQs, and newsgroups about webservers. But
those headers sound a lot like HTTP headers; if it didn't output those, it
wouldn't be a webserver, would it? :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 17 May 2000 18:10:01 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Protecting Source Code?
Message-Id: <si5o3pbs8ta117@corp.supernews.com>
James (spectralmedia@home.com) wrote:
: Anyone know any good techniques for protecting your perl code?
I take mine deep into the forest and hide it inside a hollow log.
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "The road of Excess leads to the Palace
of Wisdom" - William Blake
------------------------------
Date: 17 May 2000 18:17:25 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Protecting Source Code?
Message-Id: <8funnl$2t4$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Abigail
<abigail@arena-i.com>],
who wrote in article <slrn8i39ml.k11.abigail@ucan.foad.org>:
> On Tue, 16 May 2000 19:11:58 GMT, James <spectralmedia@home.com> wrote:
> ++ Anyone know any good techniques for protecting your perl code?
> $ chmod 000 program.pl
I find that putting the line
use more 'protection';
near the top of the script and the modules works much better.
Ilya
------------------------------
Date: Wed, 17 May 2000 19:29:28 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: qr operator and a variable as a pattern
Message-Id: <7a3dnhasbt.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>
Wilma Cray <wilma@orientation.com> writes:
> And now the same example with a variable as a pattern:
>
> $bar=qr/\d/g/; # $bar=qr/\d\/g/; doesn´t work too
>
> @foo = $bar;
@foo = /$bar/;
--Ala
------------------------------
Date: Wed, 17 May 2000 12:26:02 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: qr operator and a variable as a pattern
Message-Id: <MPG.138c92256824fdbe98aa92@nntp.hpl.hp.com>
In article <gkj5is4b9ec18ru0562v9379jfg4u2gcau@4ax.com> on Wed, 17 May
2000 19:02:31 +0200, Wilma Cray <wilma@orientation.com> says...
> I need this pattern as a variable: /\d/g
>
> $_="43aa23aa653";
>
> @foo = /\d/g;
>
> foreach $i (@fpp)
^^
Typing in untested code instead of cutting and pasting code that
compiles undermines credibility.
> {
> print $i;
> }
>
> And now the same example with a variable as a pattern:
>
> $bar=qr/\d/g/; # $bar=qr/\d\/g/; doesn´t work too
Using escapes or alternate delimiters just puts '/g' into the regex as
literals.
> @foo = $bar;
That just assigns the compiled regex to the only element of a one-
element array.
$bar = qr/\d/;
@foo = /$bar/g;
The /g modifier isn't compilable using qr(), and (?g) isn't meaningful
within a regex. If that /g needs to be variable, you may have to resort
to eval STRING or select between two expressions, one with the /g and
one without it.
You can read about qr() in perlop.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 17 May 2000 19:32:41 GMT
From: nj_kanda@alcor.concordia.ca (Neil Kandalgaonkar)
Subject: Re: qr operator and a variable as a pattern
Message-Id: <8fus4p$his$1@newsflash.concordia.ca>
In article <gkj5is4b9ec18ru0562v9379jfg4u2gcau@4ax.com>,
Wilma Cray <wilma@orientation.com> wrote:
>And now the same example with a variable as a pattern:
>
> $bar=qr/\d/g/; # $bar=qr/\d\/g/; doesn´t work too
Hm, you have some basic misunderstandings of how to write a regex.
No trailing slash; and for qr// precompiled regexes, you can't store
the /g switch. /g is unlike the others, it has more to do with
how the regex is iterated over than what it matches.
I suggest you check out the perlre page in the documentation, or
see the forthcoming perl regex tutorial:
<http://keck.ucsf.edu/~kvale/perlrequick.pod>
> @foo = $bar;
This just makes @foo an array consisting of one element, $bar.
I think you really wanted to say:
@foo = ($_ =~ /$bar/g);
Don't worry, AFAIK you still get the benefits of precompilation.
> foreach $i (@fpp)
^^ sigh. I assume you meant @foo.
> {
> print $i;
> }
If all you wanted to do was print the numbers, print already
works on a list.
print @foo;
or, without temporary variables:
print ($_ =~ /$bar/g);
--
Neil Kandalgaonkar
neil@brevity.org
------------------------------
Date: Wed, 17 May 2000 15:24:25 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: qr operator and a variable as a pattern
Message-Id: <slrn8i5sf9.2ke.tadmc@magna.metronet.com>
On Wed, 17 May 2000 19:02:31 +0200, Wilma Cray <wilma@orientation.com> wrote:
>
>I need this pattern as a variable: /\d/g
^^^^^^^^^^^^
$pattern = '\d';
The //g part is NOT a pattern. It is an operator.
> $_="43aa23aa653";
>
> @foo = /\d/g;
^^^^
> foreach $i (@fpp)
^^^^
Give pseudo code if a pseudo answer is sought.
Give real code for real answers.
(i.e. use copy/paste, don't try and retype code in messages)
> print $i;
> }
>
>And now the same example with a variable as a pattern:
>
> $bar=qr/\d/g/; # $bar=qr/\d\/g/; doesn´t work too
^^
^^
The description for that operator in perlop.pod says nothing
about a 'g' option.
>
> @foo = $bar;
>
> foreach $i (@fpp)
> {
> print $i;
> }
>
>This doesn´t work.
>Is there a solution?
Put just the pattern part into a variable and use the m// operator:
$bar = qr/\d/;
@foo = /$bar/g;
I expect you _need_ the pattern in a variable, but in case
you really just want all of the digit chars, you can:
@foo = split /\D+|/; # 1 digit char per list element
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 May 2000 11:59:27 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Randomised function
Message-Id: <MPG.138c8be9c4ab2faf98aa91@nntp.hpl.hp.com>
In article <20000517135601.L539@rahul.net> on Wed, 17 May 2000 13:56:01
-0400, Bennett Todd <bet@rahul.net> says...
> 2000-05-16-18:42:45 Larry Rosler:
...
> > printable => [ "\x20" .. "\x7E" ],
...
> I believe the range operator only expands the way you're describing
> for those strings that support the "magic ++ string increment",
> which is basically (from perlop) [a-zA-Z]*[0-9]*.
You bet. My brain took the day off, and my fingers were too lazy to
test what I posted.
Sigh...
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 17 May 2000 12:11:03 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: reading from a socket
Message-Id: <Pine.GSO.4.10.10005171207430.25459-100000@user2.teleport.com>
On Wed, 17 May 2000, Pat wrote:
> read(Client, $answer, 20);
>
> This works fine but what if I don't know the lenght of the answer in
> advance?
You may need to read a little at a time, in a loop, until you've gotten
enough. Instead of read(), it may be better to use sysread(), to avoid
some buffering issues. Does that get you closer to a solution? Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 17 May 2000 19:57:08 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: regex mind bender (for me)
Message-Id: <Pine.GHP.4.21.0005171950390.3970-100000@hpplus03.cern.ch>
On Wed, 17 May 2000, Jonah wrote:
> That's why I said the value was from a textfield, they won't
> have tabs or newlines,
Never, repeat: NEVER, trust user input. Validate it before doing
ANYTHING serious with it.
> you can't enter them in the field =)
You're living dangerously. And there's no need to.
If you don't believe me, then take a look at some of the kooky
submissions that turn up in our server logs, from people trying to
crack CGI scripts they think we might have. Newlines are particularly
favoured in such submissions!
------------------------------
Date: Wed, 17 May 2000 11:25:25 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: regex mind bender (for me)
Message-Id: <MPG.138c83eea47e1e0098aa90@nntp.hpl.hp.com>
In article <vDrU4.14029$95.197239@news1.rdc1.mb.home.com> on Wed, 17 May
2000 07:12:27 GMT, Andrew Johnson <andrew-johnson@home.com> says...
> In article <8ft1dm$137i$1@onlink3.onlink.net>,
> Jonah <nomail@nomail.com> wrote:
...
> > I'm getting a value from a $q->textfield
> > and I need to check if it contains *only* spaces.
> >
> > not empty, but if it has 1 or more spaces and nothing else in it.
^^^^^^^^^
...
> or use a negative character class:
>
> print "yay" unless $var =~ /[^ ]/;
That regex matches an empty string, so doesn't meet the requirements,
which state that the string not be empty.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 17 May 2000 20:55:13 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: regex mind bender (for me)
Message-Id: <7a7lcsnbgs.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>
Ilja <billy@arnis-bsl.com> writes:
> P.S. Never trust a user - may be he is a HaCkEr.
Hackers are not necessarily bad people. Crackers, on the other hand,
are.
--Ala
------------------------------
Date: Wed, 17 May 2000 21:10:31 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: regex mind bender (for me)
Message-Id: <bVDU4.14090$95.199185@news1.rdc1.mb.home.com>
In article <MPG.138c83eea47e1e0098aa90@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
[snip]
>
> > or use a negative character class:
> >
> > print "yay" unless $var =~ /[^ ]/;
>
> That regex matches an empty string, so doesn't meet the requirements,
> which state that the string not be empty.
It doesn't match empty strings here ... what do you put in your
empty strings that cause this pattern to match?
andrew
--
Andrew L. Johnson http://members.home.net/andrew-johnson/epwp.html
well, take it from an old hand: the only reason it would be easier
to program in C is that you can't easily express complex problems
in C, so you don't. -- Erik Naggum, on comp.lang.lisp
------------------------------
Date: Wed, 17 May 2000 23:43:22 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: regex mind bender (for me)
Message-Id: <Pine.GHP.4.21.0005172342320.3970-100000@hpplus03.cern.ch>
On Wed, 17 May 2000, Ala Qumsieh wrote:
> Ilja <billy@arnis-bsl.com> writes:
>
> > P.S. Never trust a user - may be he is a HaCkEr.
>
> Hackers are not necessarily bad people.
I think the context was deliberately case-sensitive.
:-}
------------------------------
Date: Wed, 17 May 2000 14:51:25 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: regex mind bender (for me)
Message-Id: <MPG.138cb439308b6e2b98aa96@nntp.hpl.hp.com>
In article <bVDU4.14090$95.199185@news1.rdc1.mb.home.com> on Wed, 17 May
2000 21:10:31 GMT, Andrew Johnson <andrew-johnson@home.com> says...
> In article <MPG.138c83eea47e1e0098aa90@nntp.hpl.hp.com>,
> Larry Rosler <lr@hpl.hp.com> wrote:
> [snip]
> >
> > > or use a negative character class:
> > >
> > > print "yay" unless $var =~ /[^ ]/;
> >
> > That regex matches an empty string, so doesn't meet the requirements,
> > which state that the string not be empty.
>
> It doesn't match empty strings here ... what do you put in your
> empty strings that cause this pattern to match?
I shouldn't have said that the regex matches an empty string. Obviously
it doesn't. What I meant was that the *statement* doesn't meet the
requirements, because of the negative logic.
It prints *unless* the string matches the pattern. An empty string
doesn't match the pattern, so it prints. But he wanted to print if the
string had at least one space.
> > and I need to check if it contains *only* spaces.
> >
> > not empty, but if it has 1 or more spaces and nothing else in it.
^^^^^^^^^
print "yay" unless !length($var) || $var =~ /[^ ]/;
print "yay" if length($var) && $var !~ /[^ ]/;
...
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 17 May 2000 20:14:12 GMT
From: jdaves@gilanet.com
Subject: Re: Sendmail?
Message-Id: <8fuui2$v7e$1@nnrp1.deja.com>
In article <mLAU4.20222$au2.221363@news1.rdc1.bc.home.com>,
"Marcus" <mouimet@direct.ca> wrote:
> I am using Matt's cgi script to send a form via email. It used to work
fine
> on my old
> server but now I am having the weirdest thing happen to me on my new
> dedicated server (Red Hat Linux 6.1). The script will send out to any
email
> address like: hell@hello.com or hi@hi.ca but when you try and send to
> something like: hello@mindlink.bc.ca or hello@sk.sympatico.ca it won't
send.
> I have verified the email address' I am trying to send to and it they
work
> otherwise. Any suggestions on where the problem lies or how I can fix
it?
>
>
Has your mail server changed? sendmail, exim, version, etc. Try telnet
<servername> 25 to see what mail/version you have.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3079
**************************************