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??

There look to be a bunch of things there that will make the code hard to understand and maintain.

First off, don't use prototypes. That is your immediate problem as has already been suggested. They don't do what you think and cause subtle trouble that can lead to really hard to debug errors.

Don't use artificial boolean values. Just accept that $continue_tag is a boolean variable that is false if it is empty or 0 and true otherwise.

Make it clear where information comes from. You don't show @array_of_lines (bad name btw, why not just @lines?) being assigned any content. It's not clear how the work look_through_file does relates to the work create_output does. Where does $continue_tag's value get changed?

Without any idea what your intent for the code is I can only sketch a better structure, but consider:

#!/usr/bin/perl use strict; use warnings; my $fName = 'wibble.dat'; my $group; open my $fIn, '<', $fName or die "Can't open $fName: $!\n"; while (my @lines = scanFile($fIn)) { report(++$group, @lines); } sub scanFile { my ($fIn) = @_; my @lines; while (@lines < 10 && defined (my $line = <$fIn>)) { chomp $line; next if ! length $line; push @lines, $line; } return @lines; } sub report { my ($group, @lines) = @_; printf "%04d: %s\n", $group for @lines; }

which batches lines from a file into groups of 10 non-blank lines then prints each group with a group prefix.

True laziness is hard work

In reply to Re: Calling a subroutine within a conditional by GrandFather
in thread Calling a subroutine within a conditional by Freezer

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 admiring the Monastery: (2)
As of 2024-04-24 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found