in reply to Re: pattern matching
in thread Creating a regex to match part of a URL's domain name (was: pattern matching)

hmm i used part of your code in a subroutine, and it's giving me the error "Use of uninitialized value at ./index.cgi line 29."
here's the function:
sub getd { my $string = @_; my $wanted; my $domain; ($domain) = split '/', $string; $wanted = (split /\./, $domain)[-2]; return $wanted; } my $variable = "www.google.com"; print &getd($variable); # this is line 29.

any ideas?

strfry()

Replies are listed 'Best First'.
Re: Re: Re: pattern matching
by japhy (Canon) on Jun 06, 2001 at 19:55 UTC
    You're not doing any rudimentary data-checking, or you'd see that my $string = @_ was assigning a number to your variable.
    # try one of these: my ($string) = @_; my $string = shift; my $string = $_[0];


    japhy -- Perl and Regex Hacker
      aha! but what if i want to use
      my $variable = "http://www.google.com"; ? does this subroutine not handle "/"'s?
        ok, now that i've embarrassed myself.. (:
        i figured a way around it; i just simply left out http:// and placed it statically in another portion of the code; i can always make a workaround if i need to link to, say, something with an ftp:// protocol heading. (:
        sorry for all the mess and frustration (although most of it was likely on my part hehe)
        thanks!
        strfry()