Great Andrew.
it is all good now.

Could you please tell how new line ended up as ? in the file name

Thanks,
Satya


On 19 March 2015 at 12:53, Andrew Solomon <and...@geekuni.com> wrote:

> my $logFileName="log_ping_".`date +"%d_%b_%y_%H_%M_%S"`;
>
> should be followed by
>
> chomp($logFileName)
>
> otherwise there's a trailing newline character in $logFileName on account
> of the call to date
>
> Andrew
>
> On Thu, Mar 19, 2015 at 6:08 AM, Satya Prasad Nemana <spn...@gmail.com>
> wrote:
>
>> Hi
>>
>> I have a small program listed below where i am writing ping results to a
>> file.
>> The program works file except that the file name in the output file is
>> coming as log_ping_19_Mar_15_11_27_49? (please note the ? at the end of the
>> name)
>>
>> The initial output looks like
>> bats3 snemana/perlprogs> perl pingTest.pl hostInfo.txt
>>
>> Logfile is log_ping_19_Mar_15_11_38_53
>>
>> File name is hostInfo.txt
>>
>> .............................
>>
>> Could someone please tell why the ? is getting added to the file name
>> although it looks fine in the initial print of the file name.
>>
>> use Data::Dumper;
>> use strict;
>> use warnings;
>> my $numberOfPingPackets=1;
>>
>> my $fullFileName=$ARGV[0];
>> my $logFileName="log_ping_".`date +"%d_%b_%y_%H_%M_%S"`;
>> print "\nLogfile is $logFileName";
>> print ("\nFile name is $fullFileName");
>> open FILE, $fullFileName or die $!;
>> my $logFile;
>> open $logFile, '>', $logFileName or die $!;
>> my @fileContents=<FILE>;
>> print ("\nFile contents are ".Dumper(@fileContents));
>> for(my $i=0;$i < @fileContents; $i++)
>> {
>> my $line=$fileContents[$i];
>> my @data=split(/\t/,$line);
>> my $host=$data[0];
>> my $ip=substr($data[1],0,-1);
>> my @pingResults=`ping -c $numberOfPingPackets $ip`;
>> my $succesString="$numberOfPingPackets packets transmitted,
>> $numberOfPingPackets received, 0% packet loss";
>> my $index=3+$numberOfPingPackets;
>> if(index($pingResults[$index],$succesString) >= 0)
>> {
>>     print "\nPing to host $host ip $ip is successful";
>>     print $logFile "\nPing to host $host ip $ip is successful";
>> }
>> else
>> {
>>     print "\nPing to host $host ip $ip is failure";
>>     print $logFile "\nPing to host $host ip $ip is failure";
>> }
>> }
>> close $logFile;
>>
>>
>> --
>> Satya Prasad
>>
>
>
>
> --
> Andrew Solomon
>
> Mentor@Geekuni http://geekuni.com/
> http://www.linkedin.com/in/asolomon
>



-- 
Satya Prasad

Reply via email to