Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   A Stupid question. (http://www.velocityreviews.com/forums/t886377-a-stupid-question.html)

Mark Healey 05-08-2004 08:07 PM

A Stupid question.
 
For some reason I can't find the answer to this question in the
O'Reily books I have.

How to I pass an array or hash to a function?

--
Mark Heaely
marknews(at)healeyonline(dot)com

Matt Garrish 05-08-2004 08:23 PM

Re: A Stupid question.
 

"Mark Healey" <die@spammer.die> wrote in message
news:VP2SpNyJrzMZ-pn2-lOGkVxwVd5VO@adsl-63-207-135-60.dsl.sndg02.pacbell.net...
> For some reason I can't find the answer to this question in the
> O'Reily books I have.
>
> How to I pass an array or hash to a function?
>


O'Reilly's books are much better... ; )

In answer to your question, just pass a reference to your hash or array:

mysub(\@array, \%hash);

sub mysub {

my ($aref, $href) = @_;

}

Matt



Sam Holden 05-08-2004 10:22 PM

Re: A Stupid question.
 
On Sat, 08 May 2004 20:07:40 GMT, Mark Healey <die@spammer.die> wrote:
> For some reason I can't find the answer to this question in the
> O'Reily books I have.
>
> How to I pass an array or hash to a function?


sub foo {
my ($arg1, $arg2, @array) = @_;
}

sub bar {
my ($arg1, %hash) = @_;
}

foo($a_scalar, $another, @an_array);
bar($a_scalar, %a_hash);

If you want to pass more than one array or hash then see
perldoc perlsub
Of particular interest will be the section which begins:

Pass by Reference

If you want to pass more than one array or hash into a
function--or return them from it--and have them maintain
their integrity, then you're going to have to use an
explicit pass-by-reference.

Reading the documentation that comes with perl is usually a good
first step when wanting to know how to do something in perl.


John Bokma 05-09-2004 12:35 AM

Re: A Stupid question.
 
Purl Gurl wrote:

> Purl Gurl wrote:
>
>
>>Mark Healey wrote:

>
>>>How to I pass an array or hash to a function?

>
>> http: etc...

>
> That link doesn't lead where I would like.


That's an URI for you :-D

> You will end up
> on my Perl FAQ 7 page rather than the actual FAQ answer
> because of frames.


That's why frames are often such a bad idea

> Follow the link to,
>
> Perl FAQ 7
>
> Then click on this,
>
> How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?


And make a little dance and shout "Goeba Goeba" three times :-D.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/

David Oswald 05-09-2004 08:30 AM

Re: A Stupid question.
 

"Mark Healey" <die@spammer.die> wrote:

> For some reason I can't find the answer to this question in the
> O'Reily books I have.
>
> How to I pass an array or hash to a function?


What books are you looking in, Javascript and Sendmail?

See "Programming Perl, 3rd Edition" (the Camel book) chapter 6.

See the "Perl Cookbook, 1st Edition" (the Ram book) Chapter 10.



John Bokma 05-09-2004 07:58 PM

Re: A Stupid question.
 
Purl Gurl wrote:

> John Bokma wrote:
>
>>Purl Gurl wrote:


>>>You will end up
>>>on my Perl FAQ 7 page rather than the actual FAQ answer
>>>because of frames.

>
>>That's why frames are often such a bad idea

>
> Turns out is not frames related. It is darn anchor #
> syntax usage. My Perl documentation is a blend of


What's wrong with it?

> Perl 5.6 and 5.8 versions, factory condition.
>
> This documentation is proving challenging. I have


Yeah, I have seen some errors in the ActiveState version too.

> been working for months recreating missing pages
> in documentation as found, not found, at almost
> all Perl documentation sites.


Cool

> Only method I have of finding missing pages is
> parse for 404 Page Not Found errors, then try
> to find the path to the path to the path to the
> path to the bad link. Grrrrr....


linkchecker? Believe there is one at sourceforge.

And you don't have the referer in the access_log?

>>And make a little dance and shout "Goeba Goeba" three times :-D.

>
> Save the dancing for later.


Ok, just the shouting then :-D.

> There is a benefit. We are now out of the non-commercial
> block which serves thousands of home users running boxes
> infected with all kinds of virii, which bang away at our
> server, thousands of times a day.


But that is worth a big dance :-D.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/

John Bokma 05-10-2004 04:02 AM

Re: A Stupid question.
 
Purl Gurl wrote:

> John Bokma wrote:


[ # URI fragment problem ]

> I will have to look closer when time allows. This


Kay, I am curious :-D

>>linkchecker? Believe there is one at sourceforge.

>
> I have considered a link checker which will recurse
> at least ten to fifteen links deep. Not sure how
> effective this will be because some of the links
> are circular in nature, more of a "swirl candy"


Most link checkers keep a "cache" of pages already fetched, so circular
refs shouldn't be a problem.

http://validator.w3.org/checklink

But probably with a huge depths and many documents the report is quite
impressive.

> Search engine spider bots do a darn good job of
> locating those missing pages!


Yup, if the page is not there, 404 :-D

>>And you don't have the referer in the access_log?

>
> Many browsers do not provide referrer data.


Many others do. If a browser get a 404, you can check the referring page
for the link. If the link is there, then the page has a broken link.

> Our new static ip address has only propagated for
> a matter of a few hours and already we are being
> slammed with Swen 32 virii email. Similar, several
> hundred Sasser worm attacks on port 445. Lot of
> dumb internet users out there without sense enough
> to slip condoms over their machines.


Yup, and this will always be the case. I won't call them dumb, because
many are smart in other ways, just not with computers. And no, when you
are good at Y doesn't mean you are good at Z too.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/

Mark Clements 05-10-2004 02:09 PM

Re: A Stupid question.
 
Purl Gurl wrote:
>
> Computer virii is such widespread common knowledge,
> a person would have to be dumb to not know of
> computer virii, and exceptionally dumb to not
> take precautionary measures for protection.

The plural of "virus" is "viruses".

Mark

Peter Hickman 05-10-2004 02:43 PM

Re: A Stupid question.
 
Mark Clements wrote:
> The plural of "virus" is "viruses".
>
> Mark


Thank you for your insightful comment. How could my life be complete
without a spelling lawyer, btw virii has a usage as the plural of virus
going back to the 1990s and no one but a pedant has problems with this.

disk, disc, disk, disc, disk, disc, disk, disc, disk, disc, disk, disc,
disk, disc, disk, disc, disk, disc, disk, disc, disk, disc, disk, disc,
disk, disc, disk, disc, disk, disc, disk, disc, disk, disc, disk, disc,
disk, disc, disk, disc, disk, disc, disk, disc, disk, disc, disk, disc,
disk, disc, disk, disc, disk, disc, disk, disc, disk, disc, disk, disc,
disk, disc, disk, disc, disk, disc, disk, disc, disk, disc, disk, disc,
disk, disc...

That should keep you happy for hours.

Mark Clements 05-10-2004 02:56 PM

Re: A Stupid question.
 
Peter Hickman wrote:
>
> Thank you for your insightful comment. How could my life be complete
> without a spelling lawyer, btw virii has a usage as the plural of virus
> going back to the 1990s and no one but a pedant has problems with this.

Ouch are my knuckles rapped. A precedent going back to the 90s does not make it correct usage.
PG is normally a stickler for precise definition; I was merely helping her along her merry way.

I am guilty as charged on the pedant front.

Mark


All times are GMT. The time now is 10:22 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.