Added a foreach on the ref to has as i know thats your next question ;)


my $refhash = {'foo' => 'bar'};

&foo($refhash);

sub foo {
 my $hash = {};
 $hash = shift;
 #print $hash->{'foo'};
 foreach my $key (keys(%$hash)) {
  print "$key\n";
 }
}



----- Original Message -----
From: "Rajeev Rumale" <[EMAIL PROTECTED]>
To: "Pierre Smolarek" <[EMAIL PROTECTED]>
Sent: Tuesday, July 03, 2001 10:56 AM
Subject: Re: Subroutine returning a hash (?)


> Great !
>
> I would be greatfull if you can tell me about you to "send" hash to sub as
> parameter.
>
> Thanks in advance
>
> Rajeev Rumale
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Rajeev Rumale
> MyAngel.Net Pte Ltd.,                                            Phone  :
> (65)8831530 (office)
> #04-01, 180 B, The Bencoolen,                               Email  :
> [EMAIL PROTECTED]
> Bencoolen Street, Singapore - 189648                     ICQ    :
121001541
> Website : www.myangel.net
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ----- Original Message -----
> From: "Pierre Smolarek" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>; "Martijn van Exel" <[EMAIL PROTECTED]>
> Sent: Tuesday, July 03, 2001 5:52 PM
> Subject: Re: Subroutine returning a hash (?)
>
>
> > sub cgi {}
> > my $hashref = {};
> > .....
> > return ($hashref);
> > }
> >
> > my $cgi = {};
> > $cgi = &cgi;
> > $cgi->{'varname'};
> >
> > ----- Original Message -----
> > From: "Martijn van Exel" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Tuesday, July 03, 2001 10:01 AM
> > Subject: Subroutine returning a hash (?)
> >
> >
> > > Dear subscribers,
> > >
> > > I was in a modular mood and thought it might just be a good idea to
> > > do the parsing of the querystring in a subroutine. The subroutine
> > > goes into a separate file that I then 'require' in all my future
> > > CGI-scripts (is this a good way?).
> > >
> > > I thought it would be nice to return a hash with the key/value pairs
> > > from my querystring. I was thinking of the following:
> > >
> > > sub parseit
> > > {
> > > foreach $name ($q->(param))
> > > {
> > > $input{$name} = $q->param($name);
> > > }
> > > return \%input;
> > > }
> > >
> > > Because a subroutine cannot return a hash (or so I was told) I
> > > instead return a reference to the hash. I'm not sure if this will
> > > work. How would I access the data in my main cgi? Or am I making
> > > things more difficult than they should be?
> > >
> > > 'There's always more than one way to do it' can be very confusing at
> > times..
> > > --
> > > Martijn van Exel, [EMAIL PROTECTED]
> > >
> > > WEBkitchen
> > > Waterstraat 11
> > > 3511 BW Utrecht
> > > tel/fax 030-6701818
> > >
> > > http://www.webkitchen.nl
> >
> >

Reply via email to