SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help with perl script error: Use of uninitialized value $bugid in concatenation (.) o

    Hi Experts,

    I am relatively new to Perl. I am working on the script below and when I run it, I get these messages:

    C:\Tools\Scripts>perl excel2.pl
    Use of uninitialized value $titlesrow in print at excel2.pl line 37.
    Use of uninitialized value $bugid in concatenation (.) or string at excel2.pl li
    ne 38.
    Use of uninitialized value $ci in concatenation (.) or string at excel2.pl line
    39.
    Use of uninitialized value $ip in concatenation (.) or string at excel2.pl line
    40.
    /n/n/n
    C:\Tools\Scripts>

    ===============================================================================================================

    #!/usr/bin/perl -w
    use strict;
    use Spreadsheet::ParseExcel;

    # Initializong variables
    my ($worksheet, $row, $col, $cell, $bugid, $ci, $ip, $titlesrow, $cell1, $cell2);

    # Manual workbook name and sheet name
    my $FILE = "Book1l.xls";
    my $SHEETNAME = "Sheet1";

    # the column that contains searchable key
    my $KEY_COLUMN = 3;

    # my $searchstring = $ARGV[0];


    my $excel = Spreadsheet::ParseExcel::Workbook->Parse($FILE);
    my $sheet = $excel->Worksheet($SHEETNAME);

    # Sheet limits established
    my ( $row_min, $row_max ) = $sheet->row_range();
    my ( $col_min, $col_max ) = $sheet->col_range();

    # In this section, the row that contains the titles is searched, and then
    # the column numbers for the required variables are identified

    for my $row ( $row_min .. $row_max ) {
    for my $col ( $col_min .. $col_max ) {
    my $cell = $sheet->get_cell( $row, $col );
    if ($cell->value()=~/Bug ID/i){$bugid=$col; $titlesrow=$row};
    if ($cell->value()=~/Customer Impact/i) {$ci=$col};
    if ($cell->value()=~/Impact Probability/i) {$ip=$col};
    }
    }

    # Start printing interesting information

    $titlesrow++;
    for my $row ($titlesrow .. $row_max) {
    my $cell = $sheet->get_cell( $row, $bugid );
    print $cell->value();
    my $cell = $sheet->get_cell( $row, $ci );
    print $cell->value();
    my $cell = $sheet->get_cell( $row, $ip );
    print $cell->value();

    }

  2. #2
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Code:
    # Initializong variables
    my ($worksheet, $row, $col, $cell, $bugid, $ci, $ip, $titlesrow, $cell1, $cell2);
    This makes a bunch of scalar vars, but they don't equal anything. They're undef.

    So if you try to use . (which is for strings) then you get warned that you're trying to concatenate something with undef which isnt a string.

    You could make all your variables = '' (empty string) when you initialise them. This is considered good practice anyway.

    Or you could ignore it. You are seeing the error because of the -w in your first line ("use warnings"), which is good to have on when you're writing but something you'll take off when this is production code (clients should never see warnings or errors, only you).


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •