[17421] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4841 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 8 00:10:28 2000

Date: Tue, 7 Nov 2000 21:10:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973660214-v9-i4841@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 7 Nov 2000     Volume: 9 Number: 4841

Today's topics:
    Re: percent-underscore: %_ <mcdonabNO@SPAMyahoo.com>
    Re: percent-underscore: %_ <ianb@ot.com.au>
    Re: percent-underscore: %_ (Mark-Jason Dominus)
    Re: percent-underscore: %_ (Mark-Jason Dominus)
    Re: percent-underscore: %_ (Mark-Jason Dominus)
    Re: Pushing a hash on to a stack... (Martien Verbruggen)
    Re: Pushing a hash on to a stack... (Gwyn Judd)
    Re: Pushing a hash on to a stack... (Mark-Jason Dominus)
    Re: Q: Getting program line number? - Thanks (Gwyn Judd)
    Re: Q: Getting program line number? - Thanks <joe+usenet@sunstarsys.com>
    Re: Q: Getting program line number? (Ilya Zakharevich)
    Re: returning a true value is FUN! (was Re: Log.pm did  (Tad McClellan)
        Site test <bcanning@netresults-media.co.uk>
    Re: Site test <bwalton@rochester.rr.com>
        Sort <mscozzari@ameritech.net>
    Re: Sort (Mark-Jason Dominus)
    Re: Sorting hash of hashes by value (Gwyn Judd)
    Re: strip html tags from string $text (Tad McClellan)
    Re: Tutorial on strings in perl? <elephant@squirrelgroup.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 7 Nov 2000 18:32:28 -0800
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: percent-underscore: %_
Message-Id: <YX2O5.19443$Wq1.9317405@nnrp5-w.sbc.net>


> > >
> > > what is the formal perl name of the ("scratch") variable represented
by %_?
> > > i can't seem to locate this information in the perldocs.
> >
> > Since perlvar has no listing for %_ I don't know what you mean.
>
> I don't know what %_ is either, but evidently it's real:
>
> % perl -wle 'my %_'
> Can't use global %_ in "my" at -e line 1, near "my %_"
> Execution of -e aborted due to compilation errors.
>
> So what is it?
>

well, it's real. the documentation for XML::Parser, in describing the
'Stream' style defines the StartTag sub in this way...

"StartTag
Called for every start tag with a second parameter of the element type. The
$_ variable will contain a copy of the tag and the %_ variable will contain
attribute values supplied for that element."

i don't really understand the responses that people are posting to my
question though. why is %_ not in perlvar???

brian





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

Date: Wed, 08 Nov 2000 13:06:26 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: percent-underscore: %_
Message-Id: <3A08B521.830DAF25@ot.com.au>

Brian McDonald wrote:

> "StartTag
> Called for every start tag with a second parameter of the element type. The
> $_ variable will contain a copy of the tag and the %_ variable will contain
> attribute values supplied for that element."

So, XML::Parser uses it...that doesn't contradict anything that the other
posters have said.

> i don't really understand the responses that people are posting to my
> question though. why is %_ not in perlvar???

Well, perhaps it just doesn't have any special meaning in Perl. Maybe it's
just used by that package. There's one way to find out. In the source code for
XML::Parser:

--------------------------------
sub Start {
  no strict 'refs';
  my $expat = shift;
  my $type = shift;

  doText($expat);
  $_ = "<$type";

  %_ = @_;
  while (@_) {
    $_ .= ' ' . shift() . '="' . shift() . '"';
  }
  $_ .= '>';
---------------------------------
=item * StartTag

Called for every start tag with a second parameter of the element type. The $_

variable will contain a copy of the tag and the %_ variable will contain
attribute values supplied for that element.
---------------------------------

The package simply puts values in there itself.  I assume it uses %_ due to
its similarity to @_, and the fact that it is global and yet won't get
affected by 'use strict' or clash with names others are likely to have used
already.

It doesn't get set implicitly, and it doesn't appear to be intended for
implicit use.

Regards,


Ian




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

Date: Wed, 08 Nov 2000 04:38:26 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: percent-underscore: %_
Message-Id: <3a08d8c1.795$23c@news.op.net>

In article <Pine.GSO.4.21.0011072043170.11113-100000@crusoe.crusoe.net>,
Jeff Pinyan  <japhy@pobox.com> wrote:
>A punctuation variable held in the same typeglob as $_ and @_.  Such
>variables do not belong to a package.  

More precisely, they belong to the main package, and the unqualified
versions of the names are resolved to the main package regardless of
whether the default package is 'main'.
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Wed, 08 Nov 2000 04:41:19 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: percent-underscore: %_
Message-Id: <3a08d96f.7aa$264@news.op.net>


In article <slrn90hcjh.7ck.mgjv@verbruggen.comdyn.com.au>,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>[addition after supersede]
>Actually, having thought a bit more about this... I'm not even sure
>whether the typeglob really needs to exist, or whether the name itself
>is treate specially by Perl. Anyone reading this who does know?
>[end addition]

Typeglobs are created as needed, just like everything else.  
Creating ${"{"} is just the same as creating $blug.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Wed, 08 Nov 2000 04:45:48 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: percent-underscore: %_
Message-Id: <3a08da7b.7de$73@news.op.net>
Keywords: Dobbs, Judaism, conservation, savoy

In article <YX2O5.19443$Wq1.9317405@nnrp5-w.sbc.net>,
Brian McDonald <mcdonabNO@SPAMyahoo.com> wrote:
>i don't really understand the responses that people are posting to my
>question though. why is %_ not in perlvar???

Because it's not a Perl special variable.  There is nothing to
document.  What do you think it should say in perlvar?  "%_: There is
nothing special about this variable, but maybe some module uses it."

XML::Parser also uses the variable %XML::Parser::Built_In_Styles.  Do
you want this listed in perlvar also?  It could have the same
description: "%XML::Parser::Built_In_Styles: There is nothing special
about this variable, but maybe some module uses it."


-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Wed, 08 Nov 2000 02:22:47 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <slrn90he7p.7ck.mgjv@verbruggen.comdyn.com.au>

On 8 Nov 2000 01:57:05 GMT,
	Christopher Burke <craznar@hotmail.com> wrote:
> Can any perl experts emulate the following using the push/pop idea.
> 
> %{$fulldata[scalar @fulldata]} = %hash;
> 
> 
> Basically I want to be able to do this sort of thing...

What you want to do is read the perlref, perldsc and perllol
documentation.

> $hash{X} = 4;
> $hash{Y} = 5;
> # push %hash onto stack .....
> $hash{X} = 4;
> $hash{Y} = 5;
> # push %hash onto stack .....

You will need to create a new hash each time, or a new hash reference.
What you want to do, is create an array of hash references, where each
reference is one of those things you're pushing. But using push for
that only makes sens if you're doing this in a loop or something. If
it's linear code like that, you just do

#!/usr/local/bin/perl -l
use warnings;
use strict;

my @stack;

my $i = 0;
$stack[$i]{X} = 4;
$stack[$i]{Y} = 5;
$i++;
$stack[$i]{X} = 6;
$stack[$i]{Y} = 7;
$i++;
# etc..

print $stack[0]{X};
print $stack[0]{Y};
print $stack[1]{X};
print $stack[1]{Y};

Note that this last bit is not valid use for a formal stack. You push
things on, and you pop things off. You don't access elements directly.
But I'll keep using the term stack anyway, because Perl arrays can at
least be treated as one.

For a loop, it probably makes more sense to use a lexially scoped
hash, and then you actually push it on the stack.

#!/usr/local/bin/perl -l
use warnings;
use strict;

my @stack;

for (1 .. 18)
{
	my %hash;
	$hash{X} = $_ * 10 * @stack;
	$hash{Y} = $_ * 10 * @stack;
	push @stack, \%hash;
}

print "Got " . @stack . " elements";

foreach my $hash_ref (@stack)
{
	print $hash_ref->{X};
	print $hash_ref->{Y};
}

# OR

foreach my $index (0 .. $#stack)
{
	print $stack[$index]{X};
	print $stack[$index]{Y};
}

> And no - I don't want to use references.

What a silly attitude.  Why don't you use the things that are
specifically well suited for the job? How do you open files? Without
open()? Do you get into buildings through the windows?

Oh well. Suit yourself. 

You won't have any order, except what you impose yourself. You'll also
have to keep track of the number of things you put on the 'stack' [1]:

#!/usr/local/bin/perl -l
use warnings;
use strict;

my %stack;
my $stack_size;

for (1 .. 18)
{
	$stack{$_,'X'} = $_ * 10;
	$stack{$_,'Y'} = $_ * 20;
	$stack_size++;
}

foreach (1 .. $stack_size)
{
	print $stack{$_,'X'};
	print $stack{$_,'Y'};
}

Martien

[1] Of course, this has no longer any resemblance to a stack at all.
-- 
Martien Verbruggen              | 
Interactive Media Division      | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd.   | Then things get worse.
NSW, Australia                  | 


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

Date: Wed, 08 Nov 2000 02:51:54 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <slrn90hfu9.hbr.tjla@thislove.dyndns.org>

I was shocked! How could Christopher Burke <craznar@hotmail.com>
say such a terrible thing:
>Can any perl experts emulate the following using the push/pop idea.
>
>%{$fulldata[scalar @fulldata]} = %hash;

like this:

push @fulldata, \%hash;

>And no - I don't want to use references.

Why? (and if you really don't want to use references then you are
screwed)

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Hackers have kernel knowledge.


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

Date: Wed, 08 Nov 2000 04:35:02 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <3a08d7ec.758$101@news.op.net>
Keywords: Debby, impartial, paralysis, print

In article <8FE677620craznar@130.102.2.1>,
Christopher Burke <craznar@hotmail.com> wrote:
>And no - I don't want to use references.


Hi.  Can anyone help me?  I am looking for a large gray animal with
floppy ears and a long trunk.

No elephants, please.




-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Wed, 08 Nov 2000 02:17:13 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Q: Getting program line number? - Thanks
Message-Id: <slrn90hdt7.hbr.tjla@thislove.dyndns.org>

I was shocked! How could Joe Schaefer <joe+usenet@sunstarsys.com>
say such a terrible thing:

>Nor did I ;) - apparently she hasn't yet learned to use effectively use 'grep'.

She?

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Mad, adj.:
	Affected with a high degree of intellectual independence ...
		-- Ambrose Bierce, "The Devil's Dictionary"


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

Date: 07 Nov 2000 21:25:25 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Q: Getting program line number? - Thanks
Message-Id: <m3itpzdwtm.fsf@mumonkan.sunstarsys.com>

tjla@guvfybir.qlaqaf.bet (Gwyn Judd) writes:

> She?

An honest mistake, sorry about that. 
I'll learn from it ;)

-- 
Joe Schaefer


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

Date: 8 Nov 2000 03:03:07 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Q: Getting program line number?
Message-Id: <8uafpb$470$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to James Taylor 
<james@NOSPAM.demon.co.uk>],
who wrote in article <ant080147f7ffNdQ@oakseed.demon.co.uk>:
> > >Is there a similar way to get the error line number when you have
> > >wrapped a large chunk of code in an eval to trap errors?
> > >$@ seems to only contain the error message without the line number.

> Everything I try locally fails to reproduce error messages in $@ that
> DON'T have the line number, yet I am quite sure that scripts I have
> running on a remote web server have produced messages that unhelpfully
> do not have a line number.

  die "Hey, I'm die()ing without a line number!\n";

Ilya


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

Date: Tue, 7 Nov 2000 22:18:27 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: returning a true value is FUN! (was Re: Log.pm did not return a true value)
Message-Id: <slrn90hhg3.6hh.tadmc@magna.metronet.com>

On 07 Nov 2000 13:09:30 -0600, Ren Maddox <ren.maddox@tivoli.com> wrote:
>Jeff Pinyan <jeffp@crusoe.net> writes:
>
>> Ah, but those are somewhat more intuitive.  Why would assigning 0 to an
>> empty list return a true value?
>
>Is that rhetorical?
>
>If not, perldata(1) says:
>
>       List assignment in scalar context returns the number of
>       elements produced by the expression on the right side of
>       the assignment:


For any of you playing along at home:

   ()=0;

is a list assignment.

So Perl DWIMs the zero into a list

   ()=(0);


Since perl is looking for a "true" value, it is looking for
a Boolean, and all conditionals are evaluated in scalar
context...

 ... which, finally, leads to the perldata quote above.

Nice and twisty though :-)


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


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

