[8272] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1889 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 13 13:09:03 1998

Date: Fri, 13 Feb 98 10:01:35 -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           Fri, 13 Feb 1998     Volume: 8 Number: 1889

Today's topics:
        regexp: /^[800|888]/ vs. /^8[0{2}|8{2}]/ (Fritz Knack)
    Re: regexp: /^[800|888]/ vs. /^8[0{2}|8{2}]/ <doug@tc.net>
    Re: sorting an array <dgwilson@gte.net>
    Re: training recommendation? <merlyn@stonehenge.com>
    Re: Using list as value of hash (Bart Lateur)
    Re: Using list as value of hash <dboorstein@shopcfn.com>
    Re: using Monitor.pm from the panther book a hash lusol@turkey.cc.Lehigh.EDU
        Variable interpolation or reference? (Mark666769)
        Way Off-Topic <SNIPhsommer@micro.ti.comSNIP>
        Webmasters???? <rishi_bhat@hotmail.com>
    Re: Why is Tom Christiansen so rude? <"John Porter <jdporter"@min.net>>
    Re: Why is Tom Christiansen so rude? (Andrew M. Langmead)
    Re: Y2k: [Was: Re: Learning Perl (I R A Aggie)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 13 Feb 1998 15:17:50 GMT
From: fritz.knack@nospam.POPULUS.net (Fritz Knack)
Subject: regexp: /^[800|888]/ vs. /^8[0{2}|8{2}]/
Message-Id: <34e45fe8.8296270@cnews.newsguy.com>

For a report I've written, I'm trying to determine if a given phone
number is an 800-class number, i.e., it begins with 800 or 888.

Anyway, below are two snippets of code. The first one is what works
the way I want it to. The second pulls too much, e.g., area code 813
(Houston? Dallas?) "counts" as an 800-class number.

Can anyone tell me what's going on? I would have though the two were
classic TMTOWTDI. (If it matters: perl 5.0003_07, Win32 build 311.)

# Snippet 1:
  	if ($phone =~ /^8[0{2}|8{2}]/) {
#		do stuff
	}

#	Snippet 2:
	if ($phone =~ /^[800|888]/) {
#		do stuff
	}

Best regards,
Fritz

-------------------------
Sorry 'bout the nospam in the From field. You know how those 'bots are.


------------------------------

Date: 13 Feb 1998 12:10:55 -0500
From: Douglas McNaught <doug@tc.net>
Subject: Re: regexp: /^[800|888]/ vs. /^8[0{2}|8{2}]/
Message-Id: <m2afbvbfc0.fsf@ono.tc.net>

fritz.knack@nospam.POPULUS.net (Fritz Knack) writes:

> For a report I've written, I'm trying to determine if a given phone
> number is an 800-class number, i.e., it begins with 800 or 888.
> 
> Anyway, below are two snippets of code. The first one is what works
> the way I want it to. The second pulls too much, e.g., area code 813
> (Houston? Dallas?) "counts" as an 800-class number.
> 
> # Snippet 1:
>   	if ($phone =~ /^8[0{2}|8{2}]/) {
> #		do stuff
> 	}
> 
> #	Snippet 2:
> 	if ($phone =~ /^[800|888]/) {
> #		do stuff
> 	}

You need to use parentheses instead of brackets.  Brackets denote
character classes.  The regexes you're using above are equivalent to 

/^8[028{}|]/  (which *will* match 828 and other things you don't want)

and

/^[08|]/   (which also matches stuff you don't want).  

Using parens instead of square brackets will fix both your regexes. 

-Doug
-- 
sub g{my$i=index$t,$_[0];($i%5,int$i/5)}sub h{substr$t,5*$_[1]+$_[0],1}sub n{(
$_[0]+4)%5}$t='encryptabdfghjklmoqsuvwxz';$c='fxmdwbcmagnyubnyquohyhny';while(
$c=~s/(.)(.)//){($w,$x)=g$1;($y,$z)=g$2;$w==$y&&($p.=h($w,n$x).h($y,n$z))or$x==
$z&&($p.=h(n$w,$x).h(n$y,$z))or($p.=h($y,$x).h($w,$z))}$p=~y/x/ /;print$p,"\n";


------------------------------

Date: Fri, 13 Feb 1998 12:42:17 -0500
From: Douglas Wilson <dgwilson@gte.net>
Subject: Re: sorting an array
Message-Id: <6c20jd$lo1$1@gte2.gte.net>

MR wrote:
> 
> Hello,
> 
> I have an array of keys with this patern: xxxxYYYY where xxxx is a fixed
> char and YYYY are numbers. I want to sort the array by numeric valor of
> YYYY. There is a
> simple method???

To quote an answer to one of my posts:
<quote>
 Check out the FAQ or
www.effectiveperl.com on how to do a "Schwartzian Transform".
(Named after me, but not *by* me. :-)  For this, it'd be something
like:
</quote>

(I'm assuming that you want to sort numerically by any numbers at
the end of the string, so here's my answer based on that)

@array=qw(b1 c2 hello a3 e15 d4);
@array=
map {
 #(print ("$_->[0] $_->[1] $_->[2]\n")),
 $_->[0]
} sort {
 $a->[2] <=> $b->[2]
} map {
 [$_, /[0-9]+$/, (defined $&)?$&:0]
} @array;

Hope that helps,
Douglas Wilson


------------------------------

Date: 13 Feb 1998 09:05:19 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: training recommendation?
Message-Id: <8c1zx77ao0.fsf@gadget.cscaper.com>

>>>>> "Martien" == Martien Verbruggen <mgjv@comdyn.com.au> writes:

Martien> In article <34E34173.3A0940A7@fpk.hp.com>,
Martien> 	"Jess Arnold (BFR Contractor)" <jba@fpk.hp.com> writes:
>> Can anyone recommend any good training courses in the New York area.  I
>> am interested in learning PERL but I have no real programming background
>> so I want to take a course to get me started.  If not, can anyone
>> recommend good book(s) to get me started.  Thanks.

Martien> Start here with your search:

Martien> http://language.perl.com/info/training.html

Or the much easier URL to remember:

	www.perltraining.com

:-)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 199 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


------------------------------

Date: Fri, 13 Feb 1998 16:29:52 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Using list as value of hash
Message-Id: <34e674d1.16773380@news.tornado.be>

epa@datcon.co.uk (Ed Avis) wrote:

>apple       2
>pear        2
>goat        3
>bear        4
>banana      2
>
>Here the ID "2" is associated with the names "apple", "pear" and
>"banana".  The ID "3" is associated with "goat", and "4" with "bear".

>but the problem is, this only allows one name to be associated with
>each ID.

I've already done something like this:

	push @{$hash{$key}}, $value;

Here, the value of the hash becomes an array reference.

It even works (worked?) if $key didn't have a value yet. It will (well,
did) create a new anonymous array with just one scalar in it: the new
value. Well, it still seems to work with my current Perl port.

Example of retrieving the data (printout):

	$" = ", "; $\="\n";
	foreach (keys %hash) {
	   print "$_: @{$hash{$_}}";
	}

which gives

	2: apple, pear, banana
	3: goat
	4: bear

Looks ok to me.

HTH,
Bart.


------------------------------

Date: Fri, 13 Feb 1998 12:11:08 -0500
From: Dan Boorstein <dboorstein@shopcfn.com>
To: Ed Avis <epa@datcon.co.uk>
Subject: Re: Using list as value of hash
Message-Id: <34E47EAC.E940FBCA@shopcfn.com>

Ed Avis wrote:
> open (IF, "filename");
> 
> while (<IF>)
> {
>   @words = split;
>   $id = $words[1];
>   $name{$id} = $words[0];
> }
> 
> but the problem is, this only allows one name to be associated with
> each ID.

i think what might be useful is a more complex data structure like
a hash of arrays:

----cut----

while (<DATA>)
{
  @words = split;
  $id = $words[1];
  push @{ $name{$id} }, $words[0];
}

for $id (keys %name) {
  print "$id: ";
  print join ', ', @{ $name{$id} };
  print "\n";
}

__DATA__
apple       2
pear        2
goat        3
bear        4
banana      2

----cut----

for each item, this pushes an element onto an array
which is referenced by $name{$id}. the second part
shows how to access those elements. if you wanted
to access the first item with id 3 you would use:

  ${ $name{3} }[0]

to step through all of the elements of id 2 might
be done like this:

  foreach $item (@{ $name{2} }) {
    &digest($item) || &puke($item);
  }

good luck,

-- 
dan boorstein <dboorstein@shopcfn.com>


------------------------------

Date: 13 Feb 1998 16:33:43 GMT
From: lusol@turkey.cc.Lehigh.EDU
Subject: Re: using Monitor.pm from the panther book a hash
Message-Id: <6c1sl7$ukq@fidoii.cc.Lehigh.EDU>

     Martin Bialasinski <agr30@uni-koeln.de> wrote in article <87oh0bhano.fsf@haitech.internet-treff.de> :
>
>Hi,
>
>the Monitor.pm example on page 147f. is missing the CLEAR, FIRSTKEY and
>NEXTKEY subs.
>
>CLEAR is trivial, but how do you code {FIRST,NEXT}KEY efficiently?
>
>You could create a {key => nextkey} hash on FIRSTKEY and store it in the
>object so that NEXTKEY could do the lookup easily. When NEXTKEY reaches
>the last key, this hash would be deleted.

Tie::Watch on CPAN shows how to do this....


------------------------------

Date: 13 Feb 1998 16:20:12 GMT
From: mark666769@aol.com (Mark666769)
Subject: Variable interpolation or reference?
Message-Id: <19980213162000.LAA01906@ladder03.news.aol.com>

Hi,

In the following program:


#!/usr/local/bin/perl

$var = "test";
${$var} = "data";		# creates a new variable "$test"

print "\$var is: $var\n";
print "\$test is: $test\n";


I see that ${$var} creates a new variable $test,
but I'm not quite sure why. In other words,
what concept is coming into play here? Is this
another form of variable interpolation? Or is this
creating a reference with $$ ? Or something else?

My first inclination would be to say it's variable
interpolation. But when I change the line to:

my ${$var} = "data";

I get the error:

Can't declare scalar deref in my at ...

So... I'm confused. What's going on here, and how
can I declare a variable with my, whose name comes
from another variable?

Please, no long explanation necessary. Just tell me
briefly what's going on here, and I'll look it up.
DejaNews won't let me search for "${" - try it!

Thanks.



------------------------------

Date: Fri, 13 Feb 1998 10:59:39 -0600
From: Holly Sommer <SNIPhsommer@micro.ti.comSNIP>
Subject: Way Off-Topic
Message-Id: <34E47BFB.130BB93A@micro.ti.comSNIP>

Tom Grydeland wrote:

: Note that the claim was:
: 
:    More than one user  =>  ! PC

Hm. Define user then? When in W95, I can allow someone else to
control my machine, remotely, with a program called Timbuktu -
at the same time that I control (yes, you can get into a mousewar ;).
Or, I can disallow it. When running Linux, I can allow people to
telnet in, if I've set up a shell account for them on my machine. Or,
I can disallow it. So, which of these situations is it a PC, and which
is it not? Same box in all 4 circumstances.

-Holly, doesn't think it matters anyhow


------------------------------

Date: Fri, 13 Feb 1998 10:25:37 -0600
From: Rishi Bhattacharya <rishi_bhat@hotmail.com>
Subject: Webmasters????
Message-Id: <34E47401.4E19@hotmail.com>

Hello,

I am currently starting a new project and am looking for CGI/Perl
programmers to head the CGI department of my site.  The new project is
www.webresource.net.  It is a site intended to help out webmasters (both
novice and expert).  Your main job will be to write two to three
articles per month on the topic of your choice (obviously has to deal
with CGI/Perl).  We are already receiving advertsing offers for the
site.  All revenues will be split equally among team members.

The ideal applicant will have at least one year of solid programming
experience (in CGI) and excellent writing skills.  If you are
interested, please send your resume and a few urls of your work to the
following address.  

rbhattac@bayou.uh.edu

Thanks.

Rishi Bhattacharya
Electrical Engineer
NASA/McDonnell Douglas


------------------------------

Date: Fri, 13 Feb 1998 10:57:16 -0500
From: John Porter <"John Porter <jdporter"@min.net>>
Subject: Re: Why is Tom Christiansen so rude?
Message-Id: <6c1qjf$b8s$2@out2.nntp.min.net>

Francois Trousset wrote:
> 
>     The probleme, is that when you look at the perl documentation
> in the CPAN distribution, you see that it is about 30 Megabytes of
> compressed stuff. If you want perl to be a democratic language (in the
> sense that it is used by the majority), you cannot ask people first to
> read all of these docs, and I thing that for the majority of the
> question, it should have been answer somewhere here or outside this
> list. 

The admonition to RTFM does not necessarily mean "read 30 Mbs of
text before attempting to write one line of code."  It can mean
"read the FAQ table of contents", which contains the questions.
It can also mean, for those who know how, to search the text of
the FAQs using a tool such as grep or Start:Find.

John Porter


------------------------------

Date: Fri, 13 Feb 1998 17:01:11 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Why is Tom Christiansen so rude?
Message-Id: <EoBtxz.1EF@world.std.com>

clay@panix.com (Clay Irving) writes:

>DESCRIPTION

>     Tom is a user-friendly command line tool that provides a wealth
>     of information about the Perl programming language. 


[stuff deleted]

>      This command:

>           Tom -v "Is Perl5 Y2K compliant?"

>      will output:

>           As the clock draws us relentlessly closer toward 2000, the final year of the second millennium, doom sayers everywhere are
>prophesying unprecedented computer failure in every conceivable sector. Known popularly as the Year 2000 Problem, or the
>Millennium Bug, this situation is quite easy to explain. Programs that interpret two-digit dates in the form XX as 19XX behave
>unpredictably starting in the year 2000 and beyond into the next millennium. If your birthday is ``2/2/05'', are you 101 years old
>in 2006, or just one year old? 
[more deleted]

Prettly close, except that the perl "Tom" wraps text correctly.
-- 
Andrew Langmead


------------------------------

Date: Fri, 13 Feb 1998 11:37:29 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Y2k: [Was: Re: Learning Perl
Message-Id: <fl_aggie-1302981137290001@aggie.coaps.fsu.edu>

In article <6c1mpm$krq$1@srv38s4u.cas.org>, lvirden@cas.org wrote:

+ According to Carey Evans  <c.evans@clear.net.nz>:
+ :Did you know there are no plans to make Perl 4 Y2K compliant?  Do your 
+ :managers?

+ Yet I also see, on a regular bases, the above statement - either in
+ truth or as a 'threat' to try to force folk to upgrade whether they
+ wish to or not.

They don't _have_ to upgrade to a more recent version of perl. But they
_better_ be aware that perl 4 is dead, dead, dead. And it will remain
so. They _may_ find a pocket of perl 4 enthusiasts patching bugs here or
there, but THAT IS THE ONLY SUPPORT THEY ARE LIKELY TO EVER FIND.

And they _better_ be aware of that, too -- they are, for the most part,
on their own. Which makes it obvious that there are _no_ plans to make 
Perl 4 y2k compliant.

+ Is it really any wonder that some folk are confused about the issue when
+ apparent mixed messages are posted on a regular basis?

How is it mixed? is it not, in fact, a true statement? Are you aware of
anyone planning on ensuring that perl 4 is y2k compliant?

James

-- 
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>


------------------------------

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 1889
**************************************

home help back first fref pref prev next nref lref last post