[24458] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6641 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 1 21:05:54 2004

Date: Tue, 1 Jun 2004 18:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 1 Jun 2004     Volume: 10 Number: 6641

Today's topics:
    Re: Beginner needs help with script :) <matthew.garrish@sympatico.ca>
    Re: Beginner problem to execute command <spamtrap@dot-app.org>
    Re: Beginner problem to execute command <krahnj@acm.org>
    Re: best way to count the number of rows in a multidime (Jack)
    Re: best way to count the number of rows in a multidime <noreply@gunnar.cc>
    Re: decode_entities possible bug? (Bill)
    Re: Filtering control characters from text <gnari@simnet.is>
    Re: Filtering control characters from text <krahnj@acm.org>
        How to test script that uses $EDITOR ? <please_post@nomail.edu>
    Re: How to test script that uses $EDITOR ? <usenet@morrow.me.uk>
        I am looking for PERL coder... <gp@nospm.hr>
        Import problem <jkrugman345@yahbitoo.com>
    Re: Import problem (Malcolm Dew-Jones)
    Re: Import problem ctcgag@hotmail.com
    Re: Invisible Array Loop Counter? <david@tvis.co.uk>
    Re: Invisible Array Loop Counter? <ittyspam@yahoo.com>
    Re: Invisible Array Loop Counter? <ittyspam@yahoo.com>
    Re: Invisible Array Loop Counter? <david@tvis.co.uk>
    Re: Invisible Array Loop Counter? <ittyspam@yahoo.com>
    Re: Invisible Array Loop Counter? <ittyspam@yahoo.com>
    Re: Invisible Array Loop Counter? <usenet@morrow.me.uk>
    Re: Invisible Array Loop Counter? <ittyspam@yahoo.com>
    Re: Invisible Array Loop Counter? <usenet@morrow.me.uk>
    Re: Invisible Array Loop Counter? ctcgag@hotmail.com
    Re: Invisible Array Loop Counter? <ittyspam@yahoo.com>
    Re: Invisible Array Loop Counter? <krahnj@acm.org>
    Re: Invisible Array Loop Counter? <krahnj@acm.org>
        LWP::UserAgent problem - 500 error (RP)
    Re: LWP::UserAgent problem - 500 error <matthew.garrish@sympatico.ca>
    Re: SSL connection to oracle using DBI? <nick@erkert.com>
    Re: Why is this upload script not working <remorse@partners.org>
    Re: Why is this upload script not working <usenet@morrow.me.uk>
        Window focus <please_post@nomail.edu>
    Re: YAPC::2004 <please_post@nomail.edu>
    Re: YAPC::2004 <uri@stemsystems.com>
    Re: YAPC::2004 <uri.guttman@fmr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 1 Jun 2004 19:28:48 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Beginner needs help with script :)
Message-Id: <Ji8vc.94053$tb4.3719050@news20.bellglobal.com>


"Player" <notachance@inhell.com> wrote in message
news:c9i8ol$4ho$1@news8.svr.pol.co.uk...
>
> Yes well excuse me for typing fast and over looking the obvious
>

A good summation of your stupidity.

Now go tell your wet-nurse about all the terrible bullies you ran into in
the sandbox today and see if she'll wipe your nose for you.

Matt




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

Date: Tue, 01 Jun 2004 16:00:28 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Beginner problem to execute command
Message-Id: <qfednQIY_cTDfSHdRVn-hg@adelphia.com>

Jürgen Exner wrote:

> Are you certain that you want to create two new folders the first named
> "`dirname" and the second whatever the content of $local is plus a
> trailing backquote? This looks odd to me.

Backticks work the same in a shell as they do in Perl. He might have
intended to run "dirname $local", and use its output as an argument to
"mkdir -p".

Or, he might have been hoping for multiple levels of interpolation in Perl -
which, as a another poster pointed out above, doesn't happen.

At any rate, I agree with the first part of your comment - Since both shell
and Perl use backticks and $ variables, it's impossible to do more than
guess at what level the OP expected things to be expanded.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Wed, 02 Jun 2004 00:28:01 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Beginner problem to execute command
Message-Id: <40BD1F0D.2324750C@acm.org>

"Jürgen Exner" wrote:
> 
> Petterson Mikael wrote:
> > $cmd="mkdir -p `dirname $local`";
> >  print("$cmd\n");
> >  system($cmd) || die ("Could not create new directory");
> 
> Is there a specific reason why you are forking a new shell instead of using
> Perl's buildin mkdir() function?
> 
> > Note: $local is equal to
> >
> /vobs/rbs/sw/rbssw1/boam_subsys/.metadata/.plugins/net.sourceforge.eclipsecc
> ase/pref_store.ini
> >
> > I am running this script as ./eclipse.pl
> >
> > Why do I get  "Could not create new directory"
> 
> Why don't you ask Perl?
>     system($cmd) or die ("Could not create new directory because $!");
> 
> Besides, did you check "perldoc -f system" about the return value of
> system()?
> It differs from what you might expect.

Yes, which is why "system() or die()" will not do what you apparently
expect it to do and neither will $!.  Have you read "perldoc -f system"
lately?


John
-- 
use Perl;
program
fulfillment


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

Date: 1 Jun 2004 11:54:17 -0700
From: jack_posemsky@yahoo.com (Jack)
Subject: Re: best way to count the number of rows in a multidimensional array
Message-Id: <209b7e58.0406011054.7c9365d@posting.google.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2i3ilnFh4ussU1@uni-berlin.de>...
> Jack wrote:
> > Wondering if anyone knows the best way to count the number of rows
> > in a multidimensional array.
> 
> What's a row?


Ok, what is the best way to count the number of *arrays* in a
multidimensional array.
-Jack


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

Date: Tue, 01 Jun 2004 22:06:40 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: best way to count the number of rows in a multidimensional array
Message-Id: <2i46bvFj0rfjU1@uni-berlin.de>

Jack wrote:
> Ok, what is the best way to count the number of *arrays* in a 
> multidimensional array.

Aha, so that's what you meant.

I suppose you can have a counter incremented while looping through the
AoA. "perldoc perldsc" or "perldoc perllol" should give you some
guidance how to dereference in order to reach the next level.

What's the overall structure of the AoA you want to explore? What have
you tried so far?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 1 Jun 2004 13:05:52 -0700
From: wherrera@lynxview.com (Bill)
Subject: Re: decode_entities possible bug?
Message-Id: <239ce42f.0406011205.d935a20@posting.google.com>

Gisle Aas <gisle@ActiveState.com> wrote in message 
> It is currently a compile time option when you build HTML-Parser
> whether it should support unicode entities or not.  If you enable this
> the &#8226; will be decoded.
> 

That explains it. Thanks Gisle.


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

Date: Tue, 1 Jun 2004 22:33:31 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Filtering control characters from text
Message-Id: <c9j04f$628$1@news.simnet.is>

"zzapper" <david@tvis.co.uk> wrote in message
news:lkoob0tsa3acoc0h104ng8827bn4f9cotm@4ax.com...
>
> I was going to ask how to do this, but goggled it instead but
>
> for your interest!
>
> $str =~ s/[^\x20-\x7F]//g;

and if you would consider DEL to be a control char:

    $str =~ s/[^\x20-\x7E]//g;
or
    $str =~ tr/\x20-\x7E//cd;

(note: [:cntrl:] does not contain \x7F)

gnari





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

Date: Wed, 02 Jun 2004 00:21:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Filtering control characters from text
Message-Id: <40BD1D84.2631813D@acm.org>

zzapper wrote:
> 
> On Tue, 1 Jun 2004 13:32:35 +0100, wrote:
> >>
> >> I was going to ask how to do this, but goggled it instead but
> >> for your interest!
> >>
> >> $str =~ s/[^\x20-\x7F]//g;
> >
> >I prefer this one, as it's easier to understand what it does:
> >
> >$str =~ s/[[:cntrl:]]//g;
> 
> That's cool but are they exactly equivalent?

No, but this is:

$str =~ s/[[:^graph:]]//g;


John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 1 Jun 2004 20:01:19 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: How to test script that uses $EDITOR ?
Message-Id: <c9inaf$74q$1@reader2.panix.com>




I have a script that at one point fires up $EDITOR (which can be
assumed to be Emacs for the purpose of this question) and gets some
deathless prose from the user.  I have no idea how to write a test
script that could automate this interaction.  Any suggestions would
be much appreciated.

By the way, what's the best way to write a command-line script so
that it is easily testable with test scripts?  As I have it written
now, my test script would have to mess around with pipes, but I
imagine that I could conceivably (maybe) do something with require
and -t ?

	-bill


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

Date: Wed, 2 Jun 2004 00:05:44 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: How to test script that uses $EDITOR ?
Message-Id: <c9j5ko$q38$2@wisteria.csv.warwick.ac.uk>


Quoth bill <please_post@nomail.edu>:
> 
> I have a script that at one point fires up $EDITOR (which can be
> assumed to be Emacs for the purpose of this question) and gets some
> deathless prose from the user.  I have no idea how to write a test
> script that could automate this interaction.  Any suggestions would
> be much appreciated.

Set $ENV{EDITOR} to a shell script that simply puts some text in the
file for the purposes of the test script.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: Wed, 2 Jun 2004 02:32:48 +0200
From: "PHP2" <gp@nospm.hr>
Subject: I am looking for PERL coder...
Message-Id: <c9j3ov$5nh$1@ls219.htnet.hr>

my friend has open bid by Rentacoder.com.. I expect that I am not bother any
peron here if I post info about that.. for someone it can be interesting
here..

Ivan



I am looking for PERL coder from Romania, Bulgaria, Russia or India for long
terms relationship. I have not large budget but I wish work with same coder
on few bids. Coder must have STRONG PERL and mod_perl experience.

