Find the answer to your Linux question:
Results 1 to 6 of 6
1) I am using a variable of another scripts in my script, following is my code :- #!/usr/bin/perl -w use strict; require "./test.cgi"; for my $reslt (@values) { if ( ...
  1. #1
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114

    how to use a variable in multiple perl scripts

    1) I am using a variable of another scripts in my script, following is my code :-

    #!/usr/bin/perl -w
    use strict;

    require "./test.cgi";

    for my $reslt (@values) {
    if ( $rslt eq "red" ) { next; }
    print "Value find";
    &test_fucn;

    }


    @values is from another script

    but I am getting following error with use sctrict
    Global symbol "@values" requires explicit package name at
    compilation errors.

    else

    Name "main::values" used only once: possible typo at
    syntax OK


    Any other better way ???
    Switched to Scripting

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Try putting this near the top:
    Code:
    our @values;
    ... and, just to be safe, try putting the same statement near the top of the file you're requiring.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114
    I have another query

    I want to call a function/subroutibe test_fucn from test.cgi for that I am doing following

    #!/usr/bin/perl -w
    use strict;

    require "./test.cgi";

    for my $reslt (@values) {
    if ( $rslt eq "red" ) { next; }
    print "Value find";
    &test_fucn;

    }


    But problem - It is giving me whole printable output from test.cgi which is not a part of test_fucn.

    any suggestions, so that I can use only subroutine ?
    Switched to Scripting

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Whoa, whoa, WHOA! Did my suggestion work for you?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114
    Ya now I am not getting those errors msg?

    Thanks

    Now I am looking for some other issue

    I think require can not work in that case do u have any other suggestions?
    Switched to Scripting

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    You should go to that other thread. But you probably know that already. This is like letters getting crossed in the mail. :)
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

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