Search code examples
perldata-dumper

How to get line numbers when warning with Data::Dumper result?


warn behaves differently in the following two cases:

#! /usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

warn "string";
warn Dumper("string");

The first prints:

string at dumper.pl line 6.

And the second prints just:

$VAR1 = 'string';

without any line number.

How get the line number when warning with the Dumper result?


Solution

  • Just connect a string after the Dumper call:

    warn Dumper("string").' ';
    

    yields

    $VAR1 = 'string';
      at /tmp/execpad-a668561a2ac4/source-a668561a2ac4 line 7.
    

    at eval.in.