Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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:

<$_allConfDir/*txt>

Hope this helps.


In reply to Re: Unable to write to log-file by dmlond
in thread Unable to write to log-file by turbokwak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2024-04-24 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found