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

Array Testing

Expand Messages
  • Joe Catanzaro
    ... Use grep to apply a condition to all elements in the list and return only those for which the condition was true: @MATCHING = grep { TEST ($_) } @LIST;
    Message 1 of 8 , Oct 1, 2002
    • 0 Attachment
      This was taken from O'Reilly's Perl Cookbook, recipe 4.13:

      --------- snip ---------

      Use grep to apply a condition to all elements in the list and return only
      those for which the condition was true:

      @MATCHING = grep { TEST ($_) } @LIST;

      Discussion

      This could also be accomplished with a foreach loop:

      @matching = ();
      foreach (@list) {
      push(@matching, $_) if TEST ($_);
      }

      ------- snip ----------

      My question: What is TEST? Does that come from a module? Is it a function?
      If it's neither, can someone provide an example of TEST?

      Thanks,





      Joe Catanzaro
      joecatanzaro@...
    • prakash
      Print.pm just get the information like $object- printPage( template1 ); and it prints the templates.. but i am getting this error when compiling.. have any
      Message 2 of 8 , Oct 1, 2002
      • 0 Attachment
        Print.pm just get the information like

        $object->printPage("template1");

        and it prints the templates.. but i am getting this error when compiling..
        have any answers ?? SURE IT IS NOT ADDITION PROBLEM.... !!!



        ************************

        Useless use of string in void context at /home/aebolts/cgi-bin/PM/Print.pm
        line 32.
        Useless use of string in void context at /home/aebolts/cgi-bin/PM/Print.pm
        line 40.

        ************************
      • Charles K. Clarkson
        ... It s neither (or both, or either). TEST ($_) is just a place holder. You could put in a regular expression, a subroutine, etc. As for an example look at
        Message 3 of 8 , Oct 1, 2002
        • 0 Attachment
          Joe Catanzaro [mailto:joecatanzaro@...] wrote:

          : Use grep to apply a condition to all elements in the list and
          : return only
          : those for which the condition was true:
          :
          : @MATCHING = grep { TEST ($_) } @LIST;
          :
          : Discussion
          :
          : This could also be accomplished with a foreach loop:
          :
          : @matching = ();
          : foreach (@list) {
          : push(@matching, $_) if TEST ($_);
          : }
          :
          : ------- snip ----------
          :
          : My question: What is TEST? Does that come from a module? Is
          : it a function?
          : If it's neither, can someone provide an example of TEST?

          It's neither (or both, or either). TEST ($_) is
          just a place holder. You could put in a regular
          expression, a subroutine, etc.

          As for an example look at the rest of the section

          # TEST ($_) is $_ > 1_000_000
          @bigs = grep { $_ > 1_000_000 } @nums;

          # TEST ($_) is $users{$_} > 1e7
          @pigs = grep { $users{$_} > 1e7 } keys %users;

          # TEST ($_) /^gnat /
          @matching = grep { /^gnat / } `who`;

          # TEST ($_) is $_->position() eq 'Engineer'
          @engineers = grep { $_->position() eq 'Engineer' } @employees;

          # TEST ($_) is $_->income >= 26_000 && $_->income < 30_000
          @secondary_assistance = grep { $_->income >= 26_000 &&
          $_->income < 30_000 }
          @applicants;


          HTH,

          Charles K. Clarkson
          --
          Head Bottle Washer,
          Clarkson Energy Homes, Inc.
          Small commercial and residential rehabilitation specialists.
          254 968-8328

          CJ Web Work - Solutions for Real Estate Investors.
          972 216-4952

          CJ Web Hosting - Affordable Hosting - Custom Accounts.
          254 968-8328
        • Jeff 'japhy' Pinyan
          ... Useless posting of warning (not error) message without showing the actual lines of code at NFBBJIGGMLIHLMOIHEDAEEBBCLAA.prakash@foothill.net. -- Jeff
          Message 4 of 8 , Oct 1, 2002
          • 0 Attachment
            On Oct 1, prakash said:

            >Print.pm just get the information like
            >
            >$object->printPage("template1");
            >
            >and it prints the templates.. but i am getting this error when compiling..
            >have any answers ?? SURE IT IS NOT ADDITION PROBLEM.... !!!

            >Useless use of string in void context at /home/aebolts/cgi-bin/PM/Print.pm
            >line 32.
            >Useless use of string in void context at /home/aebolts/cgi-bin/PM/Print.pm
            >line 40.

            Useless posting of warning (not error) message without showing the actual
            lines of code at NFBBJIGGMLIHLMOIHEDAEEBBCLAA.prakash@....

            --
            Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
            RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
            ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
            <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
            [ I'm looking for programming work. If you like my work, let me know. ]
          • Charles K. Clarkson
            ... I hate when that happens. :)
            Message 5 of 8 , Oct 1, 2002
            • 0 Attachment
              Jeff 'japhy' Pinyan [mailto:japhy@...] wrote:

              : Useless posting of warning (not error) message
              : without showing the actual lines of code at
              : NFBBJIGGMLIHLMOIHEDAEEBBCLAA.prakash@....

              I hate when that happens. :)
            • Jeff 'japhy' Pinyan
              ... Me too. Prakash, as I requested, please show us the context of lines 32 and 40 of Print.pm. We can t debug code we can t see. -- Jeff japhy Pinyan
              Message 6 of 8 , Oct 1, 2002
              • 0 Attachment
                On Oct 1, Charles K. Clarkson said:

                >Jeff 'japhy' Pinyan [mailto:japhy@...] wrote:
                >
                >: Useless posting of warning (not error) message
                >: without showing the actual lines of code at
                >: NFBBJIGGMLIHLMOIHEDAEEBBCLAA.prakash@....
                >
                > I hate when that happens. :)

                Me too. Prakash, as I requested, please show us the context of lines 32
                and 40 of Print.pm. We can't debug code we can't see.

                --
                Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
                RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
                ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
                <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
                [ I'm looking for programming work. If you like my work, let me know. ]
              • prakash
                Hello guys i solved the previous error.. but have new question.. ******** i am passing an object called (Org) to different object (Print).. there i get the
                Message 7 of 8 , Oct 2, 2002
                • 0 Attachment
                  Hello guys i solved the previous error.. but have new question..


                  ********

                  i am passing an object called (Org) to different object (Print)..
                  there i get the object and get the information for that object (username)..
                  but when i print this it like this.. it is not showing the result..
                  here user() returns the value $username for the object Org..

                  Org=HASH(0x8288d90)->user()

                  *********

                  here is the code (since lots of people complaned that !!!)

                  *********
                  package Print;

                  use Org;
                  my $home= "/home/aebolts/html";


                  sub new
                  {
                  my $self = {};
                  bless($self);
                  return $self;
                  }

                  sub printError
                  {
                  shift;
                  ($error,$page,$org) = @_;
                  my %ERROR= (
                  '1','Error Occured: Username already exists, please choose
                  different username',
                  '2','Error Occured: Please check that you have read and accept
                  "Terms of Condition"',
                  );
                  printHeader();
                  open(PAGE,"<$home/$page");
                  @content = <PAGE>;
                  close(PAGE);
                  foreach(@content)
                  {
                  if(/<\@ERROR\@>/){ $_ =~ s/<\@ERROR\@>/<b><font
                  color=red>$ERROR{$error}<\/font><b>/; };
                  if(/<\@USERNAME\@>/){ $_ =~ s/<\@USERNAME\@>/$org->user()/;};
                  print;
                  }
                  printFooter();
                  }

                  ##### did not mentioned other methods (just LAZY nothing secret !!!)
                  ************


                  thanks for the help...



                  -----Original Message-----
                  From: Jeff 'japhy' Pinyan [mailto:japhy@...]
                  Sent: Tuesday, October 01, 2002 11:07 PM
                  To: perl-beginner@yahoogroups.com
                  Subject: RE: [PBML] Perl Module Error


                  On Oct 1, Charles K. Clarkson said:

                  >Jeff 'japhy' Pinyan [mailto:japhy@...] wrote:
                  >
                  >: Useless posting of warning (not error) message
                  >: without showing the actual lines of code at
                  >: NFBBJIGGMLIHLMOIHEDAEEBBCLAA.prakash@....
                  >
                  > I hate when that happens. :)

                  Me too. Prakash, as I requested, please show us the context of lines 32
                  and 40 of Print.pm. We can't debug code we can't see.

                  --
                  Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
                  RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
                  ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
                  <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
                  [ I'm looking for programming work. If you like my work, let me know. ]



                  Unsubscribing info is here:
                  http://help.yahoo.com/help/us/groups/groups-32.html

                  Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


                  ______________________________________________________
                  This email was pre-scanned by Spam Guardian
                  A Service Provided by www.foothill.net and FNFmail.com
                • prakash
                  Never mind.. in the name of shrinking the code the error occured.. i was replacing it in the s///; which is wrong.. i have to get the value in a various like
                  Message 8 of 8 , Oct 2, 2002
                  • 0 Attachment
                    Never mind.. in the name of shrinking the code the error occured..

                    i was replacing it in the s///;
                    which is wrong.. i have to get the value in a various like

                    %info = $object->getInfo();

                    then

                    s/<@ERROR@>/$info{'username'}/ will work fine...


                    -----Original Message-----
                    From: prakash [mailto:prakash@...]
                    Sent: Wednesday, October 02, 2002 3:07 PM
                    To: perl-beginner@yahoogroups.com
                    Subject: RE: [PBML] Perl Module Error


                    Hello guys i solved the previous error.. but have new question..


                    ********

                    i am passing an object called (Org) to different object (Print)..
                    there i get the object and get the information for that object (username)..
                    but when i print this it like this.. it is not showing the result..
                    here user() returns the value $username for the object Org..

                    Org=HASH(0x8288d90)->user()

                    *********

                    here is the code (since lots of people complaned that !!!)

                    *********
                    package Print;

                    use Org;
                    my $home= "/home/aebolts/html";


                    sub new
                    {
                    my $self = {};
                    bless($self);
                    return $self;
                    }

                    sub printError
                    {
                    shift;
                    ($error,$page,$org) = @_;
                    my %ERROR= (
                    '1','Error Occured: Username already exists, please choose
                    different username',
                    '2','Error Occured: Please check that you have read and accept
                    "Terms of Condition"',
                    );
                    printHeader();
                    open(PAGE,"<$home/$page");
                    @content = <PAGE>;
                    close(PAGE);
                    foreach(@content)
                    {
                    if(/<\@ERROR\@>/){ $_ =~ s/<\@ERROR\@>/<b><font
                    color=red>$ERROR{$error}<\/font><b>/; };
                    if(/<\@USERNAME\@>/){ $_ =~ s/<\@USERNAME\@>/$org->user()/;};
                    print;
                    }
                    printFooter();
                    }

                    ##### did not mentioned other methods (just LAZY nothing secret !!!)
                    ************


                    thanks for the help...



                    -----Original Message-----
                    From: Jeff 'japhy' Pinyan [mailto:japhy@...]
                    Sent: Tuesday, October 01, 2002 11:07 PM
                    To: perl-beginner@yahoogroups.com
                    Subject: RE: [PBML] Perl Module Error


                    On Oct 1, Charles K. Clarkson said:

                    >Jeff 'japhy' Pinyan [mailto:japhy@...] wrote:
                    >
                    >: Useless posting of warning (not error) message
                    >: without showing the actual lines of code at
                    >: NFBBJIGGMLIHLMOIHEDAEEBBCLAA.prakash@....
                    >
                    > I hate when that happens. :)

                    Me too. Prakash, as I requested, please show us the context of lines 32
                    and 40 of Print.pm. We can't debug code we can't see.

                    --
                    Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
                    RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
                    ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
                    <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
                    [ I'm looking for programming work. If you like my work, let me know. ]



                    Unsubscribing info is here:
                    http://help.yahoo.com/help/us/groups/groups-32.html

                    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


                    ______________________________________________________
                    This email was pre-scanned by Spam Guardian
                    A Service Provided by www.foothill.net and FNFmail.com





                    Unsubscribing info is here:
                    http://help.yahoo.com/help/us/groups/groups-32.html

                    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
                  Your message has been successfully submitted and would be delivered to recipients shortly.