Date: Wed, 8 Nov 2000 02:36:41 -0800
From: "Brian Canning" <bcanning@netresults-media.co.uk>
Subject: Site test
Message-Id: <8uae84$flv$1@newsg2.svr.pol.co.uk>



Is it possible to write a script that checks to see if a site up running?
I am having problems with my ISP in that I keep getting a 303 message. I
would like to write a script that tests to see if the site is running. Can I
test to see if I get a 303 error message and then log it? This script will
run of another site.


Brian





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

Date: Wed, 08 Nov 2000 04:19:12 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Site test
Message-Id: <3A08D512.C7BC5621@rochester.rr.com>

Brian Canning wrote:
> 
> Is it possible to write a script that checks to see if a site up running?
> I am having problems with my ISP in that I keep getting a 303 message. I
> would like to write a script that tests to see if the site is running. Can I
> test to see if I get a 303 error message and then log it? This script will
> run of another site.
> 
> Brian
Check out the Net::Ping module.
-- 
Bob Walton


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

Date: Tue, 7 Nov 2000 23:01:12 -0500
From: "Mike Scozzari" <mscozzari@ameritech.net>
Subject: Sort
Message-Id: <Sh4O5.53029$ph.264668@nntp0.chicago.il.ameritech.net>

I need to sort alphanumeric data such as A1, A3, B10, B4, C11, C12, C3 etc.
into a table format such as:

