[21940] in Perl-Users-Digest
Perl-Users Digest, Issue: 4162 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 22 14:10:59 2002
Date: Fri, 22 Nov 2002 11:10:13 -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 Fri, 22 Nov 2002 Volume: 10 Number: 4162
Today's topics:
Re: shtml and Perl <stevenm@blackwater-pacific.com>
Re: shtml and Perl <tjalbout@hotmail.com>
Re: shtml and Perl <usenet@dwall.fastmail.fm>
Re: Simple array question <barryk2@delete_me.mts.net>
Re: Simple array question <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Simple array question <perl-dvd@ldschat.com>
Re: Simple array question <jurgenex@hotmail.com>
Re: Simple array question <nobull@mail.com>
Re: Simple array question <perl-dvd@ldschat.com>
Re: Simple array question <nobull@mail.com>
Re: Sort non-key in a Hash of Hash <perl-dvd@ldschat.com>
Re: split /(\d\d)/, $_, 3 may return 5 elements - why? <paladin@techmonkeys.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 22 Nov 2002 07:54:08 -0800
From: Steven May <stevenm@blackwater-pacific.com>
Subject: Re: shtml and Perl
Message-Id: <arljm0$2pk$1@quark.scn.rain.com>
Talid wrote:
> Okay so the best way is to get the perl script to run the other perl script.
> So to convert:
> <!--#include virtual="test.pl?info"-->
> Would I use:
> $timeleft = do("MKCountDown.pl?christmas");
> display('signup.html', { lists => $data, timeleft => $timeleft });
> .
> I'm not having much success with this.
>
> Thanks for the help!
> -t
> "Steven May" <stevenm@blackwater-pacific.com> wrote in message
> news:arkl9t$9pd$1@quark.scn.rain.com...
>
>>Steven May wrote:
>>
>>>News wrote:
>>>
>>>
>>>>Got a question, I have a perl script that calls a shtml file.
>>>>In the shtml file I have a "<!--#include virtual= " function. If I
>>>>run the
>>>>shtml file by itself, it works fine but if I run it through the perl
>>>>script,
>>>>the include doesn't work.
>>>>Any ideas? Am I missing a server config?
>>>>
>>>>Thanks!
>>>>-T
>>>>
>>>>
>>>
>>>Not really a Perl question,
^^^^^^^^^^^^^^^^^^^^^^^^^^
Enough said on this post in this newsgroup.
Please read the Apache documnentation, you'll be glad you did.
s
------------------------------
Date: Fri, 22 Nov 2002 17:35:21 GMT
From: "Talid" <tjalbout@hotmail.com>
Subject: Re: shtml and Perl
Message-Id: <tVtD9.62292$ka.1835431@news1.calgary.shaw.ca>
That would be fine if I was running apache :)
I'm using Abyss X1 on win32 machine.
"Steven May" <stevenm@blackwater-pacific.com> wrote in message
news:arljm0$2pk$1@quark.scn.rain.com...
> Talid wrote:
> > Okay so the best way is to get the perl script to run the other perl
script.
> > So to convert:
> > <!--#include virtual="test.pl?info"-->
> > Would I use:
> > $timeleft = do("MKCountDown.pl?christmas");
> > display('signup.html', { lists => $data, timeleft =>
$timeleft });
> > .
> > I'm not having much success with this.
> >
> > Thanks for the help!
> > -t
> > "Steven May" <stevenm@blackwater-pacific.com> wrote in message
> > news:arkl9t$9pd$1@quark.scn.rain.com...
> >
> >>Steven May wrote:
> >>
> >>>News wrote:
> >>>
> >>>
> >>>>Got a question, I have a perl script that calls a shtml file.
> >>>>In the shtml file I have a "<!--#include virtual= " function. If I
> >>>>run the
> >>>>shtml file by itself, it works fine but if I run it through the perl
> >>>>script,
> >>>>the include doesn't work.
> >>>>Any ideas? Am I missing a server config?
> >>>>
> >>>>Thanks!
> >>>>-T
> >>>>
> >>>>
> >>>
> >>>Not really a Perl question,
> ^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Enough said on this post in this newsgroup.
>
> Please read the Apache documnentation, you'll be glad you did.
>
> s
>
>
------------------------------
Date: Fri, 22 Nov 2002 18:34:57 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: shtml and Perl
Message-Id: <Xns92CE8A2B5C6CEdkwwashere@216.168.3.30>
News <tjalbout@hotmail.com> wrote on 21 Nov 2002:
> Got a question, I have a perl script that calls a shtml file.
> In the shtml file I have a "<!--#include virtual= " function. If
> I run the shtml file by itself, it works fine but if I run it
> through the perl script, the include doesn't work.
> Any ideas? Am I missing a server config?
Here's a suggestion: crosspost your questions instead of multiposting
them. You have followups here and in alt.perl, but they're in
completely different threads.
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Fri, 22 Nov 2002 08:20:44 -0600
From: godzilla <barryk2@delete_me.mts.net>
Subject: Re: Simple array question
Message-Id: <MPG.1847f937a119c22c98975a@east.usenetserver.com>
In article <hkBz9.485813$o.6605804@news1.west.cox.net>, BigB@hotmail.com
says...
> I have an array with, say 100 elements. I want to check to see if any of the
> elements matches a particular string. For example (a shorter array):
>
> @array = ('red','white','blue');
>
> And I want to know if the array contains the string 'white' as one of the
> elements. I know how to do this with a foreach loop and comparing each
> element,
>
> foreach $item(@array){
> if ($item eq 'white'){
> ## do something
> }
> }
>
> But is there an easier (faster) way than looping through the whole array?
>
@array = ('red','white','blue');
if ( 1 > grep /white/,@array ) {
print "No\n";
} # IF
else {
print "Yes\n";
} # ELSE
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Fri, 22 Nov 2002 14:24:46 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Simple array question
Message-Id: <arlene$bna$3@korweta.task.gda.pl>
In article <MPG.1847f937a119c22c98975a@east.usenetserver.com>, godzilla wrote:
> In article <hkBz9.485813$o.6605804@news1.west.cox.net>, BigB@hotmail.com
> says...
>> I have an array with, say 100 elements. I want to check to see if any of the
>> elements matches a particular string. For example (a shorter array):
>>
>> @array = ('red','white','blue');
>>
>> And I want to know if the array contains the string 'white' as one of the
>> elements. I know how to do this with a foreach loop and comparing each
>> element,
>>
>> foreach $item(@array){
>> if ($item eq 'white'){
>> ## do something
>> }
>> }
>>
>> But is there an easier (faster) way than looping through the whole array?
>>
>
>
> @array = ('red','white','blue');
>
> if ( 1 > grep /white/,@array ) {
^^^^
Just switch Yes and No and you can get rid of that.
> print "No\n";
> } # IF
> else {
> print "Yes\n";
> } # ELSE
Or perhaps:
print "Yes\n" if grep $_ eq 'white', @array;
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Fri, 22 Nov 2002 08:15:04 -0700
From: "David" <perl-dvd@ldschat.com>
Subject: Re: Simple array question
Message-Id: <ZKrD9.3641$EY.2893@fe01>
"Brian" <BigB@hotmail.com> wrote in message
news:hkBz9.485813$o.6605804@news1.west.cox.net...
> I have an array with, say 100 elements. I want to check to see if any
of the
> elements matches a particular string. For example (a shorter array):
>
> @array = ('red','white','blue');
>
> And I want to know if the array contains the string 'white' as one of
the
> elements. I know how to do this with a foreach loop and comparing each
> element,
>
> foreach $item(@array){
> if ($item eq 'white'){
> ## do something
> }
> }
>
> But is there an easier (faster) way than looping through the whole
array?
Yes,
my @array = ('red','white','blue');
if (grep(/white/, @array)){
# do your stuff
}
Note that the /white/ is a regular expression.
Regards,
David
------------------------------
Date: Fri, 22 Nov 2002 16:54:07 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Simple array question
Message-Id: <PitD9.70$Ho2.8@nwrddc04.gnilink.net>
Brian wrote:
> I have an array with, say 100 elements. I want to check to see if any
> of the elements matches a particular string. For example (a shorter
> array):
To answer your question: use the grep function, details see "perldoc -f
grep"
But probably you should read
perldoc -q contains: "How can I tell whether a list or array contains a
certain element?"
Chances are an array is not the right data structure to begin with.
jue
------------------------------
Date: 22 Nov 2002 17:05:53 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Simple array question
Message-Id: <u9el9dr0um.fsf@wcl-l.bham.ac.uk>
"David" <perl-dvd@ldschat.com> writes:
> > And I want to know if the array contains the string 'white' as one
> > of the elements.
> if (grep(/white/, @array)){
> Note that the /white/ is a regular expression.
Note also that is is the wrong regular expression.
The right regular expression to see if $_ is equal to 'white' would be:
/\Awhite\Z/
Better still, for checking string equality, use the string equality
operator:
$_ eq 'white'
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 22 Nov 2002 10:25:30 -0700
From: "David" <perl-dvd@ldschat.com>
Subject: Re: Simple array question
Message-Id: <eFtD9.3689$EY.290@fe01>
"Brian McCauley" <nobull@mail.com> wrote in message
news:u9el9dr0um.fsf@wcl-l.bham.ac.uk...
> "David" <perl-dvd@ldschat.com> writes:
>
> > > And I want to know if the array contains the string 'white' as one
> > > of the elements.
>
> > if (grep(/white/, @array)){
>
> > Note that the /white/ is a regular expression.
>
> Note also that is is the wrong regular expression.
>
> The right regular expression to see if $_ is equal to 'white' would
be:
> /\Awhite\Z/
>
> Better still, for checking string equality, use the string equality
> operator:
>
> $_ eq 'white'
>
Yes or
/^white$/
but I figured once he knew it was a regular expression, he would be able
to form it however he wished.
David
------------------------------
Date: 22 Nov 2002 17:48:36 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Simple array question
Message-Id: <u9y97lpkaz.fsf@wcl-l.bham.ac.uk>
"David" <perl-dvd@ldschat.com> writes:
> "Brian McCauley" <nobull@mail.com> wrote in message
> news:u9el9dr0um.fsf@wcl-l.bham.ac.uk...
> >
> > The right regular expression to see if $_ is equal to 'white' would
> be:
> > /\Awhite\Z/
>
> Yes or
>
> /^white$/
Actually that not only matches "white" but also "white\n" which isn't
exactly what the OP asked for (but chances are it doesn't matter).
> but I figured once he knew it was a regular expression, he would be able
> to form it however he wished.
If you are going to give a partial answer in order to make the OP do
some work for themselves then you should not present it as being a
complete answer.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 22 Nov 2002 08:25:45 -0700
From: "David" <perl-dvd@ldschat.com>
Subject: Re: Sort non-key in a Hash of Hash
Message-Id: <ZUrD9.3644$EY.2817@fe01>
"Humex" <member@mainframeforum.com> wrote in message
news:3dcee068$1_8@news.onlynews.com...
> [FONT=courier new]
>
> I am trying to sort the following Hash of Hash data by the non-key
> "LastName":
>
> *******************************************************
>
> %People = ( dande001 => {FirstName=>"Dominique",
LastName=>"Anderson"},
> jwash001 => {FirstName=>"Jamar", LastName=>"Washington"}, schan001 =>
> {FirstName=>"Sarah", LastName=>"Chang"}, ddunn001 =>
> {FirstName=>"Dorthy", LastName=>"Dunn"}, tfraz001 =>
> {FirstName=>"Trevor", LastName=>"Frazier"}, lgome001 =>
> {FirstName=>"Laticia", LastName=>"Gomez"}, chern001 =>
> {FirstName=>"Carlos", LastName=>"Hernandez"}, mlong001 =>
> {FirstName=>"Mary", LastName=>"Long"}, fsmit001 => {FirstName=>"Fred",
> LastName=>"Smith"}, kwhit001 => {FirstName=>"Karl",
LastName=>"White"},
> jvanc001 => {FirstName=>"James", LastName=>"Vance"}, nmurr001 =>
> {FirstName=>"Nancy", LastName=>"Murray"}, gstee001 =>
> {FirstName=>"Greg", LastName=>"Steel"}, tlore001 =>
{FirstName=>"Tracy",
> LastName=>"Lorenzo"}, hbalm001 => {FirstName=>"Heather",
> LastName=>"Balmer"}, gcall001 => {FirstName=>"Grace",
> LastName=>"Callaway"}, jwang001 => {FirstName=>"John",
> LastName=>"Wang"}, bflip001 => {FirstName=>"Barry",
> LastName=>"Flipmon"}, lmaca001 => {FirstName=>"Lisa",
> LastName=>"MacAniney"}, bbuck001 => {FirstName=>"Brian",
> LastName=>"Bucknell"} );
>
> *******************************************************
>
> I tried everything I can think of the sort by either of the non-keys
> ("FirstName" or "LastName"), but every sort that I've found will only
> sort by the key (which is the persons ID e.g. 'bbuck001'). I've been
> working on this for hours and haven't been able to find a solution.
Any
> help would be greatly appreciated. Thanks in advance!
>
> -Humex
Try this:
##############################
foreach my $key(sort{$People{$a}{'LastName'} cmp
$People{$b}{'LastName'}}(keys(%People))){
print "$People{$key}{'FirstName'} $People{$key}{'LastName'}\n";
}
# has been tested
##############################
Regards,
David
------------------------------
Date: Fri, 22 Nov 2002 16:45:16 GMT
From: Alan Cameron <paladin@techmonkeys.org>
Subject: Re: split /(\d\d)/, $_, 3 may return 5 elements - why?
Message-Id: <1pmlra.uk9.ln@paladin>
On Fri, 22 Nov 2002 10:26:14 GMT, Jim Bowie <cjavajim@yahoo.com> wrote:
> Why does `split' yield five elements when a maximum of three was
> specified in the following code?
[snip]
> my @fields = split /(\d\d)/, $_, 3;
[snip]
Take the string "12" as an example.
When you split it on /\d\d/ the string before the first occurrence of
\d\d is "", then there is the delimiter, "12", and then after the
delimiter is the string "". So you are returned the list ("","") (ie.
The strings before and after \d\d in the string "12").
Because you are splitting on /(\d\d)/ you are telling it to return you
any \d\d that it splits on, so you get ("", "12, "").
The logic is similar for all your other cases. It looks like split is
not what you want to use for what you are trying to do.
Perhaps (@fields) = $_ =~ /^(\d\d)(\d\d)(.*)$/; will get you what you want.
--
Mother is the name for GOD on the lips and
hearts of all children. - Eric Draven
------------------------------
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 4162
***************************************