Re: perl hash utilities

Discussion in 'Perl Misc' started by Ben Bacarisse, Sep 26, 2013.

  1. Cal Dershowitz <> writes:

    > I've been trying to break up perl tasks into smaller parts and have
    > taken something that used to work and now have it unable to pass data
    > properly:
    >
    > $ perl config1.pl
    > Global symbol "$domain" requires explicit package name at config1.pl
    > line 14.
    > Global symbol "$domain" requires explicit package name at config1.pl
    > line 15.
    > Execution of config1.pl aborted due to compilation errors.
    > $ cat config1.pl
    > #!/usr/bin/perl -w
    > use strict;
    > my %domain;
    > my $ref_to_domain = \%domain;
    > sub get_config{
    > my $my_ftp = shift;
    > print "my ftp is $my_ftp\n";
    > my $ident = 'template_stuff/ident.txt';
    > my $config = do($ident);
    > unless ($config) {
    > die("read error: $!") if $!;
    > die("parse error: $@") if $@;
    > }
    > $domain = $config->{$my_ftp};


    $domain is not the same as %domain (one's a scalar, the other is a
    hash). What did you want this line to do to %domain? What keys/values
    in the hash did you want it to set or alter?

    <snip>
    --
    Ben.
     
    Ben Bacarisse, Sep 26, 2013
    #1
    1. Advertising

  2. Cal Dershowitz <> writes:
    <snip>
    > So what I'm looking to have at the end of this great endeavor is
    > 2) a hash with the following values:
    > domain => 'www.tyui.com',
    > username => 'sdfkgkdfj',
    > password => 'alisjflasjf',
    > , and a reference to pass it around to see if I can print the darn thing.


    If $href holds a reference to a hash, then $href->{'domain'} =
    'www.tyui.com' will set the 'domain' key in the hash referenced by
    $href. So for a sub called like this:

    my %domain;
    ...
    fill_me_in(\%domain);

    the body would be something along the lines of

    sub fill_me_in
    {
    my $href = shift;
    ...
    $href->{'domain'} = '...';
    $href->{$some_key} = $some_value;
    ...
    }

    --
    Ben.
     
    Ben Bacarisse, Sep 26, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    1
    Views:
    586
    red floyd
    Nov 10, 2011
  2. JWhite

    Perl CGI utilities?

    JWhite, Jul 1, 2008, in forum: Perl Misc
    Replies:
    5
    Views:
    332
    Todd Wade
    Jul 5, 2008
  3. Uri Guttman

    Re: perl hash utilities

    Uri Guttman, Sep 26, 2013, in forum: Perl Misc
    Replies:
    2
    Views:
    202
    Charles DeRykus
    Sep 27, 2013
  4. George Mpouras

    Re: perl hash utilities

    George Mpouras, Sep 26, 2013, in forum: Perl Misc
    Replies:
    9
    Views:
    236
    John W. Krahn
    Oct 6, 2013
  5. Rainer Weikusat

    Re: perl hash utilities

    Rainer Weikusat, Oct 4, 2013, in forum: Perl Misc
    Replies:
    1
    Views:
    169
    Rainer Weikusat
    Oct 4, 2013
Loading...

Share This Page