Thursday, 15 September 2011

Perl concatenation of variables for path from a different file -



Perl concatenation of variables for path from a different file -

i have things (usually) doesn't work, it's concatenantion of variables in perl. have create script in perl redhat's server.

i have 2 files:

file.properties : contain somes variables path,

remotepath=/opt/applicaton/logs/backup logtype=statistics.log

testfile.pl : wich contain code concatenation of variables create real path..here code

#get variables if ( $type =~ /remotepath/ ) { $remotepath = $val; } if ( $type =~ /logtype/ ) { $logtype = $val; } $logname = "tcf_.$logtype"; #we add together date @ logtype , prefix.. ( $i = 0; $i <= $#argv; $i++ ) { if ( $argv[$i] =~ /(\d{4})(\d{2})(\d{2})/ ) { $dateformatlog = sprintf( "%s-%s-%s", $1, $2, $3 ); } } #i tried print each variable separately works well, not concatenation.. $finalpath = "$remotepath/$logname.$dateformatlog"; #or $finalpath = $remotepath . '/' . $logname . $dateformatlog; print $finalpath;

the result expected /opt/applicaton/logs/backup/tcf_statistics.log.2014-10-13.zip have

.2014-10-13 tics.logwas/logs/backup

or

2014-10-13istics.logwas/logs/backup

i don't know why result of concatenation such things, if have thought helpful !

thanks advance,

jimmy

first of all, looks info comes file originated on windows (or possible mac) system. such systems have cr @ end of each line as, or instead of, lf, won't removed chomp on linux platform.. don't show how read data, best way prepare such files utilize s/\s+\z// instead of chomp read each line.

secondly, expecting filename tcf_statistics.log.2014-10-13.zip value of $logname tcf_.statistics.log, have dot . in there after tcf_. should set value this

my $logname = "tcf_$logtype";

you need incorporate value of file extension .zip somehow; this.

my $finalpath = "$remotepath/$logname.$dateformatlog.zip"

that should code working.

perl variables concatenation redhat

No comments:

Post a Comment