[22417] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4638 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 28 00:06:03 2003

Date: Thu, 27 Feb 2003 21:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 27 Feb 2003     Volume: 10 Number: 4638

Today's topics:
        Active Perl, use Strict, and $Response (P D Denize)
    Re: Also religious: brackets (Tad McClellan)
    Re: Brute Force Golf Solver <goldbb2@earthlink.net>
    Re: Brute Force Golf Solver <REMOVEsdnCAPS@comcast.net>
    Re: Brute Force Golf Solver <mgjv@tradingpost.com.au>
        Counting matches in a regular expression <me@me.com>
    Re: Counting matches in a regular expression (Jay Tilton)
    Re: Counting matches in a regular expression <goldbb2@earthlink.net>
    Re: driving me nuts! <REMOVEsdnCAPS@comcast.net>
        How to sort by field in objects? (Boris)
    Re: How to sort by field in objects? <bigiain@mightymedia.com.au>
    Re: How to sort by field in objects? <mgjv@tradingpost.com.au>
    Re: newbie question <REMOVEsdnCAPS@comcast.net>
    Re: newbie question <wksmith@optonline.net>
    Re: newbie question <shondell@cis.ohio-state.edu>
    Re: newbie question <jurgenex@hotmail.com>
    Re: newbie question <jurgenex@hotmail.com>
    Re: Newbie: Trouble with time() from "learning perl" bo (Tad McClellan)
    Re: perl expect, vt102, and sending a function key. (Daniel S. Lewart)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 27 Feb 2003 19:05:57 -0800
From: paul@buyonline.co.nz (P D Denize)
Subject: Active Perl, use Strict, and $Response
Message-Id: <e888d0c1.0302271905.765e96a0@posting.google.com>

I'd like to use the strict checking features but cant seem to get
working code to find the correct libraries.


I Try:

- test.asp --------------
<%@Language=PerlScript%>
<%
use strict;
%>
TEST
-------------------------

I Get:

-------------------------
PerlScript Error error '80004005' 

Global symbol "$Response" requires explicit package name 

/accounts/test.asp, line 3 
-------------------------

I assume the "TEST" has generated a $Response->write and the strict
now wants to know where this is from.

So would I.

Can anyone tell me how I can cross this small hurdle?


Paul Denize


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

Date: Thu, 27 Feb 2003 22:17:40 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Also religious: brackets
Message-Id: <slrnb5ton4.26v.tadmc@magna.augustmail.com>

Steven Smolinski <steven.smolinski@sympatico.ca> wrote:
> Malte Ubl <ubl@schaffhausen.de> wrote:

>> print if /^regEx$/ while <$_> for someFileHandles
>> 
>> is a syntax error because chaining expression 
>> modifiers is not allowed. Hmm, maybe that's not such a bad idea :)
> 
> \begin{plea}
>   Won't somebody *please* think of the maintainers?!
> \end{plea}


Larry does, which is why it is not allowed  :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 27 Feb 2003 21:18:56 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Brute Force Golf Solver
Message-Id: <3E5EC710.2C1B1CC2@earthlink.net>

Quantum Mechanic wrote:
> 
> Under the auspices of "There are no stupid questions"...
> 
> Has anyone done any work on a brute force golf solver?
> 
> I'm not very good at golf, but I like the idea of tinkering with a
> program that writes programs.
> 
> I envision a semi-intelligent program that knows about the most useful
> command line options, builtin functions and operators, and tries to
> generate valid (i.e., "perl -c") programs, runs them against test
> input, and validates the output against the expected output.

*All* command line options, builtin functions, and operators are useful.

A better way of doing golf is to write a golf-ifyer, which takes another
(working) program, uses the B:: modules to examine it, and uses a set of
hueristics to find program structures which it "knows" can be written
using less perl code, replaces them with the smaller versions, then
deparses the result in a way that puts in no extraneous whitespace.

Also, it would try to replace variables with single letter names.

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


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

Date: Thu, 27 Feb 2003 20:41:53 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Brute Force Golf Solver
Message-Id: <Xns932FDC9D2968sdn.comcast@216.166.71.239>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

