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

Can't figure out how to print text and array values at same time

Here's code:

$csv->print ($fh1, [$ifile, @cols, @matches ]);

Here's code I tried

  $csv->print ($fh1, [$ifile, "*".@cols, @matches ]);

I tried single quotes, double quotes and print join with no luck

I must be missing something obvious!

Replies are listed 'Best First'.
Re: how to print text + array values at same time
by kcott (Archbishop) on Feb 26, 2016 at 07:02 UTC

    If that's Text::CSV's print() method you're referring to, perhaps that documentation may help.

    According to the documentation, your first line of code

    $csv->print ($fh1, [$ifile, @cols, @matches ]);

    appears to be syntactically correct. Print out the values of those variables, immediately before that line of code, and inspect them: this may help in tracking down your problem.

    I've no idea what you're attempting to achieve with "*".@cols. It will concatenate an asterisk with the number of elements in @cols (i.e. @cols in scalar context). Here's an example:

    $ perl -wE 'my @cols = qw{a b c}; say "*".@cols' *3

    Here's some suggestions as to what I think you may want (but I really am guessing here):

    $ perl -wE 'my @c = (1,2,3); say "*", @c' *123
    $ perl -wE 'my @c = (1,2,3); say "*@c"' *1 2 3
    $ perl -wE 'my @c = (1,2,3); say map { "*$_" } @c' *1*2*3
    $ perl -wE 'my @c = (1,2,3); say "@{[ map { qq{*$_} } @c ]}"' *1 *2 *3

    If you need more help, please read "How do I post a question effectively?" before posting again.

    — Ken

Re: how to print text + array values at same time
by stevieb (Canon) on Feb 26, 2016 at 01:02 UTC
    It would help tremendously if you could specify the module you're using, some input data, and expected output.

    You appear to be printing to a file handle... do you realize that your output won't be displayed in your terminal?

Re: how to print text + array values at same time
by Anonymous Monk on Feb 26, 2016 at 00:59 UTC
    What does that mean?
Re: how to print text + array values at same time
by FreeBeerReekingMonk (Deacon) on Feb 26, 2016 at 22:23 UTC
    print It expects an array ref as input (not an array!) Try this:
    my @DATA = [$ifile, @cols, @matches ]; $csv->print ($fh1, \@DATA);