I don't understand what you mean with that last sentence, do you really want to continue from the exact line the sub finished at? That menas you will have to read that line twice, once in the sub and once i the main routine, by pushing the line back into the buffer, or pass back that line to the main function using return values. Try to avoid that. I usually read a file in only one place and use some sort of state machine to control what I want to do with what I read.
Anyway, if this is just a question regarding filhandle referencies, see the perlref and perlreftut. Also, I made a small example on filehandle referencing:
#!/usr/bin/perl -w
open SESAME, "testfil";
while (<SESAME>) {
chomp;
print "main: $_ ";
if ($_ =~ /baz/) { print "go! \n"; &aSub(*SESAME) }
print "\n";
}
sub aSub {
my $inFile = shift;
while (<$inFile>) {
chomp;
print "sub: $_";
if ($_ =~ /bao/ ) { print " return!"; return };
print "\n";
}
}
the testfile is simple:
foo
bar
baz
bam
bao
fee
fie
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.