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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
open (REPORTFILE,">>$folder\\$reportfile")...
Some comments about this. First of all, you could benefit from being used to use lexical filehandles instead of package scoped ones, like:
open my $reportfile, ...
This will let you avoid nasty situations when your script grows and you find yourself opening REPORTFILE in more than one place. The usual "avoid globals if you can" stuff. You can then use it where you previously used REPORTFILE:
print $reportfile "TAG HIERARCHY REPORT\n";

Moreover, you're using the two-argument version of open, which should be avoided just to prevent the user shoot in her (or your) feet. The three-argument version needs only a bunch of chars more but is way more safe:

open my $resultfile, '>>', $filepath...
In this way, $filepath can contain stuff like "booh; rm -rf /" and still let you sleep well (I don't know an equivalently destructive command in win32, but you get the point).

The portable way to handle file paths is via File::Spec. Just in case you're interested into making your script more portable (which would probably require changes in the DB interface routines, too). Something along these lines:

my $filepath = File::Spec->catfile($folder, $reportfile); open my $reportfile, '>>', $filepath ...;

Last, but not least, you can provide a more sensible feedback to the user regarding the reasons why your script was unable to open the file, by means of the $! variable (see perlvar):

my $filepath = File::Spec->catfile($folder, $reportfile); open my $reportfile, '>>', $filepath or die "open('$filepath') for appending: $!";

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

In reply to Re: Building a data Hierarchy by polettix
in thread Building a data Hierarchy by SlackBladder

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 imbibing at the Monastery: (6)
As of 2024-04-16 10:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found