tgt4Perl has asked for the wisdom of the Perl Monks concerning the following question:
Hello Perl Monks and gurus! I have a problem in Perl here that I've been trying to solve using different techniques that I came across but it does not seem to work. :( I have a '.rc' file, 'sample1.rc' that contains just this code:
# Use -*- perl -*- mode in Emacs. #--------------------------------------------------------------------- +----------- $RC{configs} = ['dnl', 'abme', 'bet', 'khae', ], $RC{model_root} = '/nfs/fm/disks/fm_aaaa_00011/users/me/repotest/model +/tools/someproject/logs' 1;
the '$RC{model_root}' line contains the path to a file that I'm trying to read from my perl script, called 'sample.pl'. This is the complete code in 'sample.pl'..the problem is I'm unable to fetch the path from 'sample1.rc'
#!/usr/5.14.1/bin/perl -w use strict; use warnings; use FileHandle; use File::Find; use Getopt::Long; use Data::Dumper; use File::Path; use Safe; use vars qw($ProgDir $ProgName $debug $quiet %RC %OPTS %OPTS_DEF); main (); sub main { parse_cmdline (); read_file($OPTS{rcfile}) if exists $OPTS{rcfile}; dynamo_check (); } my $configs = $RC{configs}; my $model_root = $RC{model_root}; my $outputfile = 'output.txt'; my %results; myPrint("Executing the script: $ProgName"); myPrint("$ProgName executed successfully"); #--------------------------------------------------------------------- +---------- sub dynamo_check { #look for 'Errors: 0' string here my $log_file = $model_root; while ( <$log_file> ) { my ( $varname, $value ) = ( m/\A(\S+) = \'(\S+)\'/ ); if ( $varname eq '$RC{model_root}' ) { $model_root = $value +; } } #print $model_root; foreach my $log_file ( glob "/*" ) { info ("Opening file: $log_file"); my $fh = open_for_reading ($log_file); if ($log_file eq "dynamo."){ while(my $line = <$fh>) { last if ($line =~ m/s*=\s+Exiting Dynamo\W/); chomp $line; open (my $ofh, '>' , $outputfile) or printError ("Could not op +en this file $!"); if ($line =~ m/Errors:\s+0/) { print $ofh "Dynamo run status: PASS\n"; $results{'Dynamo'} = "PASS"; }else { print $ofh "Dynamo run status: FAILED\n"; $results{'Dynamo'} = "FAILED"; } close $fh; } } #add this file to the 'reports' directory } } info ("done..check 1");
Please help! Looks like something you can follow easily, but pls let me know if you need more details. Thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fetching a file path from a Perl 'rc' file
by GrandFather (Saint) on Feb 12, 2015 at 20:06 UTC | |
|
Re: Fetching a file path from a Perl 'rc' file
by RonW (Parson) on Feb 12, 2015 at 21:14 UTC | |
|
Re: Fetching a file path from a Perl 'rc' file
by Anonymous Monk on Feb 12, 2015 at 21:02 UTC | |
|
Re: Fetching a file path from a Perl 'rc' file
by tgt4Perl (Initiate) on Feb 12, 2015 at 21:59 UTC | |
by CountZero (Bishop) on Feb 13, 2015 at 17:04 UTC | |
by Anonymous Monk on Feb 12, 2015 at 23:10 UTC | |
|
Re: Fetching a file path from a Perl 'rc' file
by Anonymous Monk on Feb 13, 2015 at 05:24 UTC |