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

Re: [PBML]

Expand Messages
  • Amish Husain
    I completely agree on this, I have always used -w /use strict. Its always a good programming practice and this will help you write better/cleaner code.
    Message 1 of 20 , Sep 27, 2011
      I completely agree on this, I have always used -w /use strict. Its always a good programming practice and this will help you write better/cleaner code.


      ________________________________
      From: Shawn H Corey <shawnhcorey@...>
      To: perl-beginner@yahoogroups.com
      Cc: "Rajagopal, Jay" <jay_rajagopal@...>
      Sent: Tuesday, September 27, 2011 5:40 PM
      Subject: Re: [PBML] <STDIN>


       
      On 11-09-27 04:56 PM, Rajagopal, Jay wrote:
      > Don't use strict.

      Always `use strict;`

      Always `use warnings;`

      --
      Just my 0.00000002 million dollars worth,
      Shawn

      Confusion is the first step of understanding.

      Programming is as much about organization and communication
      as it is about coding.

      The secret to great software: Fail early & often.

      Eliminate software piracy: use only FLOSS.

      "Make something worthwhile." -- Dear Hunter



      [Non-text portions of this message have been removed]
    • merlyn@stonehenge.com
      ... Rajagopal I have professional programming experience in PERL for 10 Rajagopal years. No you don t. If you still call it PERL , you ve *never* been a
      Message 2 of 20 , Sep 28, 2011
        >>>>> "Rajagopal" == Rajagopal, Jay <jay_rajagopal@...> writes:

        Rajagopal> I have professional programming experience in PERL for 10
        Rajagopal> years.

        No you don't. If you still call it "PERL", you've *never* been a
        professional.

        Please don't lie like that.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
        See http://methodsandmessages.posterous.com/ for Smalltalk discussion
      • medura43
        Thank your for all your help, I am going to have a close look at all your comments.
        Message 3 of 20 , Sep 28, 2011
          Thank your for all your help, I am going to have a close look at all your comments.

          --- In perl-beginner@yahoogroups.com, merlyn@... wrote:
          >
          > >>>>> "Rajagopal" == Rajagopal, Jay <jay_rajagopal@...> writes:
          >
          > Rajagopal> I have professional programming experience in PERL for 10
          > Rajagopal> years.
          >
          > No you don't. If you still call it "PERL", you've *never* been a
          > professional.
          >
          > Please don't lie like that.
          >
          > --
          > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          > <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
          > See http://methodsandmessages.posterous.com/ for Smalltalk discussion
          >
        • andy_bach@wiwb.uscourts.gov
          while ( ) { my @device = (split/[ n]/); } Unfortunatley, the my here means @device goes way outside the while loop my @device; while ( ) { @device =
          Message 4 of 20 , Sep 28, 2011
            while (<CMD>) {
            my @device = (split/[\n]/);
            }

            Unfortunatley, the 'my' here means @device goes way outside the while loop
            my @device;
            while (<CMD>) {
            @device = (split/[\n]/);
            }

            same as:
            my @device = <CMD>;

            as the <...> splits on \n for you.

            >> Too many "my"s ... From this point on, the script does not make sense.

            (my $agile, my $legacy) = split(/\s+/, my $device);
            my $legacy{my $agile} = my $legacy;

            Yeah, you need to first declare the hash (as a hash, that is, w/ the '%')
            and then assign to it:
            my ($agile, $legacy) = split(/\s+/, $device);
            my %legacy;
            $legacy{$agile} = $legacy;

            'my' is only needed once per variable - it marks the variable as
            'lexically scoped' but it doesn't need to be part of any further use.
            Both:
            my @device;
            @device = <CMD>;

            and:
            my @device = <CMD>;

            are basically the same. After that you can just use @device (or
            $device[1] etc) as needed. "@devices" plural, is a better name (see
            below).

            It is silly/bad to use the same name for different vars unless there's
            really really a strong reason ... can't imagine one. So using legacy as a
            hash and a scalar var name will only confuse you more, later on. I often
            just pluralize whatever's in there (assuming 'legacy' refers to some old
            device name?)
            my %legacy_devices;
            $legacy_devices{$agile} = $legacy;

            "Perl Best Practices" suggests naming hash to reflect the fact that they
            are generally used as single objects ( $hash_name{$key} vs %hash_name -
            unlike arrays which are often used as collectives, e.g. @devices vs
            $devices[2]) so use a singular noun and a preposition (examples given:
            %title_of
            %count_for
            %is_available

            ) - a great book (Damian Conway, O'Reilly, natch) but we all can't be as
            consistenly clever as Mr. Conway, even in our dreams.

            Seems the next part you want is to get a name from the user and see if
            that is a key to your hash - you're close there, but:

            print "Which device file do you want\n "; # Test to find out why it
            chomp(my $name = <STDIN>); # hangs
            print "The value is $name \n";

            $hash_len = keys %legacy; # Number of lines in a hash
            print "The following elements\n";
            print "$agile --> $legacy{$agile} $hash_len\n";

            I think you want:
            print "$name --> $legacy_devices{$name} $hash_len\n";

            so:
            if ( exist $legacy_devices{$name} ) {
            print "$name --> $legacy_devices{$name}\n";
            }
            else {
            print "Sorry $name is not in our legacy devices list (length:
            $hash_len)\n";
            }

            or something.
            ----------------------
            Andy Bach
            Systems Mangler
            Internet: andy_bach@...
            Voice: (608) 261-5738, Cell: (608) 658-1890

            ?One of the most striking differences between a cat and a lie is that a
            cat has only nine lives.?
            Mark Twain, Vice President, American Anti-Imperialist League, and
            erstwhile writer

            [Non-text portions of this message have been removed]
          • Paul.G
            Thanks again, going through your comments. The reason, I interchange the var legacy and device. Is because, I am attempting to separate legacy device names
            Message 5 of 20 , Sep 30, 2011
              Thanks again, going through your comments.

              The reason, I interchange the var legacy and device. Is because, I am attempting to separate legacy device names from agile names. Agile names become the key in a hash for legacy devices.

              for eg:
              /dev/disk/disk43   /dev/dsk/c4t5d6

              c4t5d6 is the legacy device name for disk43

              cheers



              ________________________________
              From: "andy_bach@..." <andy_bach@...>
              To: perl-beginner@yahoogroups.com
              Sent: Thursday, 29 September 2011 1:51 AM
              Subject: [PBML] Re: <STDIN>


               
              while (<CMD>) {
              my @device = (split/[\n]/);
              }

              Unfortunatley, the 'my' here means @device goes way outside the while loop
              my @device;
              while (<CMD>) {
              @device = (split/[\n]/);
              }

              same as:
              my @device = <CMD>;

              as the <...> splits on \n for you.

              >> Too many "my"s ... From this point on, the script does not make sense.

              (my $agile, my $legacy) = split(/\s+/, my $device);
              my $legacy{my $agile} = my $legacy;

              Yeah, you need to first declare the hash (as a hash, that is, w/ the '%')
              and then assign to it:
              my ($agile, $legacy) = split(/\s+/, $device);
              my %legacy;
              $legacy{$agile} = $legacy;

              'my' is only needed once per variable - it marks the variable as
              'lexically scoped' but it doesn't need to be part of any further use.
              Both:
              my @device;
              @device = <CMD>;

              and:
              my @device = <CMD>;

              are basically the same. After that you can just use @device (or
              $device[1] etc) as needed. "@devices" plural, is a better name (see
              below).

              It is silly/bad to use the same name for different vars unless there's
              really really a strong reason ... can't imagine one. So using legacy as a
              hash and a scalar var name will only confuse you more, later on. I often
              just pluralize whatever's in there (assuming 'legacy' refers to some old
              device name?)
              my %legacy_devices;
              $legacy_devices{$agile} = $legacy;

              "Perl Best Practices" suggests naming hash to reflect the fact that they
              are generally used as single objects ( $hash_name{$key} vs %hash_name -
              unlike arrays which are often used as collectives, e.g. @devices vs
              $devices[2]) so use a singular noun and a preposition (examples given:
              %title_of
              %count_for
              %is_available

              ) - a great book (Damian Conway, O'Reilly, natch) but we all can't be as
              consistenly clever as Mr. Conway, even in our dreams.

              Seems the next part you want is to get a name from the user and see if
              that is a key to your hash - you're close there, but:

              print "Which device file do you want\n "; # Test to find out why it
              chomp(my $name = <STDIN>); # hangs
              print "The value is $name \n";

              $hash_len = keys %legacy; # Number of lines in a hash
              print "The following elements\n";
              print "$agile --> $legacy{$agile} $hash_len\n";

              I think you want:
              print "$name --> $legacy_devices{$name} $hash_len\n";

              so:
              if ( exist $legacy_devices{$name} ) {
              print "$name --> $legacy_devices{$name}\n";
              }
              else {
              print "Sorry $name is not in our legacy devices list (length:
              $hash_len)\n";
              }

              or something.
              ----------------------
              Andy Bach
              Systems Mangler
              Internet: andy_bach@...
              Voice: (608) 261-5738, Cell: (608) 658-1890

              ?One of the most striking differences between a cat and a lie is that a
              cat has only nine lives.?
              Mark Twain, Vice President, American Anti-Imperialist League, and
              erstwhile writer

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




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