Passing variable into perl system commands

Hi guys, I'm having issues getting the following snippet of my script to work and was hoping for some suggestions.
I'm trying to pass a variable in perl system with wget.

This is what I need help with:

#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime) ;

my $TimeStamp=strftime "%Y%m%d",localtime ;
system('wget -q --no-check-certificate -O /tmp/DataFile_$TimeStamp "https://foobar.com/html"') ;

I can't get the $TimeStamp to interpolate into the system command.

Any ideas on solving this?

Thanks in advance.

You need to allow the perl interpreter to interpolate perl variables.

Just try this.!

system("wget -q --no-check-certificate -O /tmp/DataFile_$TimeStamp 'https://foobar.com/html' ") ;

-Ranga

1 Like

Thanks a lot, rangarasan! That did it.

There's more than one way to do it, in Perl. :slight_smile:
The dot (".") is the string concatenation operator.

#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime) ;

my $TimeStamp=strftime "%Y%m%d",localtime ;
system('wget -q --no-check-certificate -O /tmp/DataFile_'.$TimeStamp.' "https://foobar.com/html"') ;
1 Like