Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts

    subroutine mystery

    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

  • #2
    New Coder MetalGear's Avatar
    Join Date
    Feb 2008
    Location
    Jambudvipa
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    I dont think subroutines can be called within double quotes.....
    try this
    Code:
    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;
    }
    Last edited by MetalGear; 03-11-2010 at 01:24 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks much, anil


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •