Loading ...
Sorry, an error occurred while loading the content.
 

RE: [perlguitest] Re: Writing a cross platform Perl script

Expand Messages
  • Sonam Chauhan
    Thanks Clement - it was require as you said. Thanks to Susruth as well. . I think can do away with a BEGIN block: the following code gave expected ... perl
    Message 1 of 10 , May 25, 2006
      Thanks Clement - it was 'require' as you said. Thanks to Susruth as
      well. .



      I think can do away with a BEGIN block: the following code gave expected
      output under both Cygwin and Windows:

      ----

      perl -e "if ($^O eq 'cygwin') {require Proc::ProcessTable; print 'found
      cygwin'} elsif ($^O eq 'MSWin32') {require Win32::GuiTest; print 'found
      windows'}"

      ----



      Sincerely,

      Sonam Chauhan

      ________________________________

      From: perlguitest@yahoogroups.com [mailto:perlguitest@yahoogroups.com]
      On Behalf Of Clement Cherlin
      Sent: Friday, 26 May 2006 5:53 AM
      To: perlguitest@yahoogroups.com
      Subject: [perlguitest] Re: Writing a cross platform Perl script



      --- In perlguitest@yahoogroups.com, Susruth Sudhakaran <sush_1205@...>
      wrote:
      >
      > sonam,
      >
      > try including the conditional 'use' statement inside a BEGIN
      block..That should work

      Actually, it won't, since "use" is already a compile-time directive.
      Using it inside a BEGIN block is redundant. From "perlmod" in the
      Perl docs:

      ] Perl modules are included into your program by saying
      ]
      ] use Module;
      ] or
      ] use Module LIST;
      ]
      ] This is exactly equivalent to
      ]
      ] BEGIN { require Module; import Module; }
      ] or
      ] BEGIN { require Module; import Module LIST; }

      What you really want is something like this:

      BEGIN {
      if ($^O =~ /MSWin/) {

      require Win32::GuiTest;

      }
      else {

      require Proc::ProcessTable;

      }
      }






      SPONSORED LINKS

      Basic programming language
      <http://groups.yahoo.com/gads?t=ms&k=Basic+programming+language&w1=Basic
      +programming+language&w2=C+programming+language&w3=Computer+programming+
      languages&w4=The+c+programming+language&w5=C+++programming+language&w6=S
      oftware+programming+language&c=6&s=193&.sig=p2tsb9F38_BRtgYd-Lrx9w>

      C programming language
      <http://groups.yahoo.com/gads?t=ms&k=C+programming+language&w1=Basic+pro
      gramming+language&w2=C+programming+language&w3=Computer+programming+lang
      uages&w4=The+c+programming+language&w5=C+++programming+language&w6=Softw
      are+programming+language&c=6&s=193&.sig=s417rQDhIfEJWoylZxl7QQ>

      Computer programming languages
      <http://groups.yahoo.com/gads?t=ms&k=Computer+programming+languages&w1=B
      asic+programming+language&w2=C+programming+language&w3=Computer+programm
      ing+languages&w4=The+c+programming+language&w5=C+++programming+language&
      w6=Software+programming+language&c=6&s=193&.sig=QgdknWHEB-7BcpDElLJcYw>


      The c programming language
      <http://groups.yahoo.com/gads?t=ms&k=The+c+programming+language&w1=Basic
      +programming+language&w2=C+programming+language&w3=Computer+programming+
      languages&w4=The+c+programming+language&w5=C+++programming+language&w6=S
      oftware+programming+language&c=6&s=193&.sig=DSnZ2EFeZa_krjnfz_P5vQ>

      C++ programming language
      <http://groups.yahoo.com/gads?t=ms&k=C+++programming+language&w1=Basic+p
      rogramming+language&w2=C+programming+language&w3=Computer+programming+la
      nguages&w4=The+c+programming+language&w5=C+++programming+language&w6=Sof
      tware+programming+language&c=6&s=193&.sig=IvzvhTPnaj_LFsbqs2knAg>

      Software programming language
      <http://groups.yahoo.com/gads?t=ms&k=Software+programming+language&w1=Ba
      sic+programming+language&w2=C+programming+language&w3=Computer+programmi
      ng+languages&w4=The+c+programming+language&w5=C+++programming+language&w
      6=Software+programming+language&c=6&s=193&.sig=pUnPrY01tNTjZVkDEHkvYQ>



      ________________________________

      YAHOO! GROUPS LINKS



      * Visit your group "perlguitest
      <http://groups.yahoo.com/group/perlguitest> " on the web.

      * To unsubscribe from this group, send an email to:
      perlguitest-unsubscribe@yahoogroups.com
      <mailto:perlguitest-unsubscribe@yahoogroups.com?subject=Unsubscribe>

      * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
      Service <http://docs.yahoo.com/info/terms/> .



      ________________________________



      [Non-text portions of this message have been removed]
    • Sonam Chauhan
      Sorry Clement - you are exactly right - the require statements need to be within BEGIN blocks for subroutines in modules to be referenced properly at compile
      Message 2 of 10 , May 25, 2006
        Sorry Clement - you are exactly right - the 'require' statements need to
        be within BEGIN blocks for subroutines in modules to be referenced
        properly at compile time.



        As you said:



        BEGIN {
        if ($^O =~ /MSWin/) {
        require Win32::GuiTest;
        }
        else {
        require Proc::ProcessTable;
        }
        }




        Sincerely,

        Sonam Chauhan

        ________________________________

        From: Sonam Chauhan
        Sent: Friday, 26 May 2006 11:26 AM
        To: 'perlguitest@yahoogroups.com'
        Subject: RE: [perlguitest] Re: Writing a cross platform Perl script



        Thanks Clement - it was 'require' as you said. Thanks to Susruth as
        well. .



        I think can do away with a BEGIN block: the following code gave expected
        output under both Cygwin and Windows:

        ----

        perl -e "if ($^O eq 'cygwin') {require Proc::ProcessTable; print 'found
        cygwin'} elsif ($^O eq 'MSWin32') {require Win32::GuiTest; print 'found
        windows'}"

        ----



        Sincerely,

        Sonam Chauhan

        ________________________________

        From: perlguitest@yahoogroups.com [mailto:perlguitest@yahoogroups.com]
        On Behalf Of Clement Cherlin
        Sent: Friday, 26 May 2006 5:53 AM
        To: perlguitest@yahoogroups.com
        Subject: [perlguitest] Re: Writing a cross platform Perl script



        --- In perlguitest@yahoogroups.com, Susruth Sudhakaran <sush_1205@...>
        wrote:
        >
        > sonam,
        >
        > try including the conditional 'use' statement inside a BEGIN
        block..That should work

        Actually, it won't, since "use" is already a compile-time directive.
        Using it inside a BEGIN block is redundant. From "perlmod" in the
        Perl docs:

        ] Perl modules are included into your program by saying
        ]
        ] use Module;
        ] or
        ] use Module LIST;
        ]
        ] This is exactly equivalent to
        ]
        ] BEGIN { require Module; import Module; }
        ] or
        ] BEGIN { require Module; import Module LIST; }

        What you really want is something like this:

        BEGIN {
        if ($^O =~ /MSWin/) {

        require Win32::GuiTest;

        }
        else {

        require Proc::ProcessTable;

        }
        }





        SPONSORED LINKS

        Basic programming language
        <http://groups.yahoo.com/gads?t=ms&k=Basic+programming+language&w1=Basic
        +programming+language&w2=C+programming+language&w3=Computer+programming+
        languages&w4=The+c+programming+language&w5=C+++programming+language&w6=S
        oftware+programming+language&c=6&s=193&.sig=p2tsb9F38_BRtgYd-Lrx9w>

        C programming language
        <http://groups.yahoo.com/gads?t=ms&k=C+programming+language&w1=Basic+pro
        gramming+language&w2=C+programming+language&w3=Computer+programming+lang
        uages&w4=The+c+programming+language&w5=C+++programming+language&w6=Softw
        are+programming+language&c=6&s=193&.sig=s417rQDhIfEJWoylZxl7QQ>

        Computer programming languages
        <http://groups.yahoo.com/gads?t=ms&k=Computer+programming+languages&w1=B
        asic+programming+language&w2=C+programming+language&w3=Computer+programm
        ing+languages&w4=The+c+programming+language&w5=C+++programming+language&
        w6=Software+programming+language&c=6&s=193&.sig=QgdknWHEB-7BcpDElLJcYw>


        The c programming language
        <http://groups.yahoo.com/gads?t=ms&k=The+c+programming+language&w1=Basic
        +programming+language&w2=C+programming+language&w3=Computer+programming+
        languages&w4=The+c+programming+language&w5=C+++programming+language&w6=S
        oftware+programming+language&c=6&s=193&.sig=DSnZ2EFeZa_krjnfz_P5vQ>

        C++ programming language
        <http://groups.yahoo.com/gads?t=ms&k=C+++programming+language&w1=Basic+p
        rogramming+language&w2=C+programming+language&w3=Computer+programming+la
        nguages&w4=The+c+programming+language&w5=C+++programming+language&w6=Sof
        tware+programming+language&c=6&s=193&.sig=IvzvhTPnaj_LFsbqs2knAg>

        Software programming language
        <http://groups.yahoo.com/gads?t=ms&k=Software+programming+language&w1=Ba
        sic+programming+language&w2=C+programming+language&w3=Computer+programmi
        ng+languages&w4=The+c+programming+language&w5=C+++programming+language&w
        6=Software+programming+language&c=6&s=193&.sig=pUnPrY01tNTjZVkDEHkvYQ>



        ________________________________

        YAHOO! GROUPS LINKS



        * Visit your group "perlguitest
        <http://groups.yahoo.com/group/perlguitest> " on the web.

        * To unsubscribe from this group, send an email to:
        perlguitest-unsubscribe@yahoogroups.com
        <mailto:perlguitest-unsubscribe@yahoogroups.com?subject=Unsubscribe>

        * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
        Service <http://docs.yahoo.com/info/terms/> .



        ________________________________



        [Non-text portions of this message have been removed]
      • Clement Cherlin
        If that works for you, great! For an object-oriented module, it probably doesn t matter whether you use a BEGIN block or not, since method calls are
        Message 3 of 10 , May 26, 2006
          If that works for you, great! For an object-oriented module, it probably doesn't matter whether you use a BEGIN block or not, since method calls are dispatched at run-time.

          On the other hand, if you want to import symbols from a package, use package constants, take advantage of sub prototypes, or other compile-time features and optimizations, you'll need to put your require statement into a BEGIN block so that the module is available at compile-time.

          Basically, putting a require statement inside a BEGIN block doesn't hurt and it could help, so it's safer as a rule of thumb.

          ----- Original Message ----
          From: Sonam Chauhan <sonam.chauhan@...>
          To: perlguitest@yahoogroups.com
          Sent: Thursday, May 25, 2006 6:25:30 PM
          Subject: RE: [perlguitest] Re: Writing a cross platform Perl script

          Thanks Clement - it was 'require' as you said. Thanks to Susruth as
          well. .



          I think can do away with a BEGIN block: the following code gave expected
          output under both Cygwin and Windows:

          ----

          perl -e "if ($^O eq 'cygwin') {require Proc::ProcessTable; print 'found
          cygwin'} elsif ($^O eq 'MSWin32') {require Win32::GuiTest; print 'found
          windows'}"

          ----



          Sincerely,

          Sonam Chauhan

          ________________________________

          From: perlguitest@yahoogroups.com [mailto:perlguitest@yahoogroups.com]
          On Behalf Of Clement Cherlin
          Sent: Friday, 26 May 2006 5:53 AM
          To: perlguitest@yahoogroups.com
          Subject: [perlguitest] Re: Writing a cross platform Perl script



          --- In perlguitest@yahoogroups.com, Susruth Sudhakaran <sush_1205@...>
          wrote:
          >
          > sonam,
          >
          > try including the conditional 'use' statement inside a BEGIN
          block..That should work

          Actually, it won't, since "use" is already a compile-time directive.
          Using it inside a BEGIN block is redundant. From "perlmod" in the
          Perl docs:

          ] Perl modules are included into your program by saying
          ]
          ] use Module;
          ] or
          ] use Module LIST;
          ]
          ] This is exactly equivalent to
          ]
          ] BEGIN { require Module; import Module; }
          ] or
          ] BEGIN { require Module; import Module LIST; }

          What you really want is something like this:

          BEGIN {
          if ($^O =~ /MSWin/) {

          require Win32::GuiTest;

          }
          else {

          require Proc::ProcessTable;

          }
          }






          SPONSORED LINKS

          Basic programming language
          <http://groups.yahoo.com/gads?t=ms&k=Basic+programming+language&w1=Basic
          +programming+language&w2=C+programming+language&w3=Computer+programming+
          languages&w4=The+c+programming+language&w5=C+++programming+language&w6=S
          oftware+programming+language&c=6&s=193&.sig=p2tsb9F38_BRtgYd-Lrx9w>

          C programming language
          <http://groups.yahoo.com/gads?t=ms&k=C+programming+language&w1=Basic+pro
          gramming+language&w2=C+programming+language&w3=Computer+programming+lang
          uages&w4=The+c+programming+language&w5=C+++programming+language&w6=Softw
          are+programming+language&c=6&s=193&.sig=s417rQDhIfEJWoylZxl7QQ>

          Computer programming languages
          <http://groups.yahoo.com/gads?t=ms&k=Computer+programming+languages&w1=B
          asic+programming+language&w2=C+programming+language&w3=Computer+programm
          ing+languages&w4=The+c+programming+language&w5=C+++programming+language&
          w6=Software+programming+language&c=6&s=193&.sig=QgdknWHEB-7BcpDElLJcYw>


          The c programming language
          <http://groups.yahoo.com/gads?t=ms&k=The+c+programming+language&w1=Basic
          +programming+language&w2=C+programming+language&w3=Computer+programming+
          languages&w4=The+c+programming+language&w5=C+++programming+language&w6=S
          oftware+programming+language&c=6&s=193&.sig=DSnZ2EFeZa_krjnfz_P5vQ>

          C++ programming language
          <http://groups.yahoo.com/gads?t=ms&k=C+++programming+language&w1=Basic+p
          rogramming+language&w2=C+programming+language&w3=Computer+programming+la
          nguages&w4=The+c+programming+language&w5=C+++programming+language&w6=Sof
          tware+programming+language&c=6&s=193&.sig=IvzvhTPnaj_LFsbqs2knAg>

          Software programming language
          <http://groups.yahoo.com/gads?t=ms&k=Software+programming+language&w1=Ba
          sic+programming+language&w2=C+programming+language&w3=Computer+programmi
          ng+languages&w4=The+c+programming+language&w5=C+++programming+language&w
          6=Software+programming+language&c=6&s=193&.sig=pUnPrY01tNTjZVkDEHkvYQ>



          ________________________________

          YAHOO! GROUPS LINKS



          * Visit your group "perlguitest
          <http://groups.yahoo.com/group/perlguitest> " on the web.

          * To unsubscribe from this group, send an email to:
          perlguitest-unsubscribe@yahoogroups.com
          <mailto:perlguitest-unsubscribe@yahoogroups.com?subject=Unsubscribe>

          * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
          Service <http://docs.yahoo.com/info/terms/> .



          ________________________________



          [Non-text portions of this message have been removed]







          Yahoo! Groups Links











          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.