[23185] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5406 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 21 18:05:51 2003

Date: Thu, 21 Aug 2003 15: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           Thu, 21 Aug 2003     Volume: 10 Number: 5406

Today's topics:
    Re: 5.80, OS X, bizarre FTP weirdness <cpryce@pryce.net>
    Re: 5.80, OS X, bizarre FTP weirdness <bgjohnson@note.amherst.edu>
        \@rray, error? maybe not. <Ben_Dover@psychiatric-center.Bellevue-Hospital.com>
    Re: \@rray, error? maybe not. (Tad McClellan)
    Re: and Randal L. Schwartz the hacker <emschwar@pobox.com>
        Apache returns 200 OK, but my perl script sends 302 RED (Michel Tokic)
        Apache returns 200 OK, but my perl script sends 302 RED (Michel Tokic)
    Re: Apache returns 200 OK, but my perl script sends 302 <dwilga-MUNGE@mtholyoke.edu>
    Re: Apache returns 200 OK, but my perl script sends 302 <michel@tokic.com>
    Re: Apache returns 200 OK, but my perl script sends 302 <flavell@mail.cern.ch>
    Re: Approach to match segments, opinions welcome <spamfilter@cheiron-it.nl>
    Re: automation of web form queries (Tad McClellan)
    Re: Copy constructors <wksmith@optonline.net>
    Re: dogma....re: modules <syscjm@gwu.edu>
    Re: dogma....re: modules <uri@stemsystems.com>
    Re: Image::Magick jpeg compression (Jay Tilton)
    Re: IN SEARCH OF ELEGANT CODE: Setting a hash value to  (David Filmer)
        proto-type sub needs new ribbon ? (stu7)
    Re: Quick removal of the begging of a file? <tzz@lifelogs.com>
    Re: Quick removal of the begging of a file? (Tad McClellan)
    Re: Using strict references (Tad McClellan)
    Re: Using strict references <skuo@mtwhitney.nsc.com>
    Re: Using strict references <spam@thecouch.homeip.net>
    Re: Using strict references <todd@ti.com>
    Re: Using strict references (Tad McClellan)
    Re: Using strict references <todd@ti.com>
        XML parsing problem <kurt-simone@t-online.de>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 21 Aug 2003 15:00:23 -0500
From: cp <cpryce@pryce.net>
Subject: Re: 5.80, OS X, bizarre FTP weirdness
Message-Id: <210820031500235500%cpryce@pryce.net>

In article <3f44f5e3@amhnt2.amherst.edu>, Brad Johnson
<bgjohnson@note.amherst.edu> wrote:

> 500 Unknown command.
> 227 Entering Passive Mode (208,209,50,18,22,139)

The only thing that your comandline FTP client is doing differently,
from what I can see is it seems to be auto sensing passive mode on the
server. 

Read the docs for NEt::FTP perldoc Net::FTP. There are methods for
setting Passive mode (PASV), or doing passive transfers

-- 
cp


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

Date: Thu, 21 Aug 2003 22:00:27 GMT
From: Brad Johnson <bgjohnson@note.amherst.edu>
Subject: Re: 5.80, OS X, bizarre FTP weirdness
Message-Id: <3f453fbd@amhnt2.amherst.edu>

cp <cpryce@pryce.net> wrote:
: In article <3f44f5e3@amhnt2.amherst.edu>, Brad Johnson
: <bgjohnson@note.amherst.edu> wrote:

:> 500 Unknown command.
:> 227 Entering Passive Mode (208,209,50,18,22,139)

: The only thing that your comandline FTP client is doing differently,
: from what I can see is it seems to be auto sensing passive mode on the
: server. 

: Read the docs for NEt::FTP perldoc Net::FTP. There are methods for
: setting Passive mode (PASV), or doing passive transfers

