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

Re: [PBML] Re: Need some serious help. Day of the month from a date

Expand Messages
  • Charles K. Clarkson
    ... print Dumper { map {$_ = get_day_name($_)} }; ... { . . . } is an anonymous hash. An anonymous hash is a reference to
    Message 1 of 4 , Nov 29, 2001
      <jonathan.mark2@...>

      : I tried playing with the excellent code that Charles posted, and
      : tried to use a reference to an anonymous hash
      :
      : print Dumper \{map {$_ => get_day_name()} <DATA>};

      print Dumper { map {$_ => get_day_name($_)} <DATA> };

      : It gives me a compliation error. Why? It seems to me that the map
      : function returns a hash. If I surround that hash with brackets, isn't
      : that an anonymous hash?

      { . . . } is an anonymous hash. An anonymous hash is a reference
      to a unamed hash.

      : If I put a backwards slash in front of an anonymous hash, isn't the
      : result a reference to an anonymous hash?

      \{ . . . } is a refeence to an anonymous hash which is a reference
      to a reference to a unamed hash and throws the error.

      : Finally, can't I pass that reference to the Dumper function?

      Yes, you can. It's preferable for hashes and arrays.

      : Why doesn't this approach work?

      Occam's razor.


      HTH,
      Charles K. Clarkson
      Clarkson Energy Homes, Inc.

      Entities should not be multiplied unnecessarily.
      - William of Occam
    • Charles K. Clarkson
      ... This runs fine on my system. What do you mean by it does not compile ? What specific error messages are you getting?
      Message 2 of 4 , Nov 30, 2001
        <jonathan.mark2@...>

        : Thanks for the quick response. Perl doesn't compile
        :
        : print Dumper {map {$_ => get_day_name($_)} <DATA>};
        :
        : either. Nor does it compile
        :
        : print Dumper \{map {$_ => get_day_name($_)} <DATA>};
        :
        : Why? Any ideas? Your script runs fine as long as I don't mess with
        : it. But messing with scripts is the whole idea behind Perl.

        This runs fine on my system. What do you mean by 'it does not
        compile'? What specific error messages are you getting?

        #!/usr/bin/perl
        use strict;
        use warnings;
        #use diagnostics;

        use Data::Dumper;
        use POSIX;

        print Dumper { map {$_ => get_day_name()} <DATA> };

        sub get_day_name {
        chomp;
        my @date = m|^(\d+)/(\d+)/(\d+)|;
        $date[1] -= 1;
        $date[2] -= 1900;
        return strftime "%A", 0, 0, 0, @date;
        }

        __END__
        26/11/2001_Page_1.pp
        27/11/2001_Page_1.pp
        28/11/2001_Page_1.pp
        29/11/2001_Page_1.pp


        HTH,
        Charles K. Clarkson
        Clarkson Energy Homes, Inc.

        Language is the dress of thought.
        - Samuel Johnson
      • jonathan.mark2@dyncorp.com
        Thanks for the quick response. Perl doesn t compile print Dumper {map {$_ = get_day_name($_)} }; either. Nor does it compile print Dumper {map {$_ =
        Message 3 of 4 , Nov 30, 2001
          Thanks for the quick response. Perl doesn't compile

          print Dumper {map {$_ => get_day_name($_)} <DATA>};

          either. Nor does it compile

          print Dumper \{map {$_ => get_day_name($_)} <DATA>};

          Why? Any ideas? Your script runs fine as long as I don't mess with
          it. But messing with scripts is the whole idea behind Perl.



          --- In perl-beginner@y..., "Charles K. Clarkson" <cclarkson@h...>
          wrote:
          > <jonathan.mark2@d...>
          >
          > : I tried playing with the excellent code that Charles posted, and
          > : tried to use a reference to an anonymous hash
          > :
          > : print Dumper \{map {$_ => get_day_name()} <DATA>};
          >
          > print Dumper { map {$_ => get_day_name($_)} <DATA> };
          >
          > : It gives me a compliation error. Why? It seems to me that the map
          > : function returns a hash. If I surround that hash with brackets,
          isn't
          > : that an anonymous hash?
          >
          > { . . . } is an anonymous hash. An anonymous hash is a reference
          > to a unamed hash.
          >
          > : If I put a backwards slash in front of an anonymous hash, isn't
          the
          > : result a reference to an anonymous hash?
          >
          > \{ . . . } is a refeence to an anonymous hash which is a
          reference
          > to a reference to a unamed hash and throws the error.
          >
          > : Finally, can't I pass that reference to the Dumper function?
          >
          > Yes, you can. It's preferable for hashes and arrays.
          >
          > : Why doesn't this approach work?
          >
          > Occam's razor.
          >
          >
          > HTH,
          > Charles K. Clarkson
          > Clarkson Energy Homes, Inc.
          >
          > Entities should not be multiplied unnecessarily.
          > - William of Occam
        • jonathan.mark2@dyncorp.com
          Thanks. I found the error. It was in the line above the call to map. Instead of using Perl s // to create a comment I was using /* */ to create a comment,
          Message 4 of 4 , Dec 1, 2001
            Thanks. I found the error. It was in the line above the call to map.
            Instead of using Perl's // to create a comment I was using /* */ to
            create a comment, which is gibberish to perl.


            --- In perl-beginner@y..., "Charles K. Clarkson" <cclarkson@h...>
            wrote:
            > <jonathan.mark2@d...>
            >
            > : Thanks for the quick response. Perl doesn't compile
            > :
            > : print Dumper {map {$_ => get_day_name($_)} <DATA>};
            > :
            > : either. Nor does it compile
            > :
            > : print Dumper \{map {$_ => get_day_name($_)} <DATA>};
            > :
            > : Why? Any ideas? Your script runs fine as long as I don't mess
            with
            > : it. But messing with scripts is the whole idea behind Perl.
            >
            > This runs fine on my system. What do you mean by 'it does not
            > compile'? What specific error messages are you getting?
            >
            > #!/usr/bin/perl
            > use strict;
            > use warnings;
            > #use diagnostics;
            >
            > use Data::Dumper;
            > use POSIX;
            >
            > print Dumper { map {$_ => get_day_name()} <DATA> };
            >
            > sub get_day_name {
            > chomp;
            > my @date = m|^(\d+)/(\d+)/(\d+)|;
            > $date[1] -= 1;
            > $date[2] -= 1900;
            > return strftime "%A", 0, 0, 0, @date;
            > }
            >
            > __END__
            > 26/11/2001_Page_1.pp
            > 27/11/2001_Page_1.pp
            > 28/11/2001_Page_1.pp
            > 29/11/2001_Page_1.pp
            >
            >
            > HTH,
            > Charles K. Clarkson
            > Clarkson Energy Homes, Inc.
            >
            > Language is the dress of thought.
            > - Samuel Johnson
          Your message has been successfully submitted and would be delivered to recipients shortly.