quantum_mechanic_1964@yahoo.com (Quantum Mechanic) wrote in 
news:f233f2f0.0302271109.12de30e6@posting.google.com:

> Under the auspices of "There are no stupid questions"...
> 
> Has anyone done any work on a brute force golf solver?

I don't have an answer to your question, but...

Is anyone holding any golf contests anymore, now that 
perlgolf.sourceforge.net seems to have dropped off the planet?

Just curious.

- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA+AwUBPl7MR2PeouIeTNHoEQKBTgCYn8UycutHbWIzHFc/pEvnls9x7wCgsCY1
7lOJZ/tB21z2s2ICBclDkVI=
=xHsr
-----END PGP SIGNATURE-----


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

Date: Fri, 28 Feb 2003 03:30:02 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Brute Force Golf Solver
Message-Id: <slrnb5tltq.kmb.mgjv@verbruggen.comdyn.com.au>

On Thu, 27 Feb 2003 20:41:53 -0600,
	Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:
> quantum_mechanic_1964@yahoo.com (Quantum Mechanic) wrote in 
> news:f233f2f0.0302271109.12de30e6@posting.google.com:

>> Has anyone done any work on a brute force golf solver?

> Is anyone holding any golf contests anymore, now that 
> perlgolf.sourceforge.net seems to have dropped off the planet?

What do you mean, "dropped off the planet"?

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | What's another word for Thesaurus?
                        | 


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

Date: Fri, 28 Feb 2003 03:01:19 GMT
From: "Barty" <me@me.com>
Subject: Counting matches in a regular expression
Message-Id: <3iA7a.207$W%5.39096@news1.telusplanet.net>

Hi everyone, I would be grateful if someone could fill in the blanks for me
on this..  I can't seem to find the answer...

I need to quickly find the number of matches of six numbers within a string.
Yes, this is a lottery-type question..

So say I have 1,4,10,15,20,44 and I want to find out how many of those match
in a string: |4|14|20|24|40|44|.  Is there a way to do this in one regular
expression?

Thanks, Ian




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

Date: Fri, 28 Feb 2003 04:16:27 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Counting matches in a regular expression
Message-Id: <3e5ee1e2.14475852@news.erols.com>

"Barty" <me@me.com> wrote:

: I need to quickly find the number of matches of six numbers within a string.
: 
: So say I have 1,4,10,15,20,44 and I want to find out how many of those match
: in a string: |4|14|20|24|40|44|.  Is there a way to do this in one regular
: expression?

That's a task better suited to split() and the techniques described in
perlfaq4, "How do I compute the intersection of two arrays?"



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

Date: Fri, 28 Feb 2003 00:06:22 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Counting matches in a regular expression
Message-Id: <3E5EEE4E.821A2154@earthlink.net>

Barty wrote:
> 
> Hi everyone, I would be grateful if someone could fill in the blanks
> for me on this..  I can't seem to find the answer...
> 
> I need to quickly find the number of matches of six numbers within a
> string. Yes, this is a lottery-type question..
> 
> So say I have 1,4,10,15,20,44 and I want to find out how many of those
> match in a string: |4|14|20|24|40|44|.  Is there a way to do this in
> one regular expression?

my @nums = (1,4,10,15,20,44);
my $data = "|4|14|20|24|40|44|";
my $count = do {
   local $" = "|";
   () = $data =~ /\b(@nums)\b/g;
};

This isn't necessarily the most efficient way, but it does satisfy your
requirement of being done in one regular expression.

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


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

Date: Thu, 27 Feb 2003 20:43:24 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: driving me nuts!
Message-Id: <Xns932FDCDEB40E5sdn.comcast@216.166.71.239>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

robert.reilly@gecapital.com (Robert Reilly) wrote in 
news:e955026c.0302271109.547fedc0@posting.google.com:

> All, I have a program that i want to assaign a value to a scalar which
> has a scalar name appended to it i.e
> 
> $bar = 'server1';
> 
> $foo = getserv();
> 
> what I want to do is append the $bar to the scalar $foo so I would
> have $fooserver1 of $foo_server1.
> any help is appreciated.

This is generally a Bad Thing to do, unless you Really Know What You're 
Doing.

What's your ultimate goal here?

- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPl7Mn2PeouIeTNHoEQIl+wCfRTZ4zM0AKIEXg/3D0eEez+6tbM8AnjJt
N8o7FsOJICt55qWWv/7OEs/t
=tKBu
-----END PGP SIGNATURE-----


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

Date: 27 Feb 2003 18:07:17 -0800
From: borischow@yahoo.com (Boris)
Subject: How to sort by field in objects?
Message-Id: <5304d2cf.0302271807.671b9f01@posting.google.com>

Dear all,

I would like to create many objects and would like to sort by one of
the field there.

---
my person{PETER} = Employee-> {
   surname => "Bruce",
   age     => 20,
   weight  => 50 
};

my person{HENRY} = Employee-> {
   surname => "MCGEE",
   age     => 25,
   weight  => 51 
};

--
I would like to get a sorted list of objects by "age" ( or by "weight"
). Is there any built-in function (or package) to do so?

Many thanks!!!

Best regards,
Boris


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

Date: Fri, 28 Feb 2003 13:27:25 +1100
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: How to sort by field in objects?
Message-Id: <bigiain-B2F683.13272528022003@nasal.pacific.net.au>

In article <5304d2cf.0302271807.671b9f01@posting.google.com>,
 borischow@yahoo.com (Boris) wrote:

> Dear all,
> 
> I would like to create many objects and would like to sort by one of
> the field there.
> 
> ---
> my person{PETER} = Employee-> {
>    surname => "Bruce",
>    age     => 20,
>    weight  => 50 
> };
> 
> my person{HENRY} = Employee-> {
>    surname => "MCGEE",
>    age     => 25,
>    weight  => 51 
> };
> 
> --
> I would like to get a sorted list of objects by "age" ( or by "weight"
> ). Is there any built-in function (or package) to do so?

You know, this is just a wild stab in the dark, but do you suppose 
looking at the doco for the "sort" finction might be worthwhile here?

:-)

big


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

Date: Fri, 28 Feb 2003 03:34:26 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: How to sort by field in objects?
Message-Id: <slrnb5tm62.kmb.mgjv@verbruggen.comdyn.com.au>

On 27 Feb 2003 18:07:17 -0800,
	Boris <borischow@yahoo.com> wrote:
> Dear all,
> 
> I would like to create many objects and would like to sort by one of
> the field there.

The perlfunc documentation on sort has information, and the Perl FAQ
also contains information about how to sort complex data structures.

You can read the perlfunc entry on sort with

$ perldoc -f sort

and the FAQ bits you want to read can be viewed with

$ perldoc -q sort

> my person{PETER} = Employee-> {
>    surname => "Bruce",
>    age     => 20,
>    weight  => 50 
> };

This is not Perl code. What is it?

Martien
-- 
                        | 
Martien Verbruggen      | Never hire a poor lawyer. Never buy from a
Trading Post Australia  | rich salesperson.
                        | 


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

Date: Thu, 27 Feb 2003 20:46:59 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: newbie question
Message-Id: <Xns932FDD7A5EE76sdn.comcast@216.166.71.239>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Ryan Shondell <shondell@cis.ohio-state.edu> wrote in 
news:xcwznohmhzz.fsf@psi.cis.ohio-state.edu:

> Ditch the C-style for loop.
> 
> # print everything in @var
> 
> foreach my $index (@var) {
>   print $index;
> }

Nitpick:  In this case, $index is a very poor choice of variable name, as 
the variable takes on the *values* of the array in turn, not the *indexes*.  
For what it's worth:

    foreach my $value (@var) {
        print $value;
    }

- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPl7NeWPeouIeTNHoEQKn2gCeKEvReLu/cXc30/De2kVKXNn2vhIAnjod
G/uWt6SYzQUfTpNdRIbjuFzs
=WP1A
-----END PGP SIGNATURE-----


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

Date: Fri, 28 Feb 2003 03:13:44 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: newbie question
Message-Id: <ItA7a.607638$HG.111192467@news4.srv.hcvlny.cv.net>


"nono" <nono@nono.no> wrote in message
news:f06t5v03tvca84iit0bfl8p0b8g8quli6a@4ax.com...
--snip--
>
> for($index=0; $index <=4; $index++)
> {
> ???    print $var.$index; ???
> }
>