that's looking like it's the right track. Reading further (e.g. 
http://archive.develooper.com/macosx@perl.org/msg04468.html) I get the
impression that part of the problem is that Perl isn't properly grabbing
configuration from the system. Which may be because Mac::InternetConfig
now isn't installed and I can't just install w/cpan since i need to set
the configs right first.

I may have enough info to muddle here but if anyone knows the right
steps I'd be ever grateful.

-bgj.


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

Date: Thu, 21 Aug 2003 16:05:31 -0400
From: Ben Dover - Mental Patient 0057  <Ben_Dover@psychiatric-center.Bellevue-Hospital.com>
Subject: \@rray, error? maybe not.
Message-Id: <3F45260B.E23B5FD3@psychiatric-center.Bellevue-Hospital.com>

I'm looking at another persons code and I saw what I thought was an
error, but it seems to be in more than one place.

the following line for example:
  ($web{open},$web{dates},$web{stat}) = classStat($loc,\@classes);
I saw the \@classes 
why is there a \ in front of the @rray?
isn't that something you would use in a print statement?
but it's in many places...


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

Date: Thu, 21 Aug 2003 15:22:36 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: \@rray, error? maybe not.
Message-Id: <slrnbkaagc.a7p.tadmc@magna.augustmail.com>

Ben Dover - Mental Patient 0057 <Ben_Dover@psychiatric-center.Bellevue-Hospital.com> wrote:

> I'm looking at another persons code 


Everybody has problems.


> and I saw what I thought was an
> error, 

> the following line for example:
>   ($web{open},$web{dates},$web{stat}) = classStat($loc,\@classes);
> I saw the \@classes 
> why is there a \ in front of the @rray?


It is taking a reference to the array named @classes.

classStat() must have been written to expect an array reference
as its second argument.


> isn't that something you would use in a print statement?


Huh?

Where have you seen a backslash used in a print statement?

Maybe you meant in a double-quoted string instead?


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


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

Date: Thu, 21 Aug 2003 12:10:42 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: and Randal L. Schwartz the hacker
Message-Id: <etoptiyc259.fsf@wormtongue.emschwar>

Keith Keller <kkeller-spammmm@wombat.san-francisco.ca.us> writes:
> Wow, you're bitter.  Did he crack your password of 12345?

That's the stupidest combination I've ever heard in my life! That's
the kind of thing an idiot would have on his luggage!

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: 21 Aug 2003 11:33:02 -0700
From: michel@tokic.com (Michel Tokic)
Subject: Apache returns 200 OK, but my perl script sends 302 REDIRECT
Message-Id: <1e9d7925.0308211033.a0c6b67@posting.google.com>

Hello,

I have a little problem in Apache configuration. My little test script
returns a simple redirection to another website. After debugging with
ethereal, I recognised that apache returns HTTP response Code 302,
instead of 200, with the redirection content:

##### Browser Output ######
Moved
The document has moved [here, link ...] . 

##### my little test script ######
use CGI qw(:all);
 ...
print redirect('http://www.foobar.com/intern/index.html');


I asume that there must be something to set in apache configuration,
because on other webservers it works perfektly. There's even no
success with "PerlSendHeader On". I'm using apache/1.3.26 with
mod_perl/1.27.

Has got anyone an idea???

Thanks in advance,
Michel


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

Date: 21 Aug 2003 11:38:10 -0700
From: michel@tokic.com (Michel Tokic)
Subject: Apache returns 200 OK, but my perl script sends 302 REDIRECT
Message-Id: <1e9d7925.0308211038.102a76db@posting.google.com>

I'm sorry, i meant apache returns 200 instead of 302.


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

Date: Thu, 21 Aug 2003 19:02:35 GMT
From: Dan Wilga <dwilga-MUNGE@mtholyoke.edu>
Subject: Re: Apache returns 200 OK, but my perl script sends 302 REDIRECT
Message-Id: <dwilga-MUNGE-573A48.15023021082003@nap.mtholyoke.edu>

In article <1e9d7925.0308211033.a0c6b67@posting.google.com>,
 michel@tokic.com (Michel Tokic) wrote:

> Hello,
> 
> I have a little problem in Apache configuration. My little test script
> returns a simple redirection to another website. After debugging with
> ethereal, I recognised that apache returns HTTP response Code 302,
> instead of 200, with the redirection content:
> 
> ##### Browser Output ######
> Moved
> The document has moved [here, link ...] . 
> 
> ##### my little test script ######
> use CGI qw(:all);
> ...
> print redirect('http://www.foobar.com/intern/index.html');

The 302 is being generated by the CGI module, because 302 is the proper 
status code to return when a true redirection is what you want.

If you only want to tell the user to manually click on a link to go to 
the other locaiton, then you should generate the HTML code yourself and 
not use the "redirect" method.

-- 
Dan Wilga          dwilga-MUNGE@mtholyoke.edu
** Remove the -MUNGE in my address to reply **


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

Date: Thu, 21 Aug 2003 21:07:23 +0200
From: Michel Tokic <michel@tokic.com>
Subject: Re: Apache returns 200 OK, but my perl script sends 302 REDIRECT
Message-Id: <bi35co$vbu$03$1@news.t-online.com>

Dan,

thanks for your help. My script is a little complicated, and calls some 
functions of a self written module. Depending on the parameters, it 
gives a special output to the user. But one function is, to relocate to 
a special site, when eg. the delete-function is called. Just to prevent, 
  that the user don't can reload the page with the browsers built-in 
reload-button.

So just doing generated HTML output isn't enough for me ;-)

Another idea?

Thanks in advance,
Michel



Dan Wilga wrote:
> In article <1e9d7925.0308211033.a0c6b67@posting.google.com>,
>  michel@tokic.com (Michel Tokic) wrote:
> 
> 
>>Hello,
>>
>>I have a little problem in Apache configuration. My little test script
>>returns a simple redirection to another website. After debugging with
>>ethereal, I recognised that apache returns HTTP response Code 302,
>>instead of 200, with the redirection content:
>>
>>##### Browser Output ######
>>Moved
>>The document has moved [here, link ...] . 
>>
>>##### my little test script ######
>>use CGI qw(:all);
>>...
>>print redirect('http://www.foobar.com/intern/index.html');
> 
> 
> The 302 is being generated by the CGI module, because 302 is the proper 
> status code to return when a true redirection is what you want.
> 
> If you only want to tell the user to manually click on a link to go to 
> the other locaiton, then you should generate the HTML code yourself and 
> not use the "redirect" method.
> 



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

Date: Thu, 21 Aug 2003 20:50:16 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Apache returns 200 OK, but my perl script sends 302 REDIRECT
Message-Id: <Pine.LNX.4.53.0308212040430.25122@lxplus016.cern.ch>

On Thu, Aug 21, Michel Tokic inscribed on the eternal scroll:

> I have a little problem in Apache configuration.

If you were sure about that, then why ask here?  (i.e c.l.p.m).
(comp.infosystems.www.servers.* are places for server configuration
questions.)

Looks more like a CGI question to me, and thus very apt for
comp.infosystems.www.authoring.cgi (beware the automoderator bot).

> My little test script
> returns a simple redirection to another website.

Sounds clear enough.  I don't understand your Subject: line.  You say
Apache returns 200 OK?  But your redirection should be status 302.

> After debugging with
> ethereal, I recognised that apache returns HTTP response Code 302,

Now you say Apache *doesn't* return 200 OK.  So which is it to be?

> instead of 200, with the redirection content:
>
> ##### Browser Output ######
> Moved
> The document has moved [here, link ...] .

That's quite usual with a 302 redirection (RFC2616 has the details,
since that is the HTTP part of the transaction).

