...

View Full Version : subroutine mystery



gorilla1
03-10-2010, 10:29 PM
I am unfortunately very rusty with Perl and I am trying to build a script where I read a file and when I find a certain string in each line I want to do a database lookup and then add a hyperlink.
The loop as I read each record from the file is below. What I can't figure out is how to call the subroutine -- it just prints out as the name of the subroutine (&getpage).

while (<FILE>) {

if (/\>line\|/) {

s{(\>line\|[^\s]*)} {<A HREF=" &getpage($1) ">$1</A>}gs;
}

print "$_";
}

sub getlink {
my $link_index = shift;
my $link;
do some lookup for line here
return $link;
}


G

MetalGear
03-11-2010, 12:20 PM
I dont think subroutines can be called within double quotes.....
try this


while (<FILE>) {

if (/\>line\|/) {
$var = &getpage($1);
s{(\>line\|[^\s]*)} {<A HREF= $var>$1</A>}gs;
}

print "$_";
}

sub getlink {
my $link_index = shift;
my $link;
do some lookup for line here
return $link;
}

gorilla1
03-12-2010, 04:36 AM
thanks much, anil



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum