Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: How to write the perl script for the following linux command?

by finddata (Sexton)
on Mar 14, 2017 at 12:27 UTC ( [id://1184538]=note: print w/replies, xml ) Need Help??


in reply to Re^3: How to write the perl script for the following linux command?
in thread How to write the perl script for the following linux command?

my $sorce_direcrtory = $input_dir; my $new_directory = $output_dir; opendir(my $dh, $sorce_direcrtory) || die; while(readdir $dh) { if($_ =~ /.csv/){ copy("$sorce_direcrtory/$_", "$new_directory/$_"); } } closedir $dh;
error: Use of uninitialized value in pattern match (m//)
  • Comment on Re^4: How to write the perl script for the following linux command?
  • Download Code

Replies are listed 'Best First'.
Re^5: How to write the perl script for the following linux command?
by Corion (Patriarch) on Mar 14, 2017 at 12:38 UTC

    Usually, Perl also outputs the exact line number where the warning occurs. What line number does your code output?

    I find it unlikely that opendir would succeed but then readdir should return undef.

    Let me recommend to you, again, File::Find, which makes iterating over a directory tree somewhat easier.

      the error ocurrs at this line if($_ =~ /.csv/){

        Please post a self-contained, small example that reproduces the behaviour you see.

        Using the below code, I cannot reproduce your problem:

        #!perl -w use strict; my $sorce_direcrtory = '.'; my $new_directory = './target/'; opendir(my $dh, $sorce_direcrtory) || die $!; while(readdir $dh) { print "Found directory entry [$_]\n"; if($_ =~ /.csv/){ print qq{copy("$sorce_direcrtory/$_", "$new_directory/$_")\n}; } } closedir $dh;
Re^5: How to write the perl script for the following linux command?
by poj (Abbot) on Mar 14, 2017 at 12:47 UTC

    What is exact and complete error message ?

    poj
      Use of uninitialized value in pattern match (m//) at line 7

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found