Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Unable to write to log-file

by dmlond (Acolyte)
on Jul 29, 2009 at 17:08 UTC ( #784295=note: print w/replies, xml ) Need Help??

in reply to Unable to write to log-file

Using strict and warnings is critical to writing working code. It will save you alot of headaches. Another thing you might want to do is get into the habit of using the <> operator to read in the contents of a directory (available, I believe, since perl 5.6). This makes reading the contents from a directory much more idiomatically similar to reading in the contents of a file. Also, the perl open function can now open handles into an IO::Handle object, which, again, allows you to make greater use of the file handles as references passed to subroutines, etc. Finally, I always use the 3 argument version of open. It makes it much more intuitive what you are doing, and prevents whitespace mistakes that can occur when trying to pass a string in with the handle type and the path in the same string. Here is a bit of code that can do what you want:

use strict; use warnings; my $allDevices = 'All_Devices.txt'; open (my $device_h, '>>', $allDevices) or die "Could not create $allDe +vices $!\n"; while (my $file = <$_allConfDir/*>) { print $device_h $file; } close $device_h;

Another advantage of the <> usage is that it accepts unix regular expressions, so instead of doing:

next uness ($file =~ m/\.txt$/);

You can just use:


Hope this helps.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://784295]
[Lady_Aleena]: shmem, geany on Debian jessie.
[shmem]: some experience with vim?
[Lady_Aleena]: None
[shmem]: I don't know geany, and don't know whether it has support for ctags.
[Lady_Aleena]: ctags?
[shmem]: ctags is a program which (recursively) extracts the symbols from source and stores them in a one-file database. This allows you to query the locations where these symbols (e.g. a subroutine name) are used anywhere in the source code tree...
[shmem]: ...from inside the editor.
[shmem]: apt-get install exuberant-ctags
[Lady_Aleena]: I think I heard vim has a big learning curve.
[shmem]: then in the root of your source tree run: ctags -R

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-04-27 12:07 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (505 votes). Check out past polls.