in reply to Re^5: Can not use JSON module
in thread Can not use JSON module

Hi, Thank you everyone for helping me. Thanks karlgoethebier again for providing the function, it solved my problem. Although, I tried all JSON modules suggested in the discussion and they are working fine on ubuntu but not on the board as I am unable to install modules on the board. Problem resolved. one query as below : I have pasted the function in one of the cgi file and tested it.It is working fine and I am able to extract json. As I have multiple cgi files, do I need to copy-paste that function in each file or is there any way to keep that function in separate file and use it, if possible how? Thanks

Replies are listed 'Best First'.
Re^7: Can not use JSON module
by hippo (Archbishop) on Jun 06, 2017 at 10:48 UTC
    As I have multiple cgi files, do I need to copy-paste that function in each file or is there any way to keep that function in separate file and use it, if possible how?

    This sort of code re-use is performed in Perl using modules. See Simple Module Tutorial for how to create and use a module for such a purpose. There are other, similar guides for Creating and Distributing Modules in our Tutorials section.

Re^7: Can not use JSON module
by Corion (Patriarch) on Jun 06, 2017 at 10:32 UTC

    The traditional approach to keeping an often-used function in a file is named a "module". You have already been shown the links to the modules and also links on how to install modules into a Perl.

    Most likely, use lib will be enough, but a look at Yes, even you can use CPAN and/or local::lib won't hurt either.

Re^7: Can not use JSON module
by karlgoethebier (Abbot) on Jun 06, 2017 at 11:36 UTC
    "Thanks..."

    My pleasure. Next step: Go over that bridge named "module" - as some fellow monks mentioned already.

    Like this, less or more:

    package YourModule; use strict; use warnings; use Exporter qw(import); our ( $VERSION, @EXPORT_OK ); $VERSION = 1.00; @EXPORT_OK = qw(from_json); sub from_json { # stuff... } 1;

    See also Re: How to parse the logs in a generic manner

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    Furthermore I consider that Donald Trump must be impeached as soon as possible

      Hi, Done. Thank you everyone for help. :D