I have some computer qnowledge and I wish learn during bids. Same coder who
win this bid, have from me additional educational set of 12 bids (12 months
x $25/per month for my mod_perl education).



My bid is active on https://www.rentacoder.com  web site with name: 'Perl
web education more advanced details' and you can send your bid offer.

I have by Rent a Coder still one bid active: 'Anti spam script'




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

Date: Tue, 1 Jun 2004 20:20:48 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Import problem
Message-Id: <c9iof0$7cl$1@reader2.panix.com>



If I do

use strict;
my $bar;
use Foo '%Bar';
BEGIN {
  $bar = \%Bar;
}

my script compiles fine, but when I try

use strict;
my $bar;
BEGIN {
  require Foo;
  Foo->import('%Bar');
  $bar = \%Bar;
}

I get a compilation error ('Global symbol "%Bar" requires explicit
package name...').  What's wrong with the second version?

TIA,

jill

-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: 1 Jun 2004 14:06:17 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Import problem
Message-Id: <40bcefc9@news.victoria.tc.ca>

J Krugman (jkrugman345@yahbitoo.com) wrote:


: If I do

: use strict;
: my $bar;
: use Foo '%Bar';
: BEGIN {
:   $bar = \%Bar;
: }

: my script compiles fine, but when I try

: use strict;
: my $bar;
: BEGIN {
    use vars qw(%Bar);  ### add this
:   require Foo;
:   Foo->import('%Bar');
:   $bar = \%Bar;
: }

Or try

 use strict;
 my $bar;
 BEGIN {
   BEGIN {
     require Foo;
     Foo->import('%Bar');
   }
   $bar = \%Bar;
 }


: I get a compilation error ('Global symbol "%Bar" requires explicit
: package name...').  What's wrong with the second version?


The export that happens during use Foo '%Bar'; has the same effect on the
variable as the use vars pragma.  Because use Foo happens at compile time,
therefore %Bar is known to perl when it finds it later in the code.  In
your second example you only do a require and import.  Because they happen
at run time, the %Bar is not known to perl at compile time.  So, either
run the require/import as part of the compile (i.e. BEGIN), or do
something else at compile time to make the variable known (i.e. use vars).

"our" would presumably work also.


--

(Paying) telecommute programming projects wanted.  Simply reply to this.



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

Date: 02 Jun 2004 00:01:48 GMT
From: ctcgag@hotmail.com
Subject: Re: Import problem
Message-Id: <20040601200148.610$CT@newsreader.com>

J Krugman <jkrugman345@yahbitoo.com> wrote:
> If I do
>
> use strict;
> my $bar;
> use Foo '%Bar';
> BEGIN {
>   $bar = \%Bar;
> }
>
> my script compiles fine, but when I try
>
> use strict;
> my $bar;
> BEGIN {
>   require Foo;
>   Foo->import('%Bar');
>   $bar = \%Bar;
> }

perldoc perlmod:
A "BEGIN" subroutine is executed as soon as possible, that is, the
moment it is completely defined, even before the rest of the containing
file is parsed.


So BEGIN doesn't execute line by line, but only once the whole thing is
compiled, i.e. not until the closing } is parsed.  So the %Bar dies during
the compiling of the BEGIN block because the import has not been executed
yet (although it has been compiled).  So move the \%Bar after the BEGIN
block.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 01 Jun 2004 19:24:12 +0100
From: zzapper <david@tvis.co.uk>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <dghpb058drt3qkv58clplkmpegg39se9dc@4ax.com>

On Tue, 1 Jun 2004 13:23:24 -0400, wrote:

>On Tue, 1 Jun 2004, zzapper wrote:
>
>> When you are looping thru an array
>> is there an "invisible" loop counter ?
>>
>> eg
>>
>> for (@somearray)
>> {
>>
>>
>> }
>
>Your question is extremely vague.  What exactly are you looking for?  And
>what do you mean by "loop counter"?
>
>Going through a foreach loop, if you do not assign the control variable
>(as you show above), the default $_ variable is used.  That is, within the
>loop body, $_ will be an alias to each subsequent element of the array.
>
>If you mean does Perl "invisibly" keep track of where it is in the loop,
>the answer to that is Yes.  Perl knows where in the array it is, and
>internally stores that information so it can move on to the next element
>in the array.
>
>If you mean does Perl "invisibly" keep track of the indices of the array,
>the answer is no.  Using the foreach loop you show above, you cannot
>determine the index of the current iteration.  To do that, use this loop
>instead:
>
>for (0..$#array){
>   #the index of the current iteration is $_
>   $element = $array[$_];
>}
>
>
>I hope this helps.  If not, be more explicit about what you are asking.
>
>Paul Lalli
Paul,
You pretty much answered my question, I was just naively hoping there
was a special variable

I mainly wanted it to conditionally delete certain elements eg

@t=@r=@q=qw(fred joe freddy sick);

for (@q)
{
delete $q[$cnt] if /fred/;
$cnt++;
}
print join "",@q;

# your solution

for (0..$#r)
{
delete $r[$_] if $r[$_] =~ /fred/;
}
print join "",@r;

# avoiding counters

for (@t)
{
$_="" if /fred/;
}
print join "",@t;


zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


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

Date: Tue, 1 Jun 2004 14:54:10 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040601144756.X18263@dishwasher.cs.rpi.edu>

On Tue, 1 Jun 2004, zzapper wrote:

> I mainly wanted it to conditionally delete certain elements eg
>
> @t=@r=@q=qw(fred joe freddy sick);
>
> for (@q)
> {
> delete $q[$cnt] if /fred/;
> $cnt++;
> }
> print join "",@q;

Don't modify an array while you're looping through the array.

>
> # your solution
>
> for (0..$#r)
> {
> delete $r[$_] if $r[$_] =~ /fred/;
> }
> print join "",@r;

Don't modify an array while you're looping through the array.

>
> # avoiding counters
>
> for (@t)
> {
> $_="" if /fred/;
> }
> print join "",@t;
>

Don't modify an array while you're looping through the array.


It's just a bad idea.  The results are ill-defined at best, and un-defined
at worst.  Something like this might suit you better:

@t = grep { !/fred/ } @t;
print @t;


(on another note, there is no reason to join a sequence of elements with
the empty string.  (Non-interpolated) arrays are printed in that manner by
default.  (Unless of course you've changed $,)

Paul Lalli


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

Date: Tue, 1 Jun 2004 15:22:20 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040601152107.F18263@dishwasher.cs.rpi.edu>

On Tue, 1 Jun 2004, Paul Lalli wrote:

> > # avoiding counters
> >
> > for (@t)
> > {
> > $_="" if /fred/;
> > }
> > print join "",@t;
> >
>
> Don't modify an array while you're looping through the array.
>

Actually, this one's okay.  Nothing wrong with changing the actual
element.  All of those notations actually meant "don't change the size of
the array while you're looping through the array".  Sorry for the lack of
clarity there.

Paul Lalli


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

Date: Tue, 01 Jun 2004 22:44:27 +0100
From: zzapper <david@tvis.co.uk>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <mptpb09rh76t9ekf36hnkihh6rd169uag0@4ax.com>

On Tue, 1 Jun 2004 15:22:20 -0400, wrote:

>On Tue, 1 Jun 2004, Paul Lalli wrote:
>
>> > # avoiding counters
>> >
>> > for (@t)
>> > {
>> > $_="" if /fred/;
>> > }
>> > print join "",@t;
>> >
>>
>> Don't modify an array while you're looping through the array.
>>
>
>Actually, this one's okay.  Nothing wrong with changing the actual
>element.  All of those notations actually meant "don't change the size of
>the array while you're looping through the array".  Sorry for the lack of
>clarity there.
>
>Paul Lalli

In fact none of the three methods actually shortened the array

@t=@r=@q=qw(fred joe freddy sick);

for (@q)
{
delete $q[$cnt] if /fred/;
$cnt++;
}
print @q;

for (0..$#r)
{
delete $r[$_] if $r[$_] =~ /fred/;
}
print @r;

for (@t)
{
$_="" if /fred/;
}
print @t;

print $#q;
print $#r;
print $#t;
zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


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

Date: Tue, 1 Jun 2004 18:47:08 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040601183534.N18263@dishwasher.cs.rpi.edu>

On Tue, 1 Jun 2004, zzapper wrote:

> In fact none of the three methods actually shortened the array
>
> @t=@r=@q=qw(fred joe freddy sick);
>
> for (@q)
> {
> delete $q[$cnt] if /fred/;
> $cnt++;
> }
> print @q;
>
> for (0..$#r)
> {
> delete $r[$_] if $r[$_] =~ /fred/;
> }
> print @r;
>
> for (@t)
> {
> $_="" if /fred/;
> }
> print @t;
>
> print $#q;
> print $#r;
> print $#t;

Running your code, for all three methods, we see that the sizes of the
arrays are still four.  However, printing out the values shows only the
'joe' and 'sick' elements.  Why is this?  Well, I modified your code to
print out the full contents of the arrays, using Data::Dumper.

use Data::Dumper;
@t=@r=@q=qw(fred joe freddy sick);
for (@q)
{
   delete $q[$cnt] if /fred/;
   $cnt++;
}
for (0..$#r)
{
   delete $r[$_] if $r[$_] =~ /fred/;
}
for (@t)
{
   $_="" if /fred/;
}

print Dumper(\@q)
print Dumper(\@r)
print Dumper(\@t);
__END__

And here's the output:

$VAR1 = [
          undef,
          'joe',
          ${\$VAR1->[0]},
          'sick'
        ];
$VAR1 = [
	  undef,
          'joe',
          ${\$VAR1->[0]},
          'sick'
        ];
$VAR1 = [
          '',
          'joe',
          '',
          'sick'
        ];

What we see here is that in the first method, the first element you tried
to delete actually became undef, and the third element became a reference
back to that first element.  (Right?  Someone back me up here, or tell me
if that's wrong).
In the second method, a similar event happened.
In the third, you successfully modified the array so that the first and
third elements are equal to the empty string.

So in all cases, you modified the actual elements, without removing them
from the array.  This is the behavior of the 'delete' function.  (See
perldoc -f delete for more info).

Compare this to the method I suggested:
use strict;
use warnings;
use Data::Dumper;

my @q = qw(fred joe freddy sick);
@q = grep { !/fred/ } @q;
print Dumper (\@q);
__END__

$VAR1 = [
          'joe',
          'sick'
        ];

This method actually removes the elements from the array.

Paul Lalli




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

Date: Tue, 1 Jun 2004 18:57:23 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040601185624.P18263@dishwasher.cs.rpi.edu>

On Tue, 1 Jun 2004, Paul Lalli wrote:

> use Data::Dumper;
> @t=@r=@q=qw(fred joe freddy sick);
> for (@q)
> {
>    delete $q[$cnt] if /fred/;
>    $cnt++;
> }
> for (0..$#r)
> {
>    delete $r[$_] if $r[$_] =~ /fred/;
> }
> for (@t)
> {
>    $_="" if /fred/;
> }
>
> print Dumper(\@q)
> print Dumper(\@r)

I forgot the semicolons here when I modified the code pasted in.
Apologies for that.

Paul Lalli


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

Date: Wed, 2 Jun 2004 00:02:47 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <c9j5f7$q38$1@wisteria.csv.warwick.ac.uk>


Quoth Paul Lalli <ittyspam@yahoo.com>:
> On Tue, 1 Jun 2004, zzapper wrote:
> 
> > In fact none of the three methods actually shortened the array
> >
> > @t=@r=@q=qw(fred joe freddy sick);
> >
> > for (@q)
> > {
> > delete $q[$cnt] if /fred/;
> > $cnt++;
> > }
> > print @q;
> >
> > for (0..$#r)
> > {
> > delete $r[$_] if $r[$_] =~ /fred/;
> > }
> > print @r;
> >
> > for (@t)
> > {
> > $_="" if /fred/;
> > }
> > print @t;
> >
> > print $#q;
> > print $#r;
> > print $#t;
> 
> Running your code, for all three methods, we see that the sizes of the
> arrays are still four.

 ...which is why you don't change the size of an array while looping over
it. Perl is clever enough not to actually do what you asked (which would
make a complete mess of the loop); so it doesn't work.

Ben

-- 
   Although few may originate a policy, we are all able to judge it.
                                             - Pericles of Athens, c.430 B.C.
  ben@morrow.me.uk


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

Date: Tue, 1 Jun 2004 20:10:20 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040601200706.Y18263@dishwasher.cs.rpi.edu>

On Wed, 2 Jun 2004, Ben Morrow wrote:
>
> Quoth Paul Lalli <ittyspam@yahoo.com>:
> >
> > Running your code, for all three methods, we see that the sizes of the
> > arrays are still four.
>
> ...which is why you don't change the size of an array while looping over
> it. Perl is clever enough not to actually do what you asked (which would
> make a complete mess of the loop); so it doesn't work.

I'm not actually convinced this is directly related to modifying the array
within the loop:

use strict;
use warnings;
use Data::Dumper;

my @chars = ('a'..'e');
delete $chars[1];
delete $chars[3];
print "After deletion, size is: " . @chars . "\n";
print Dumper(\@chars);

__END__

After deletion, size is: 5
$VAR1 = [
          'a',
          undef,
          'c',
          ${\$VAR1->[1]},
          'e'
        ];


It seems like this is just the default behavior of delete.  Or am I
misreading the results somehow?

Paul Lalli


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

Date: Wed, 2 Jun 2004 00:13:45 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <c9j63p$q38$4@wisteria.csv.warwick.ac.uk>


Quoth Paul Lalli <ittyspam@yahoo.com>:
> On Wed, 2 Jun 2004, Ben Morrow wrote:
> >
> > Quoth Paul Lalli <ittyspam@yahoo.com>:
> > >
> > > Running your code, for all three methods, we see that the sizes of the
> > > arrays are still four.
> >
> > ...which is why you don't change the size of an array while looping over
> > it. Perl is clever enough not to actually do what you asked (which would
> > make a complete mess of the loop); so it doesn't work.
> 
> I'm not actually convinced this is directly related to modifying the array
> within the loop:
> 
> use strict;
> use warnings;
> use Data::Dumper;
> 
> my @chars = ('a'..'e');
> delete $chars[1];
> delete $chars[3];
> print "After deletion, size is: " . @chars . "\n";
> print Dumper(\@chars);
> 
> __END__
> 
> After deletion, size is: 5
> $VAR1 = [
>           'a',
>           undef,
>           'c',
>           ${\$VAR1->[1]},
>           'e'
>         ];
> 
> 
> It seems like this is just the default behavior of delete.  Or am I
> misreading the results somehow?

Err... yes, my mistake. delete on arrays is actually not a defined
operation: it only exists to support pseudohashes, and any other use
should be considered deprecated. As phashes are themselves deprecated
now, it shouldn't be used at all. The 'undef' that the elements all
refer to is marked with a flag which says 'this element doesn't really
exist', so that exists can return false (also not strictly speaking a
defined operation on arrays).

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk


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

Date: 02 Jun 2004 00:14:42 GMT
From: ctcgag@hotmail.com
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040601201442.828$S9@newsreader.com>

Paul Lalli <ittyspam@yahoo.com> wrote:

> Running your code, for all three methods, we see that the sizes of the
> arrays are still four.  However, printing out the values shows only the
> 'joe' and 'sick' elements.  Why is this?  Well, I modified your code to
> print out the full contents of the arrays, using Data::Dumper.
>
> use Data::Dumper;
> @t=@r=@q=qw(fred joe freddy sick);
> for (@q)
> {
>    delete $q[$cnt] if /fred/;
>    $cnt++;
> }
 ...
> print Dumper(\@q)
> __END__
>
> And here's the output:
>
> $VAR1 = [
>           undef,
>           'joe',
>           ${\$VAR1->[0]},
>           'sick'
>         ];
 ...
>
> What we see here is that in the first method, the first element you tried
> to delete actually became undef, and the third element became a reference
> back to that first element.  (Right?  Someone back me up here, or tell me
> if that's wrong).

It seems that Perl has a special "undef" structure which is shared by all
empty array slots (rather than giving each one it's own "real" undef sv*).
Of course, the guts of perl must know about this, so that if something is
assigned to something pointing to this special structure it knows to break
the link, rather than sharing the new value with all other empty array
slots.  Apparently this confuses Data::Dumper.   I would consider it a bug
in Data::Dumper.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 1 Jun 2004 20:21:18 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040601201845.A18263@dishwasher.cs.rpi.edu>

On Tue, 2 Jun 2004 ctcgag@hotmail.com wrote:

> It seems that Perl has a special "undef" structure which is shared by all
> empty array slots (rather than giving each one it's own "real" undef sv*).
> Of course, the guts of perl must know about this, so that if something is
> assigned to something pointing to this special structure it knows to break
> the link, rather than sharing the new value with all other empty array
> slots.  Apparently this confuses Data::Dumper.   I would consider it a bug
> in Data::Dumper.

This would seem to support that analysis:

use strict;
use warnings;
use Data::Dumper;

my @arr;
$#arr = 4;
print Dumper(\@arr);
$arr[2] = 'foo';
print Dumper(\@arr);

__END__
$VAR1 = [
          undef,
          ${\$VAR1->[0]},
          ${\$VAR1->[0]},
          ${\$VAR1->[0]},
          ${\$VAR1->[0]}
        ];
$VAR1 = [
          undef,
          ${\$VAR1->[0]},
          'foo',
          ${\$VAR1->[0]},
          ${\$VAR1->[0]}
        ];


Paul Lalli


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

Date: Wed, 02 Jun 2004 00:40:38 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <40BD2202.E54030C4@acm.org>

zzapper wrote:
> 
> When you are looping thru an array
> 
> is there an "invisible" loop counter ?
> 
> eg
> 
> for (@somearray)
> {
> 
> }

No.  :-)


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 02 Jun 2004 01:00:34 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <40BD26AE.7A79C7FB@acm.org>

zzapper wrote:
> 
> On Tue, 1 Jun 2004 13:23:24 -0400, wrote:
> >
> >If you mean does Perl "invisibly" keep track of the indices of the array,
> >the answer is no.  Using the foreach loop you show above, you cannot
> >determine the index of the current iteration.  To do that, use this loop
> >instead:
> >
> >for (0..$#array){
> >   #the index of the current iteration is $_
> >   $element = $array[$_];
> >}
> 
> You pretty much answered my question, I was just naively hoping there
> was a special variable
> 
> I mainly wanted it to conditionally delete certain elements eg
> 
> @t=@r=@q=qw(fred joe freddy sick);
> 
> for (@q)
> {
> delete $q[$cnt] if /fred/;
> $cnt++;
> }
> print join "",@q;
> 
> # your solution
> 
> for (0..$#r)
> {
> delete $r[$_] if $r[$_] =~ /fred/;
> }
> print join "",@r;
> 
> # avoiding counters
> 
> for (@t)
> {
> $_="" if /fred/;
> }
> print join "",@t;

delete() does not remove the array element, it removes the contents of
the array element.  The usual Perl way to do it is to use grep():

@t = grep { $_ ne 'fred' } @t;


That copies the contents of the array to a list and then back to the
array.  If you want to modify the array without making a copy (it may be
very large) you have to do something like this:

for my $i ( reverse 0 .. $#t ) {
    if ( $t[ $i ] eq 'fred' ) {
        splice @t, $i, 1;
        }
    }

Note that you have to "reverse 0 .. $#t" or it will not work correctly.


John
-- 
use Perl;
program
fulfillment


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

Date: 1 Jun 2004 14:36:12 -0700
From: izco@hotmail.com (RP)
Subject: LWP::UserAgent problem - 500 error
Message-Id: <9e7779b4.0406011336.4d82b45@posting.google.com>

Hi, I'm trying to get the data off of a number of different pages, and
I'm getting an error:

500 Can't connect to www.yahoo.com:80 (connect: Permission denied)

My code is very simple, I'm just trying to get this to work:

#!/usr/bin/perl -w

use strict;
use LWP::UserAgent;

my $url = 'http://www.yahoo.com';
my $browser = LWP::UserAgent->new;
my $response = $browser->get($url,
	'User-Agent' => 'compatible; MSIE 6.0; Windows 98',
	'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
image/png, */*',
	'Accept-Charset' => 'iso-8859-1,*',
	'Accept-Language' => 'en-US',
 );

print "Content-type: text/html\n\n";
if ($response->is_success)
{ print $response->content; }
else { print $response->error_as_HTML; }

(Most of this code is copied from Spidering Hacks.)  I've been
assuming that the problem is that the headers I'm sending, but I
really don't know - I'm a neophyte with LWP::UserAgent (and most perl
modules, for that matter).  Could there be a problem with the response
my server is giving to the request?  I've never had any luck getting
LWP::UserAgent/LWP::Simple/HTML::Tokeparser to work on that server,
even extremely simple programs.  I've been struggling with this for
weeks, and I'm at a total loss.  Help?!?!  Thanks a million!


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

Date: Tue, 1 Jun 2004 19:40:41 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: LWP::UserAgent problem - 500 error
Message-Id: <St8vc.94346$tb4.3725677@news20.bellglobal.com>


"RP" <izco@hotmail.com> wrote in message
news:9e7779b4.0406011336.4d82b45@posting.google.com...
> Hi, I'm trying to get the data off of a number of different pages, and
> I'm getting an error:
>
> 500 Can't connect to www.yahoo.com:80 (connect: Permission denied)
>
> My code is very simple, I'm just trying to get this to work:
>

Did you try running it from the command line on your computer? Would have
proven it's not a problem in the code and saved you some of the headache.

The usual guess is that you have to go through a proxy, but you'll have to
ask your host why you can't connect out.

Matt




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

Date: Tue, 01 Jun 2004 14:04:29 -0700
From: Nicholas Erkert <nick@erkert.com>
Subject: Re: SSL connection to oracle using DBI?
Message-Id: <40bcf2f0$1@nntp0.pdx.net>

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

Joe User wrote:
| Has anyone done this before? If so, please let me know. Just
| remove the "nospam" and put in oracle in my email. Or, just reply
| to my post.
|
| Thanks,
| Bill
I'm not sure if DBI has native support for oracle over SSL but you can
use stunnel to provide a local port which makes it appear as if there's
an unencrypted connection to the database on the localhost.

Take a look at the following stunnel configuration file to get a head start.

client = yes
output = /dev/null
[snpp]
accept = localhost:lport
connect = SSLORACLE:rport

lport should be the local port you're binding to.
SSLORACLE is the hostname or IP of the Oracle server running SSL.
rport is the port the SSL Oracle server is running on.

Notes
- -----------------------------
This assumes that you only want plain text connections from localhost.
If this is not the case change the accept line to bind to whatever
IP:port you like.

the service description "[snpp]", although not meaningful is necessary
to get stunnel to run correctly.

If you want any logging change the output line to a file, otherwise the
output just gets tossed into the bit-bucket.
- ------------------------------
Once you have stunnel running properly you should be able to build an
ordinary DBI connection to an oracle server on localhost:lport.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAvO9dR6L8l18VQqsRAuqrAJ4wtI3tgSPnzpFhmSylohYosg0+1gCfS0Oq
X+zUgXL5ZWjQNTTdfBq0NhA=
=yL0F
-----END PGP SIGNATURE-----


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

Date: Tue, 01 Jun 2004 16:35:02 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: Why is this upload script not working
Message-Id: <remorse-FB2C24.16350201062004@plato.harvard.edu>

In article <ce43fdea.0405281659.7c859f99@posting.google.com>,
 constants@mix-net.net (Mark Constant) wrote:

> 	open(OUTFILE, '>$dir/$filename')

So a lot of people here complain if you use '"' (ie, double-quotes) 
where you don't need to.  However, this is one place where you should.  
What this line is creating is a file named dollar-sign, f, i, l, e, n, 
a, m, e (that is, exactly those characters) in a directory named 
dollar-sign, d, i, r.  You probably want this to read:

   open(OUTFILE, '>', "$dir/$filename") ...

I would actually suggest using a lexical file handle, such as:

   open my $out, '>', "$dir/$filename") ...

but that's your call.

Ricky

-- 
Pukku


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

Date: Wed, 2 Jun 2004 00:07:33 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Why is this upload script not working
Message-Id: <c9j5o5$q38$3@wisteria.csv.warwick.ac.uk>


Quoth Richard Morse <remorse@partners.org>:
> In article <ce43fdea.0405281659.7c859f99@posting.google.com>,
>  constants@mix-net.net (Mark Constant) wrote:
> 
> > 	open(OUTFILE, '>$dir/$filename')
> 
> So a lot of people here complain if you use '"' (ie, double-quotes) 
> where you don't need to.  However, this is one place where you should.  
> What this line is creating is a file named dollar-sign, f, i, l, e, n, 
> a, m, e (that is, exactly those characters) in a directory named 
> dollar-sign, d, i, r.  You probably want this to read:
> 
>    open(OUTFILE, '>', "$dir/$filename") ...
> 
> I would actually suggest using a lexical file handle, such as:
> 
>    open my $out, '>', "$dir/$filename") ...

And if this is meant to be in any way portable (certainly if it's in a
module) you shoudl use File::Spec instead.

Ben

-- 
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t    # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.


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

Date: Tue, 1 Jun 2004 21:17:17 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Window focus
Message-Id: <c9irot$8oc$1@reader2.panix.com>




I'm finalizing a script that, during its operation, brings up an
editor, which, depending on the value of the $EDITOR environmental
variable, can cause a new X window for the editor to pop up.
Annoyingly, when this second window closes the original window that
spawned it does not get the focus back.  This forces the user to
use the mouse, in what would otherwise be an entirely mouseless
interaction.  Is there any trick to return the focus to the original
window after the temporary editor window has been closed?

Thanks,

	-bill


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

Date: Tue, 1 Jun 2004 19:49:52 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: YAPC::2004
Message-Id: <c9iml0$6n0$1@reader2.panix.com>

In <Pine.SOL.4.56.0405312342080.24448@gagarin.cse.buffalo.edu> Daniel K Magnuszewski <dkm@cse.buffalo.edu> writes:

>The Buffalo Perl Mongers are proud to announce that Buffalo is hosting
>Yet Another Perl Conference (YAPC) at UB this summer, June 16-18, 2004.
>YAPC is an inexpensive ($85), grassroots conference on the Perl
>programming language aimed at beginners and experts alike, organized by
>Yet Another Society, Inc., a non-profit corporation.

The plane fare is what kills me...  Have the organizers made any
arrangements for tele-attendance via video?  I'd be happy to shell
out the $85 for access to that (even though I'd be getting only
10% of the hecklingly good fun of being there).

	-bill


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

Date: Tue, 01 Jun 2004 23:34:56 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: YAPC::2004
Message-Id: <x74qpu3l9b.fsf@mail.sysarch.com>

>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:

>>>>> "Tad" == Tad McClellan <tadmc@augustmail.com> writes:
  Tad> If you're going to be at YAPC this summer, consider setting aside
  Tad> Thursday to get about half of a Stonehenge Alpaca (Intermediate) 
  Tad> class for free!

  Tad> http://yapc.org/America/day2.shtml

  Tad> I have a very high opinion of the presenter. (heh)

  RLS> Actually, I do too. (heh)

i think he is a low down dirty rotten scoundrel and scalawag who should
be forced to code in php and python.

or maybe i don't think that. :)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 01 Jun 2004 17:28:32 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: YAPC::2004
Message-Id: <li65abeznj.fsf@localhost.localdomain>

>>>>> "b" == bill  <please_post@nomail.edu> writes:

  b> In <Pine.SOL.4.56.0405312342080.24448@gagarin.cse.buffalo.edu> Daniel K Magnuszewski <dkm@cse.buffalo.edu> writes:
  >> The Buffalo Perl Mongers are proud to announce that Buffalo is hosting
  >> Yet Another Perl Conference (YAPC) at UB this summer, June 16-18, 2004.
  >> YAPC is an inexpensive ($85), grassroots conference on the Perl
  >> programming language aimed at beginners and experts alike, organized by
  >> Yet Another Society, Inc., a non-profit corporation.

  b> The plane fare is what kills me...  Have the organizers made any
  b> arrangements for tele-attendance via video?  I'd be happy to shell
  b> out the $85 for access to that (even though I'd be getting only
  b> 10% of the hecklingly good fun of being there).

there is no way $85 could cover the cost of televideo. you would need
high speed net connections (not clogged with all the yapc hackers),
multiple tv cameras and probably A/V types, a fast server for the feeds,
etc. lotsa expensive stuff. yapc is so cheap since it is run on the
cheap. :)

uri




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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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