Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

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

Hey, thanks for all the helpful responses.

Thanks in particular to the link to hash slices. The part I found particularly helpful was

"If you're confused about why you use an '@' there on a hash slice instead of a '%', think of it like this. The type of bracket (square or curly) governs whether it's an array or a hash being looked at. On the other hand, the leading symbol ('$' or '@') on the array or hash indicates whether you are getting back a singular value (a scalar) or a plural one (a list)."

I think that using "map" as a variable name in an example using the "map" function is a bit confusing.

As far as when to declare variables, I do try to use the smallest lexical scope possible. I also often have a series of what I call "global" variables at the beginning and top level of the program declared with "my." The main purpose is a) saving typing (if certain strings are used several times in the program I will use a variable with a short name; for example if I know I will be using directory and/or file base names of "temp" I might declare 'my $t = "temp";' or somesuch) b) the other obvious reason of making the code more maintainable (if the directory I want to use for something changes, I only have to change it in one spot near the beginning of the program). Both are fraught with danger though as sometimes I'll see a variable used and have to scroll back up to remind myself what it is. This discussion is probably as old as the concept of scoping; further comments(or nudges in the right direction) are welcome.

In this particular case I download four reports in CSV format and I define a (global) hash with reportname=>["wantedfield1","wf2",etc] pairs. The full list of available column headers is generated dynamically by reading in the first line of each report. Then, the field map is generated via the process discussed in this thread. This means hopefully the next time they change the reports (which seems to constitute simply adding fields), it won't be a major rewrite.

johngg, I don't get your method at all.

One last question: it seems a couple of the responses used qw(Field1 Field2 Field3) as opposed to ("Field1","Field2","Field3"). What's the difference?

Thanks again and ++ all responses in this thread regardless.

T.

_________________________________________________________________________________

I like computer programming because it's like Legos for the mind.


In reply to Re: My 'perldar' tells me there is a 'better' solution for this list operation by OfficeLinebacker
in thread My 'perldar' tells me there is a 'better' solution for this list operation by OfficeLinebacker

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 perusing the Monastery: (5)
As of 2024-04-25 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found