> ##### my little test script ######
> use CGI qw(:all);
> ...
> print redirect('http://www.foobar.com/intern/index.html');

It looks as if you're asking for a 302 redirection.  At least one of
your statements was that you're getting a 302 redirection.  If that's
true then it's working as designed.

> I asume that there must be something to set in apache configuration,

I'm still not clear where your problem is.

> because on other webservers it works perfektly.

Define "works".  You appear to be contradicting yourself too much.

> There's even no success with "PerlSendHeader On". I'm using
> apache/1.3.26 with mod_perl/1.27.

OK, so it's a mod_perl question, but I wouldn't have thought this
aspect was significantly different from plain CGI.

Clarify the question please (though I'm still sceptical that it's on
topic here...)


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

Date: Thu, 21 Aug 2003 20:11:10 +0200
From: "Frank Maas" <spamfilter@cheiron-it.nl>
Subject: Re: Approach to match segments, opinions welcome
Message-Id: <3f450b3e$0$26126$e4fe514c@dreader7.news.xs4all.nl>

Hi Steven,

> You're using certain numbers to delimit a list of numbers?

I am not exactly sure what you mean by this. If your question
was to what I am doing exactly: this is about calculating travel
times in a network of nodes. Where the string is the node list and
the triples are travel times between two nodes.

