Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Broken Write function? Does anyone have Magic fixer ability?

by ProgrammerJutsu (Initiate)
on Jan 10, 2013 at 23:17 UTC ( [id://1012755]=perlquestion: print w/replies, xml ) Need Help??

ProgrammerJutsu has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Broken Write function? Does anyone have Magic fixer ability?
by davido (Cardinal) on Jan 11, 2013 at 00:26 UTC

    You don't see any problems here?

    $i = 0; my $filename2 = "invaildAddress"; $arrayLength = scalar(@addressSave); print $arrayLength ."\n"; open(IN2 , '>', $filename2); print IN "Invalid Addresses:\n\n\n"; while($i > $addressL){ ##########BROKE? print IN2 "City = " . $invalidAdd[$i]->{City} . "\n"; print IN2 "State = " . $invalidAdd[$i]->{State} . "\n"; print IN2 "Zip = " . $invalidAdd[$i]->{Zip} . "\n"; print IN2 "Address = " . $invalidAdd[$i]->{Address} . "\n"; print IN2 "Po Box = " . $invalidAdd[$i]->{PoBox} . "\n"; print IN2 "Suite = " . $invalidAdd[$i]->{Suite} . "\n"; print IN2 "Misc data = " . $invalidAdd[$i]->{MiscData} . "\n\n"; $i++; } close(IN2);

    First you set $i to 0. Then you open a file with the handle "IN2" for output, but fail to check open for success. Then you print a line to the closed filehandle named "IN". Then you have a while loop that never executes because $i still holds zero, which should never be greater than $addressL. Since the only lines that print to IN2 are inside of a loop that never executes, you get no output. Within your loop at least you're trying to print to the correct filehandle.


    Dave

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Broken Write function? Does anyone have Magic fixer ability?
by tobyink (Canon) on Jan 10, 2013 at 23:55 UTC
    open(IN2 , '>', $filename2); ### "IN2" print IN "Invalid Addresses:\n\n\n"; ### "IN" !!!

    (Of course, why you're calling an output file "IN" is another mystery...)

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Broken Write function? Does anyone have Magic fixer ability?
by dave_the_m (Monsignor) on Jan 10, 2013 at 23:42 UTC
    So, you call everyone on this site morons, then expect people to help you. You have an interesting perspective on human psychology.

    Dave.

Re: Broken Write function? Does anyone have Magic fixer ability?
by blue_cowdawg (Monsignor) on Jan 11, 2013 at 15:05 UTC
        Please dont respond if you want to tell me about formatting, or if you want to tell me this is a continuation post or if you dont have anything constructive to input. Unless you want to tell me im a genius.

    It's comments like that which cause me to heap scorn on your posts. If you were one of my students I'd probably end up failing you for the semester. I won't tell you about formatting (this time) but I will point out several flaws in your programming.

    1. Failure to use the pragma "strict." This probably would have saved you some pain
    2. Lack of error checking (see your "open" calls) to ensure what you want to have happen happens
    Those two issues alone would have me give your programming assignment a failing grade if you were one of my students.

    I have to be honest with you: when I see posts like the one I am critiquing now and others like this one from someone who has been around this Monastery for less than a week and is flame baiting I consider ignoring anything else you post.

    I've been on this site since 2001. Experience has taught me that here in PM as well as in life a bit of humility goes a very long way if you want help from others learning any skill and especially Perl. Tone down your attitude and you'll find this is a great place to hang out and a go to place to learn about Perl. My expectations of my students can apply here:

    1. Do you own work
    2. Write proper code with embedded documentation
    3. If you come to me for help with a programming issue:
      1. Explain what you are trying to accomplish or what you expect to happen
      2. Show me the code. There should be just enough for it to be self contained but don't overwhelm me with your entire source.
      3. Provide me with an error code. Copy/paste if you can.
    4. Be professional/polite. I've been in the field since 1981 and I have personal experience that taught me that bad attitude gets you nowhere.

    The other thing that irritates me are node titles that smack of the author being a smart ass. "Magic fixer ability", really? Did you get that from a Pokemon episode?


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
    A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Broken Write function? Does anyone have Magic fixer ability?
by Your Mother (Archbishop) on Jan 11, 2013 at 03:11 UTC

    *You’re a genius.

Re: Broken Write function? Does anyone have Magic fixer ability?
by frozenwithjoy (Priest) on Jan 11, 2013 at 08:01 UTC
    Even if this doesn't solve your two stated problems, the very first thing you need to do is add this to the top (and then deal with any errors/warnings that may arise):
    use strict; use warnings; use autodie; # or give a die option when opening each filehandle
Re: Broken Write function? Does anyone have Magic fixer ability?
by Mr. Muskrat (Canon) on Jan 11, 2013 at 21:42 UTC

    Troll much?

      A troll acts like a jerk to cause trouble and to start flame wars. This guy's not a troll; he's the real deal.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-18 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found