in reply to Perl Variable Help.

Don't append new lines (\n) to the values of $webfile and $dbfile. use chomp on your $date variable. Note that This is not a portable (between Operating systems) way to get dates (see localtime).

#!/usr/bin/perl use strict; use warnings; my $date = `date +%Y%m%d`; chomp $date; my $tar = '.tar'; my $gz = '.gz'; my $dbfile = 'bugs_db_'.$date.$gz; my $webfile = 'bugzilla_'.$date.$tar.$gz; print "dbfile: $dbfile\n"; print "webfile: $webfile\n"; # since you want them in one line: print "$dbfile $webfile\n";

Replies are listed 'Best First'.
Re^2: Perl Variable Help.
by Dumu (Monk) on Jul 02, 2015 at 11:36 UTC

    I think the OP does want the filenames printing on two lines, he just doesn't want newlines inside the filenames (of course).

    arvindmarlabs, Perl has faster and similarly named equivalents for many of the Unix®-y commands. You don't need to use backticks for simple stuff like this. You can if you want, but it's better to leave them for interacting with other programs for which you don't have any other convenient interface.

    As marto says, shelling out isn't portable across OSes, and it will probably be slower than using Perl's own date function(s) e.g. localtime.

    localtime is fairly straightforward, but does require a couple of extra lines of code to get the date into the format you want. If you can install a module from CPAN, DateTime makes date and time handling a lot easier.