> I think the second approach is better.

Yes... When I wrote this I had an error in the code that I found later.
The 2nd approach is way (way!) faster.

> You've not mentioned what
> should be done if the first number in the list has no stopping
> delimiter.   Do you stop?  Or do you attempt to find a valid starting
> point?  Assuming the former, here's what I'd do:

> # Loop once and exit as soon as possible -- should be faster than
> # what you had previously written.

I can use this, but not exactly your solution. What I did not write
is that it is possible to have two triples with the same "start".
Your solution does not accommodate this. But the one time loop (w/o
shifting) seems promising.

Thanks!

Frank




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

Date: Thu, 21 Aug 2003 14:16:03 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: automation of web form queries
Message-Id: <slrnbka6jj.a38.tadmc@magna.augustmail.com>

Ian Morton <igm@liv.ac.uk> wrote:

> Hi, I'm brand new to Perl so please forgive me if this question appears
> simple 


Your Question is Asked Frequently.


> Could you tell me what howto's to read or where to go for examples that 
> allow you to automatically insert data into a url and submitt the form
                                                                    ^^^^
                                                                    ^^^^
   perldoc -q form

         How do I automate an HTML form submission?


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


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

Date: Thu, 21 Aug 2003 20:36:49 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Copy constructors
Message-Id: <B3a1b.145733$_R5.55102354@news4.srv.hcvlny.cv.net>


"Joe Creaney" <mail@annuna.com> wrote in message
news:3F44F19E.4070000@annuna.com...
> I have been reading up in C++ about copy constructors, is it possable
to
> use them in perl.  I want to delete an object from one array and put
it
> in another array.  When I delete the object the object in the other
> array goes away too.
>

I recommend Damian Conway's book "Object Oriented Perl".  The section
"Constructors as object duplicators" describes this problem and its
solution from the Perl perspective.

Bill




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

Date: Thu, 21 Aug 2003 15:04:19 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: dogma....re: modules
Message-Id: <3F4517B3.4060306@gwu.edu>

hudson wrote:
> On Wed, 20 Aug 2003 23:09:07 +1200, "Tintin" <me@privacy.net> wrote:
> 
> 
>>>I mean, come on...I can delete a directory as follows:
>>>
>>>`rm -r $directory`
>>
>>And that works well under Windows, VMS, etc?
> 
> 
> well...doesn't it boil down to:
> 
> are you doing general abstraction or solving a single problem

and the answer is: "You are doing a general abstraction, even when
you *think* you are solving a single problem."  There is nothing
so permanent as temporary code.

> 
> If you are writing up a script to be used on some *nix and you know
> that's all its going to do...what's the problem?

The problem is that unless you are The Amazing Criswell, it is impossible
to know what uses your code may be put to.

> 
> If you want to write a module for millions of perl hackers and want to
> think of every case, then of course you got to worry....

More programming disasters have come from the words "That case will
never happen" than any other single cause.

                              Chris Mattern



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

Date: Thu, 21 Aug 2003 19:16:46 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: dogma....re: modules
Message-Id: <x7ada2stwh.fsf@mail.sysarch.com>

>>>>> "CM" == Chris Mattern <syscjm@gwu.edu> writes:

  CM> More programming disasters have come from the words "That case will
  CM> never happen" than any other single cause.

he is just going to have to learn that on his own. it will take him
about 10 years at his pace. then he will start spouting the module
'dogma' to newbies and recall what a jerk he was for not grokking the
concept earlier. and he will regret the massive delays when constantly
rewriting his code to add each new feature that wasn't planned for and
discovering that his adhoc design doesn't scale well with all those
changes and that cutting and pasting and editing 10 versions of the same
thing is a major time sink.

yadda yadda yadda. it is amazing what ignoring 50+ years of industry
experience causes. all because he knows better and can see the future
all the way to next thursday.

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: Thu, 21 Aug 2003 21:35:51 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Image::Magick jpeg compression
Message-Id: <3f453b19.86891905@news.erols.com>

"Andrew Harton" <andrew_harton@agilent.com> wrote:

