in reply to Re^5: To read files from two dir
in thread To read files from two dir

Hi,

I had been away for a while from work due to some reasons and this issue is still pending. I will try to explain. In the original script, the topology files and the PM files were placed in the same directory, $VTIERBASE/pvc/ohdr/topology and the $SRC_DIR = $VTIERBASE/pvc/ohdr/topology. But in the new script, topology files are in $VTIERBASE/pvc/ohdr/topology and PM files are $VTIERBASE/pvc/ohdr/instance-0/preprocess. I need the $SRC_DIR to read both set of files from these two directories. I tried with the below

................. my @dir = ("$VTIERBASE/pvc/ohdr/topology","$VTIERBASE/pvc/ohdr/instanc +e-0/preprocess"); foreach my $SRC_DIR(@dir) ............................. #--------------------------------------------------------------------- +- # Validate the parameters #--------------------------------------------------------------------- +- my $file_cnt= scalar(@feed_files); logNdie "$PROGNAME: ERROR: Invalid number of feed files specified +($file_cnt). 8 are required!\n" unless $file_cnt == 8; # Build the complete path if not fully specified $DONE_DIR = "$VTIERBASE/pvc/ohdr/instance-0/cucp/$DONE_DIR" unles +s $DONE_DIR =~ m|^/|; $SRC_DIR = "$VTIERBASE/pvc/ohdr/topology/$SRC_DIR" unless $SRC_D +IR =~ m|^/|; <p> I am not sure how to use $SRC_DIR here</p> $DST_DIR = "$VTIERBASE/pvc/ohdr/instance-0/processed/$DST_DIR" u +nless $DST_DIR =~ m|^/|; # DST_DIR is where we output results ......................... exit 0; }

Please let me know if you need details

Thanks

Replies are listed 'Best First'.
Re^7: To read files from two dir
by graff (Chancellor) on Apr 23, 2022 at 01:06 UTC
    I'll pester you some more (you've earned it). The not-quite-helpful code snippets in this last reply of yours raises some more questions:
    1. We told you about the apparent problem with that "foreach" line having two open-curly brackets; in the snippet above, it looks like you removed both of them. What happened as a result?
    2. We told you about the fact that when you use "foreach my $variable (...) { ... }", the $variable's scope is limited to the loop, so if you want to use that same variable name anywhere outside the loop, you need to declare it with "my" outside the loop. Have you done that?
    3. Based on the too-lengthy-but-still-incomplete code that you posted a while ago, it seems like the overall design of the script is based on handling just one $SRC_DIR value per run, and (it's not clear, but) it seems like the one value could be a command-line parameter, so you could just run the original script twice (assuming it ever worked), once for each directory. Is there some reason you can't do that?
    Well, no point going any further until you show us that you can at least answer some questions.
Re^7: To read files from two dir
by graff (Chancellor) on Apr 23, 2022 at 00:37 UTC
    It seems that you are not aware of the fact that we have been asking you questions and offering suggestions. You have not answered any of our questions, and you have not mentioned anything about our suggestions (like: whether you understood them, or tried them out, or ran into new problems after trying them out).

    So... that would be the sort of "details" we would "need" if you really expect to make any progress based on help from us.

    Here's another suggestion: PLEASE -- PLEASE -- PLEASE: Edit that terribly long post of yours above -- the one with nearly 1200 lines of code in it -- and put a <readmore> tag above the beginning of the code, and a </readmore> tag at the end of the code. I'm SERIOUS!! DO IT!!! Because it is an awful PAIN IN THE A$$ to have to scroll over all 1200 lines every time I look at this thread. Thanks in advance.

      Hi,

      I was able to fix the issue to read from two directories. I added a variable for the second directory and used that throughout my code. That simplified the effort. I have another issue. Currently, I have this directory as

      my $TOP_DIR = "$VTIERBASE/pvc/ohdr/instance-00

      where the 00 in front of instance is derived from the hostname of the VM (zldcdabcdef14-vos-fxohr-correlator-00). digits after correlator- for example, the VMs may start from 00 to 99 I need to pass this value , /instance-xx dynamically How to do this?

      Thanks,

        The problem statement is a little vague. Perhaps see How to ask better questions using Test::More and sample data? Anyway here might be what you want.

        use strict; use warnings; use Test::More tests => 1; my $vmstr = 'zldcdabcdef14-vos-fxohr-correlator-00'; my ($digits) = $vmstr =~ /-(\d\d)$/; my $instance = "/instance-$digits"; is $instance, '/instance-00';

        🦛