Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Avoiding global variables when I need to supply a callback

by beable (Friar)
on Jul 22, 2004 at 11:39 UTC ( [id://376546]=note: print w/replies, xml ) Need Help??


in reply to Avoiding global variables when I need to supply a callback

You can use an anonymous subroutine for the callback, which will let you put the URIs you find into an array which isn't global:
#!/usr/bin/perl use strict; use warnings; use URI::Find; find_em(); sub find_em { my $text = "http://www.goolge.com/ blah httg://kew.org ftp://127.0 +.0.1/warez"; my @uris = (); my $finder = URI::Find->new(sub{my ($uri, $text) = @_; push @uris, + $uri;}); my $how_many_found = $finder->find(\$text); print("uris are @uris\n"); } __END__

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://376546]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found