Refer to perldoc -q "variable name" for an explanation of why this is a
bad idea.

Bill




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

Date: 27 Feb 2003 22:23:53 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: newbie question
Message-Id: <xcw7kblozp2.fsf@psi.cis.ohio-state.edu>

"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> writes:

> Ryan Shondell <shondell@cis.ohio-state.edu> wrote in 
> news:xcwznohmhzz.fsf@psi.cis.ohio-state.edu:
> 
> > Ditch the C-style for loop.
> > 
> > # print everything in @var
> > 
> > foreach my $index (@var) {
> >   print $index;
> > }
> 
> Nitpick:  In this case, $index is a very poor choice of variable name, as 
> the variable takes on the *values* of the array in turn, not the *indexes*.  

*sigh*

Yeah, you're absolutely correct. Sometimes the synapses fire sideways,
I swear. :-)

-- 
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'


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

Date: Fri, 28 Feb 2003 04:11:46 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: newbie question
Message-Id: <6kB7a.40051$ep5.37354@nwrddc02.gnilink.net>

nono wrote:
> let's say I have these variables:
>
> $var0 = 55
> $var1 = 66
> $var2 = 77
> $var3 = 88
> $var4 = 99

A much better way is to use an array:

my @var = (55, 66, 77, 88, 99);

> how do I print them one by one depending on what the $index is in the
> following for cycle ?
> I mean when $index = 0, print $var0 , when $index is 3 print $var3

Then you can simply use

> for($index=0; $index <=4; $index++)

foreach (@var)

> {
> ???    print $var.$index; ???

print $_;

Or if you insist on explicit indexes then take your old for line and make
the print line

print $var[$i];

> }





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

Date: Fri, 28 Feb 2003 04:17:35 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: newbie question
Message-Id: <zpB7a.40070$ep5.27634@nwrddc02.gnilink.net>

Mina Naguib wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> nono wrote:
>> let's say I have these variables:
>>
>> $var0 = 55
>> $var1 = 66
>> $var2 = 77
>> $var3 = 88
>> $var4 = 99
>>
>> how do I print them one by one depending on what the $index is in the
>> following for cycle ?
>> I mean when $index = 0, print $var0 , when $index is 3 print $var3
>
> You should really consider using an array instead of multiple
> variables like so.
[example snipped]

Yes, that is the way to go.

> However, if you do insist on using your logic, then here's how you can
[Example with Symbolic References deleted]

No, you don't.
Pointing someone who is so inexperienced that he can't even create a
meaningful subject line to symbolic references is A Bad Thing.
Doing so without even mentioning that they are bad and without pointing to
the proper FAQ entry is malicious.

jue




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

Date: Thu, 27 Feb 2003 22:15:42 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie: Trouble with time() from "learning perl" book example...please help explain?
Message-Id: <slrnb5toje.26v.tadmc@magna.augustmail.com>

cayenne <chilecayenne@yahoo.com> wrote:

> dbmclost (%last_good);
        ^^
        ^^

> foreach $name (sort keys (%last_good)) {
>     $when = $last_good{$namd};
                            ^^
                            ^^

    Do not re-type Perl code
        Use copy/paste or your editor's "import" function rather than
        attempting to type in your code. If you make a typo you will get
        followups about your typos instead of about the question you are
        trying to get answered.


Like this one.

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 28 Feb 2003 04:46:37 GMT
From: lewart@uiuc.edu (Daniel S. Lewart)
Subject: Re: perl expect, vt102, and sending a function key.
Message-Id: <NQB7a.4633$o7.48428@vixen.cso.uiuc.edu>

jkw@carspot.com (John) writes:

> This is what I'm currently doing for F3.
> my $function_key = "\e[OR";
> $exp->send( $function_key );
> The above will send 0x1b 0x5b 0x4f 0x52. I'm assume those are the
> correct codes.
> ...
> Any help would be highly appreciated.

Question your assumptions, especially when they are wrong:
	my $function_key = "\eOR";	# F3

Daniel Lewart
lewart@uiuc.edu


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 4638
***************************************


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