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!


In reply to Fetching a file path from a Perl 'rc' file by tgt4Perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.