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

Re: [PBML] func

Expand Messages
  • John Francini
    In the first, x is a global variable; in the second, x has two instances -- the global, and the local inside the subroutine. Mind you, neither will output
    Message 1 of 4 , Feb 26, 2010
    • 0 Attachment
      In the first, x is a global variable; in the second, x has two
      instances -- the global, and the local inside the subroutine. Mind
      you, neither will output anything because you don't call the
      subroutine in the example code given. Once modified to actually run,
      both will give the same output. In the first case, you're changing
      the global $x to 0; in the second, you're creating a local $x which is
      set to zero.

      munch> cat > foo.pl
      #!/usr/bin/perl
      $x=12;
      abcd();
      sub abcd
      {
      $x=0;
      print $x;
      }
      munch> ./foo.pl
      0
      munch> cat > foo.pl
      #!/usr/bin/perl
      $x=12;
      abcd();
      sub abcd
      {
      local $x=0;
      print $x;
      }
      munch> ./foo.pl
      0
      munch>

      j

      On 26 Feb 2010, at 7:28, Jagadesh wrote:

      > what is the difference between
      > $x=12;
      > sub abcd
      > {
      > $x=0;
      > print $x;
      > }
      >
      > and
      >
      > $x=12;
      > sub abcd
      > {
      > local $x=0;
      > print $x;
      > }
      >
      >
      >



      [Non-text portions of this message have been removed]
    • marquee7_2000@yahoo.com
      Hey, John,...It s Mario (formerly with PRC) How are things going (assuming that this is the same JF)? Sent from my Verizon Wireless BlackBerry ... From: John
      Message 2 of 4 , Feb 26, 2010
      • 0 Attachment
        Hey, John,...It's Mario (formerly with PRC) How are things going (assuming that this is the same JF)?
        Sent from my Verizon Wireless BlackBerry

        -----Original Message-----
        From: John Francini <francini@...>
        Date: Fri, 26 Feb 2010 13:34:31
        To: <perl-beginner@yahoogroups.com>
        Subject: Re: [PBML] func

        In the first, x is a global variable; in the second, x has two
        instances -- the global, and the local inside the subroutine. Mind
        you, neither will output anything because you don't call the
        subroutine in the example code given. Once modified to actually run,
        both will give the same output. In the first case, you're changing
        the global $x to 0; in the second, you're creating a local $x which is
        set to zero.

        munch> cat > foo.pl
        #!/usr/bin/perl
        $x=12;
        abcd();
        sub abcd
        {
        $x=0;
        print $x;
        }
        munch> ./foo.pl
        0
        munch> cat > foo.pl
        #!/usr/bin/perl
        $x=12;
        abcd();
        sub abcd
        {
        local $x=0;
        print $x;
        }
        munch> ./foo.pl
        0
        munch>

        j

        On 26 Feb 2010, at 7:28, Jagadesh wrote:

        > what is the difference between
        > $x=12;
        > sub abcd
        > {
        > $x=0;
        > print $x;
        > }
        >
        > and
        >
        > $x=12;
        > sub abcd
        > {
        > local $x=0;
        > print $x;
        > }
        >
        >
        >



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



        ------------------------------------

        Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo! Groups Links
      • Piroska Devay
        In one case you set the global x to 0 and if you call this subr. x the value of x will be changed. When you say local the local x will not be seen outside of
        Message 3 of 4 , Feb 26, 2010
        • 0 Attachment
          In one case you set the global x to 0 and if you call this subr. x
          the value of x will be changed.
          When you say local the local x will not be seen outside of the subr.
          and won't change global x.
          Instead of local it is better to use my $x=0;


          On Feb 26, 2010, at 7:28 AM, Jagadesh wrote:

          > what is the difference between
          > $x=12;
          > sub abcd
          > {
          > $x=0;
          > print $x;
          > }
          >
          > and
          >
          > $x=12;
          > sub abcd
          > {
          > local $x=0;
          > print $x;
          > }
          >
          >



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