Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I found a perl script in internet and would like to converted in subroutine in order to embed that in another perl script. Could you help me? Thanks in ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2012
    Posts
    57

    Subroutines in perl


    Hi,

    I found a perl script in internet and would like to converted in subroutine in order to embed that in another perl script. Could you help me?
    Thanks in advance.

    Code:
    #!/usr/bin/perl
    use Algorithm::Diff qw(traverse_sequences);
    use warnings;
    
    
    print cam ("thank you", "thank you very much");
    
    
    
    sub cam {
    my @one1 = qw(@_);
    my @two1 = qw(@_);
    my @one = sort @one1;
    my @two = sort @two1;
      
    my $found = 0;
    traverse_sequences(\@one, \@two, {
        MATCH => sub { count ($one[$_[0]], $two[$_[1]]) },
        });
      
    
    sub count {
    $found++;
        
      }
    return $found;
    }

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by corfuitl View Post
    I found a perl script in internet and would like to converted in subroutine in order to embed that in another perl script. Could you help me?
    it is mostly two subroutines already. but if you want to subroutine-ize the print portion, you could do something like this in your main script:

    Code:
    sub cam_print {
      print cam ("thank you", "thank you very much");
    }
    and include the other two subs, as is. at the top of the script, be sure to include the Algo::Diff module (use ...).

    then call it in your main perl script like:

    Code:
    &cam_print;
    or, if you want to get fancy (and learn something), you could make it a Perl module and then use/require that module.

Posting Permissions

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