A1
A3
B4
B10
C3
C11
C12

The data has to be sorted first in alphabetical order then in numerical
sequence as above.

I have half this with @list, but that's as far as I've gotten because of the
numbering as it gets tangled up on the numbers such as C11, C12, C3 . Help,
help, help!

--
Michael E. Scozzari




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

Date: Wed, 08 Nov 2000 04:32:47 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Sort
Message-Id: <3a08d76e.734$2f2@news.op.net>
Keywords: Venusian, authoritative, furtive, militant

In article <Sh4O5.53029$ph.264668@nntp0.chicago.il.ameritech.net>,
Mike Scozzari <mscozzari@ameritech.net> wrote:
>I need to sort alphanumeric data such as A1, A3, B10, B4, C11, C12, C3 etc.
>into a table format such as:
>
>A1
>A3
>B4
>B10
>C3
>C11
>C12
>

sub alphanumerically {
  my @a = split /(\d+)/, $a;
  my @b = split /(\d+)/, $b;
  my $M = @a > @b ? @a : @b;
  my $res = 0;
  for (my $i = 0; $i < $M; $i++) {
    return -1 if ! defined $a[$i];
    return 1 if  ! defined $b[$i];
    if ($a[$i] =~ /\d/) {
      $res = $a[$i] <=> $b[$i];
    } else {
      $res = $a[$i] cmp $b[$i];
    }
    last if $res;
  }
  $res;
}

sort alphanumerically @items;
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Wed, 08 Nov 2000 02:22:59 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Sorting hash of hashes by value
Message-Id: <slrn90he81.hbr.tjla@thislove.dyndns.org>

I was shocked! How could Gwyn Judd <tjla@guvfybir.qlaqaf.bet>
say such a terrible thing:

>Of course, that only works as long as there are no duplicate number
>values. This version should guarantee unique hash keys:

Although, when you think about it, if you are doing this then what's the
point of using a hash? An array would be better, in this instanc, if all
you want to do is print out a sorted list. If you need to do hashy stuff
like look up values by key then the OP's solution is better.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The Microsoft Torque Wrench: what do you want to shear today?
-Malcolm Ray


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

Date: Tue, 7 Nov 2000 22:20:18 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: strip html tags from string $text
Message-Id: <slrn90hhji.6hh.tadmc@magna.metronet.com>

On Tue, 07 Nov 2000 22:04:57 GMT, dobrocinitelj@my-deja.com 
   <dobrocinitelj@my-deja.com> wrote:

>I have a string $text containing multiple lines of text, how can I
>strip all the html tags?


Like it says in the Perl FAQ:

   "How do I remove HTML from a string?"


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


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

Date: Wed, 8 Nov 2000 14:15:58 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: Tutorial on strings in perl?
Message-Id: <MPG.14737077677bef52989885@localhost>

Alex wrote ..
>Where can I find a good and comprehensive tutorial or faq for the handling
>and working with strings in perl?

you'll find a fair amount of information on the types of things that can 
be done with strings by typing the following on the command line

  perldoc -q string

for more information on the perldoc utility type the following on the 
command line

  perldoc perldoc

-- 
  jason -- elephant@squirrelgroup.com --


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

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 4841
**************************************


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