http://www.perlmonks.org?node_id=1184635


in reply to Re: following if condition fails to print its variable using perl?
in thread following if condition fails to print its variable using perl?

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: following if condition fails to print its variable using perl?
  • Download Code

Replies are listed 'Best First'.
Re^3: following if condition fails to print its variable using perl?
by stevieb (Canon) on Mar 15, 2017 at 04:52 UTC

    That shows a lot of Perl code, but it doesn't explain what you're trying to do.

    We need to know what your *input* is, and what you want as *output*. What directories or files are you sending in? What directories or files do you want out?

    That's reasonably intermediate Perl code there with a lot of hack comments and other such things (definitely kudos for at a glance appearing strict, and 3-arg open), so you can't just expect to throw it up on Perlmonks and think we'll know what you're trying to do with it.

    Start over. Tell us your problem statement. "I have this problem, and I want this outcome.".

    Or: "I have this directory with these files: ..., and I want to do ... with each one of them."

      PROJECT:DCMS_DEMO:prj1 BLOCK:de_top:blk1 BLOCK:new_block2:blk2 BLOCK:test:blk3 CHECKLIST:Block_DV:checklist1 CHECKLIST:Block_Physical_design_checklist:checklist2 CHECKLIST:CAD_checklist:checklist3 CHECKLIST:DFT:checklist4 CHECKLIST:Formality_DCT_Vs_ICC:checklist5 CHECKLIST:Formality_RTL_Vs_DCT:checklist6 CHECKLIST:FrontEnd_Design_Checklist:checklist7 CHECKLIST:Fullchip_Physical_design_checklist:checklist8 CHECKLIST:ICC_DPMHV_Checklist:checklist9 CHECKLIST:ICC_L2_Checklist:checklist10 CHECKLIST:ICC_Top_level_Checklist:checklist11 CHECKLIST:Overall_DV:checklist12 CHECKLIST:Power_analysis_checklist:checklist13 CHECKLIST:Synthesis_L2_checklist:checklist14 CHECKLIST:Timing_analysis_checklist:checklist15 CHECKLIST:checklist_tmp:checklist17 CHECKLIST:synthesis:checklist16 CHECKLIST:test:checklist18 CHECKLIST:test_copy_checklist:checklist19
      this is the input file(i.e $mapfile)

        Did you want to change that file here

        change_file( $mapfile, $name_map, $regex ); poj
Re^3: following if condition fails to print its variable using perl?
by huck (Prior) on Mar 15, 2017 at 06:15 UTC

    start here

    sub rename_dirs { my ( $top_dir, $name_map, $regex ) = @_; print "start rename dirs $top_dir, $name_map \n"; opendir (my $dh, $top_dir) or die "Can't open $top_dir: $!"; my $save_dir = getcwd(); chdir $top_dir; while (my $name = readdir $dh) { next if ($name eq '.') or ($name eq '..'); print 'name :'.$name,"\n"; if ( ( -d $name ) && ( exists $name_map->{$name} ) ) { my $new_name = $name_map->{$name}; print 'newdir :'.$new_name."\n; rename_file_or_dir( $name, $new_name ); $name = $new_name; } elsif ( -f $name ) { if (( my $base_name = $name) =~ s/\.config$// ) { if ( $name_map->{$base_name} ) { my $new_name = $name_map->{$base_name} . '.config' +; print 'newfile:'.$new_name."\n; # print $new_name; rename_file_or_dir( $name, $new_name ); change_file( $mapfile, $name_map, $regex ); } } } if ( -d $name) { print "down :'.$name."\n"; rename_dirs( $name, $name_map, $regex ); print "up :'.$name."\n"; } } chdir $save_dir; }
    See what you can determine from that

      Here,
      i had print as like print 'name :$name', ((exists $name_map->{$name} ) + ? "is in hash" : "is not in hash"), "\n"; above the if condition but it prints not in hash .without taking hash +how it can rename the contents
      Error: when i prints these statements. print 'name :$name', ((exists $name_map->{$name} ) ? "is in hash" : "is not in hash"), "\n";
      name :$nameis in hash name :$nameis not in hash name :$nameis in hash name :$nameis not in hash name :$nameis in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis in hash name :$nameis not in hash name :$nameis in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash name :$nameis not in hash

        print 'name :$name' uses single quotes and the $ is just text, try print 'name :'.$name or print "name :$name"