Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: following if condition fails to print its variable using perl?

by huck (Parson)
on Mar 15, 2017 at 06:15 UTC ( #1184648=note: print w/replies, xml ) Need Help??


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

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

  • Comment on Re^3: following if condition fails to print its variable using perl?
  • Download Code

Replies are listed 'Best First'.
Re^4: following if condition fails to print its variable using perl?
by finddata (Sexton) on Mar 15, 2017 at 09:16 UTC
    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
Re^4: following if condition fails to print its variable using perl?
by finddata (Sexton) on Mar 15, 2017 at 09:27 UTC
    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"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1184648]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2020-02-19 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (84 votes). Check out past polls.

    Notices?