akagrawal3 has asked for the wisdom of the Perl Monks concerning the following question:

my @intervals = $poller_db->resultset('Aggregation')-> search({aggregation_interval => undef,})

In my Database, there are many tables of which 'aggregation' is one of them. In this table, there is a column named 'aggregation_interval'. I am using MySQL. Now I have the following questions: 1. What value is stored in @intervals 2. How is it possible to have 'Aggregation' in code and 'aggregation' table in database 3. What does 'undef' signify here.

Replies are listed 'Best First'.
Re: Database MySQL Perl
by shmem (Chancellor) on Feb 27, 2012 at 09:24 UTC
    1. What value is stored in @intervals

    Since @intervals denotes an array, most likely it holds a list of values - only one would just be a special case. The array holds what is returned from the search method of the object provided by resultset.

    If in doubt, have a look:

    { my $c; for my $thingy (@intervals) { printf "%2d. '%s'\n",++$c, $thingy; } }
    2. How is it possible to have 'Aggregation' in code and 'aggregation' table in database

    It's possible with some piece of software which does the connection between 'Aggregation' and 'aggregation', probably by upper-/lowercasing the identifier.

    3. What does 'undef' signify here.

    It means just what undef means anywhere else: a placeholder for nothing, which is just about the same as the NULL value in a database cell.

    Have a look at the documentation of DBIx::Class and DBIx::Class::ResultSet.

      Thank you very much :)
Re: Database MySQL Perl
by CountZero (Bishop) on Feb 27, 2012 at 07:29 UTC
    Are you using DBIx::Class?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: Database MySQL Perl
by aaron_baugher (Curate) on Feb 27, 2012 at 12:13 UTC

    When the question is, "What is in this variable?" the answer is Data::Dumper (or one of its alternatives from CPAN). For anything more complex than a single scalar value, it's typically easier to type the two lines below than to create a loop or recursive function to print the thing. (Typically I 'use Data::Dumper' in all my programs during development, so I only need to type the second line to quickly dump a variable.)

    use Data::Dumper; print Dumper @interval;

    Aaron B.
    My Woefully Neglected Blog, where I occasionally mention Perl.

      Data::Dumper is great, but for development I find it much more efficient to set a breakpoint (single click) then hover over the variable in question to see its content in a popup tool tip. YMMV depending on the IDE you use.

      True laziness is hard work
      Oh that was worth knowing.. :)