: I've been banging my head against a wall trying to use Image::Magick
: to generate jpeg compressed thumbnails.
: 
: Here's latest iteration of the code I've been using;
:   my $image = Image::Magick->new;
:   $image->Read(filename=>$source);
:   $image->Resize(width=>400, height=>300);
:   $image->Write(filename=>$output);
:   $image->Resize(width=>100, height=>75);
:   $image->Set(Quality=>10);
:   $image->Write(filename=>$thumb, compression=>'JPEG');
:   undef $image;
: 
: Basically, I'm trying to read a source image, resize to 400x300 and
: write that, then resize to 100x75 and then write that.  I notice that
: the typical filesize I get for the 400x300 image is between 50-60k,
: however the filesize for the thumbnail is roughly 25k.  Using
: Paintshop Pro I can produce compressed images of around 5k.
: 
: Any pointers as to what I'm doing wrong would be great, as I find the
: documentation on the Image::Magick website a bit short on detail.

I agree.

I recall seeing what you describe with a thumbnail generator of my
own.  The files shrank dramatically when I inserted a call to the
Profile() method, which removed a huge chunk of data that was being
carried forward from the full-size image to the thumbnail.

    $magick->Read( $ifile );
    $magick->Profile();
    $magick->Resize( width=>$x, height=>$y );
    $magick->Write( $ofile );

I'm not sure anymore what an "ICC or IPTC image profile" is or why it
has to be removed manually, but it made sense back when I wrote the
program.

IOW, I don't know what I'm doing, but it did the trick.
Cargo cult programming is bad, mmkay?



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

Date: 21 Aug 2003 14:32:23 -0700
From: IneverReadAnythingSentToMe@hotmail.com (David Filmer)
Subject: Re: IN SEARCH OF ELEGANT CODE: Setting a hash value to a chomp'ed thing
Message-Id: <e4c916dd.0308211332.44fe8743@posting.google.com>

Brian McCauley <nobull@mail.com> wrote in message news:<u9u18bxmtf.fsf@wcl-l.bham.ac.uk>...
> "John W. Krahn" <krahnj@acm.org> writes:
> 
> > Well this will work, if that's what you want.
> > 
> >    %hash = ( key => grep [ chomp ], `which ps` );
> 
> Wow, that's a neat trick.

Agreed! I had no idea you could do something like that.  Kewl. Thanks!


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

Date: 21 Aug 2003 14:14:51 -0700
From: stuseven@hotmail.com (stu7)
Subject: proto-type sub needs new ribbon ?
Message-Id: <d7dd90b0.0308211314.2e175a29@posting.google.com>

+
   With Perl 5.6, I'm trying to use prototypes and a new
 subroutine...

     sub testproto($) { subroutine here }

    With this, I tried to use the actual "prototype" call...

     prototype testproto ;
      and I also tried   
     print prototype testproto;

  however, the subroutine output seems unaffected regardless of
 what parameters are sent... $a or @Arr... and the prototype command
 doesnt seem to return anything at all.

     Am I using these correctly, or isnt prototyping of this kind
 working in Perl yet ?


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

Date: Thu, 21 Aug 2003 14:05:07 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Quick removal of the begging of a file?
Message-Id: <4nvfsqevjg.fsf@lockgroove.bwh.harvard.edu>

On Tue, 19 Aug 2003, ben.goldberg@hotpop.com wrote:

>> >  scalar(<FH>); # skip to the end of the line.
> 
> I got the idea of skipping to the end of the line this way from
> look.pl.

Doesn't this cause the whole file to be put into memory temporarily?

Why not just seek(FH, 0, SEEK_END)? It's O(1) * as opposed to any O(n)
solution that loops through the lines of the file.

Ted

* depending on the filesystem, but generally O(1) I think


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

Date: Thu, 21 Aug 2003 14:27:15 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Quick removal of the begging of a file?
Message-Id: <slrnbka78j.a38.tadmc@magna.augustmail.com>

Ted Zlatanov <tzz@lifelogs.com> wrote:
> On Tue, 19 Aug 2003, ben.goldberg@hotpop.com wrote:
> 
>>> >  scalar(<FH>); # skip to the end of the line.


> Doesn't this cause the whole file to be put into memory temporarily?


In scalar context the input operator reads a single line, so no,
it does not cause the whole file to be put into memory.


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


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

Date: Thu, 21 Aug 2003 14:32:03 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Using strict references
Message-Id: <slrnbka7hj.a38.tadmc@magna.augustmail.com>

Todd Bair <todd@ti.com> wrote:

>     the goal is to use the $key as the name of the array


Why do you think that you need to do that?

Symbolic references are not allowed under use strict, for good reason.

You would be well served to modify your goal.


   http://www.plover.com/~mjd/perl/varvarname.html
   http://www.plover.com/~mjd/perl/varvarname2.html
   http://www.plover.com/~mjd/perl/varvarname3.html




[ snip TOFU. Please quote your followups properly in the future. ]

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


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

Date: Thu, 21 Aug 2003 12:39:42 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Using strict references
Message-Id: <Pine.GSO.4.21.0308211237580.25629-100000@mtwhitney.nsc.com>

On Thu, 21 Aug 2003, Todd Bair wrote:

> Hi,
> 
>     I am trying to write all of my code using strict to improve my
> code.  However, the correct use of references for the following problem
> eludes me.  I have a work around, but I would like to know the correct
> way to code this.
> 
> #!/usr/bin/perl -w
> ######################################
> 
> use strict;
> #no strict 'refs';  ## work around ##
> 
> ######################################
> 
> my %hash = qw(foo one bar two);
> my $key;
> 
> foreach $key (keys %hash)
> {
>         @{$key} = (0..5);
> }




Just say 'no' to symbolic references.



 
> ######################################
> # later on in the program
> ######################################
> 
> foreach $key (keys %hash)
> {
>         print "array $hash{$key} = ";
> 
>         print join("\t",@{$key});
> 
>         print "\n";
> }
> 


Try a hash instead:

#!/usr/local/bin/perl

use strict;
use warnings;

my %hash = qw(foo one bar two);
my %array_lookup;
my $key;

foreach $key (keys %hash)
{
          $array_lookup{$key} = [ 0 .. 5 ];       

      # is preferred to
      # @{$array_lookup{$key}} = (0 .. 5);
}


foreach $key (keys %hash)
{
        print "array $hash{$key} = ";

        print join("\t",@{$array_lookup{$key}});

        print "\n";
}


-- 
Hope this helps,
Steven



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

Date: Thu, 21 Aug 2003 16:22:26 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Using strict references
Message-Id: <aS91b.7635$MG5.39279@wagner.videotron.net>

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

Todd Bair wrote:

> #!/usr/bin/perl -w
> ######################################
> 
> use strict;
> #no strict 'refs';  ## work around ##
> 
> ######################################
> 
> my %hash = qw(foo one bar two);

For clarity, hashes should be populated like so instead of the above array-style:

%hash = (
	"foo"	=>	"one",
	"bar"	=>	"two",
);

> my $key;
> 
> foreach $key (keys %hash)
> {
>         @{$key} = (0..5);
> }

The above loops over the hash's keys ("foo" and "bar") and creates brand new variables out of those 
names, @foo and @bar.

Do NOT do this.  If you're a beginner, do NOT do it no matter how tempting it might seem, and if 
you're not a beginner, you already know not to do it.

Instead of creating brand-new variables, you should save the new stuff either in a new hash or in 
your existing hash.



> 
> ######################################
> # later on in the program
> ######################################
> 
> foreach $key (keys %hash)
> {
>         print "array $hash{$key} = ";
> 
>         print join("\t",@{$key});
> 
>         print "\n";
> }

It appears to me that you don't know that you can store arrays (actually, array _references_) as 
values to a hash's keys.  Please see "perldoc perlref".

Your code could be re-written in several approaches.  One is to create the values in the hash 
definition (since you're completely ignoring "one" and "two" in your current code):

%hash = (
	"foo"	=>	[0..5],
	"bar"	=>	[0..5],
);

Or if you want to do it your way:

%hash = (
	"foo"	=>	"one",
	"bar"	=>	"two",
);

foreach $key (keys %hash) {
	$hash{$key} = [0..5];
}

Then later on during the iteration:

foreach $key (keys %hash) {
	print "arrayref in hash key $key dereferences to = ";
	print join("\t", @{$hash{$key}});
	print "\n";
}

Or:

while (($key, $value) = each %hash) {
	print "arrayref in hash key $key dereferences to = ";
	print join("\t", @$value);
	print "\n";
}


Best of luck.

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/RSoFeS99pGMif6wRAjN+AJ9sh4BVeHLUggtYvJma1m9nt/hNTQCg96Lh
gJYTF3PkHE+lpGpaSaJz5rI=
=cK7E
-----END PGP SIGNATURE-----



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

Date: Thu, 21 Aug 2003 15:56:58 -0500
From: Todd Bair <todd@ti.com>
Subject: Re: Using strict references
Message-Id: <3F45321A.80A2723@ti.com>

Tad,

> Symbolic references are not allowed under use strict, for good reason.
>  http://www.plover.com/~mjd/perl/varvarname.html
>  http://www.plover.com/~mjd/perl/varvarname2.html
>  http://www.plover.com/~mjd/perl/varvarname3.html

    Thank you for clearing the symbolic references under strict for me,
and thanks for the links.

>Why do you think that you need to do that?

    I would rather not predeclare 32**26 possible variable names.

Todd




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

Date: Thu, 21 Aug 2003 16:13:16 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Using strict references
Message-Id: <slrnbkadfc.atn.tadmc@magna.augustmail.com>

Todd Bair <todd@ti.com> wrote:

>>Why do you think that you need to do that?
> 
>     I would rather not predeclare 32**26 possible variable names.


Use a hash and real references, and you won't have to.


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


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

Date: Thu, 21 Aug 2003 16:18:43 -0500
From: Todd Bair <todd@ti.com>
Subject: Re: Using strict references
Message-Id: <3F453733.AA8705F@ti.com>

Steve,

    Thanks, that is the more graceful/correct method I was looking for.

Todd

Steven Kuo wrote:

> On Thu, 21 Aug 2003, Todd Bair wrote:
>
> > Hi,
> >
> >     I am trying to write all of my code using strict to improve my
> > code.  However, the correct use of references for the following problem
> > eludes me.  I have a work around, but I would like to know the correct
> > way to code this.
> >
> > #!/usr/bin/perl -w
> > ######################################
> >
> > use strict;
> > #no strict 'refs';  ## work around ##
> >
> > ######################################
> >
> > my %hash = qw(foo one bar two);
> > my $key;
> >
> > foreach $key (keys %hash)
> > {
> >         @{$key} = (0..5);
> > }
>
> Just say 'no' to symbolic references.
>
>
> > ######################################
> > # later on in the program
> > ######################################
> >
> > foreach $key (keys %hash)
> > {
> >         print "array $hash{$key} = ";
> >
> >         print join("\t",@{$key});
> >
> >         print "\n";
> > }
> >
>
> Try a hash instead:
>
> #!/usr/local/bin/perl
>
> use strict;
> use warnings;
>
> my %hash = qw(foo one bar two);
> my %array_lookup;
> my $key;
>
> foreach $key (keys %hash)
> {
>           $array_lookup{$key} = [ 0 .. 5 ];
>
>       # is preferred to
>       # @{$array_lookup{$key}} = (0 .. 5);
> }
>
> foreach $key (keys %hash)
> {
>         print "array $hash{$key} = ";
>
>         print join("\t",@{$array_lookup{$key}});
>
>         print "\n";
> }
>
> --
> Hope this helps,
> Steven



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

Date: Thu, 21 Aug 2003 22:25:23 +0200
From: Kurt Klinner <kurt-simone@t-online.de>
Subject: XML parsing problem
Message-Id: <bi39tj$1jt$07$1@news.t-online.com>

Hello,

while trying to parse a "large" XML document i found a 
strange behaviour of the Parser Module(s) (XML::Parser:PerlSAX, 
XML::Parser, XML::Parser::Expat

If my file XML file is larger then 65536 bytes
the actual character string is interrupted and a whitespace 
is added.

For Example

<DATASET>
<DATA><![CDATA["NOVDEC_B"]]></DATA>
<DATA><![CDATA["November\December"]]></DATA>
<DATA><![CDATA["Nov\Dec"]]></DATA>
<DATA><![CDATA["01.11."]]></DATA>
<DATA><![CDATA[11]]></DATA>
<DATA><![CDATA["begin_2month"]]></DATA>
<DATA><![CDATA[11]]></DATA>
</DATASET>

if now "Novemver\December" is at the 65536 border the String is
splitted in "Nov WHITESPACE ember\December"

Any ideas how to avoid /fix that problem


Thanks in advance

Regards

Kurt



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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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